private function ChangStr(byval isStr as string) as string return "pre" & (val(replace(istr,"pre",""))+1) end function
很简单啊,取出最后一位,以及最后的数字。 如果最后一位为9则,新的字符串为pre & 最后的数字+2 如果最后一位不为9则,新的字符串为pre & 最后的数字+1 str="pre……";str1=mid(str,3,len(str)) str2=mid(str,len(str)-1,len(str)) if int(str2)<>9 then str="pre" & Str$(int(str1)+1) else str="pre" & Str$(int(str)+2)
dim strA as string dim intTmp as integer dim StrB as stringstrA="pre1" ... intTmp=val(mid(strA,4))+1 if intTmp mod 10=0 then inttmp=intTmp+1 strB="pre" & intTmp
Public Function ChangStr(ByVal Str As String) As String Dim str1 As String Dim str2 As Stringstr1 = Mid(Str, 3, Len(Str)) str2 = Mid(Str, Len(Str) - 1, Len(Str)) If Int(str2) <> 9 Then Str = "pre" & Str$(Int(str1) + 1) Else Str = "pre" & Str$(Int(Str) + 2) End If ChangStr = Str End Function
这段代码写好 为什么会出错:“缺少数组”
Public Function ChangStr(ByVal iStr As String) As StringChangStr = "pre" & Trim(Str((IIf((Val(Replace(iStr, "pre", "")) + 1) Mod 10 = 0, Val(Replace(iStr, "pre", "")) + 2, Val(Replace(iStr, "pre", "")) + 1))))End Function
我觉得他想表述的是。 dim pre1 as string dim pre2 as string ...... 这种情况吧。 如果输入的为pre1这个字串,则返回pre2这个字串。 ...... 不然太容易了。
因为string+int=string
return "pre" & (val(replace(istr,"pre",""))+1)
end function
如果最后一位为9则,新的字符串为pre & 最后的数字+2
如果最后一位不为9则,新的字符串为pre & 最后的数字+1
str="pre……";str1=mid(str,3,len(str))
str2=mid(str,len(str)-1,len(str))
if int(str2)<>9 then str="pre" & Str$(int(str1)+1)
else str="pre" & Str$(int(str)+2)
dim intTmp as integer
dim StrB as stringstrA="pre1"
...
intTmp=val(mid(strA,4))+1
if intTmp mod 10=0 then inttmp=intTmp+1
strB="pre" & intTmp
Dim str1 As String
Dim str2 As Stringstr1 = Mid(Str, 3, Len(Str))
str2 = Mid(Str, Len(Str) - 1, Len(Str))
If Int(str2) <> 9 Then Str = "pre" & Str$(Int(str1) + 1)
Else
Str = "pre" & Str$(Int(Str) + 2)
End If
ChangStr = Str
End Function
这段代码写好 为什么会出错:“缺少数组”
dim pre1 as string
dim pre2 as string
......
这种情况吧。
如果输入的为pre1这个字串,则返回pre2这个字串。
......
不然太容易了。