VB中怎么样使前一次运行的参数值保持不变,在下一次运行时值为前一次运行结束后的值,而不是为0,谢谢!
2个回答
展开全部
使用static定义变量,而不是用dim,例如:
在command_click事件中
private sub command1_click()
static a as integer
a=a+1
print a
end sub
这样的代码你按一次command打印出来的是1,按第2次打印出来的是3以此类推。而如果使用dim定义变量a ,那么每一次按command都是1
在command_click事件中
private sub command1_click()
static a as integer
a=a+1
print a
end sub
这样的代码你按一次command打印出来的是1,按第2次打印出来的是3以此类推。而如果使用dim定义变量a ,那么每一次按command都是1
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
找个文件 把上次的结果存起来.
建议使用INI, 有现成的INI文件读写模块
我在网上找了一个
'保存为读写INI.bas
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Public Function 读取(ByVal a As String, ByVal B As String) As String
Dim ret As Long
Dim buff As String
buff = String(255, 0)
ret = GetPrivateProfileString(a, B, "", buff, 256, 路径 & App.EXEName & ".ini")
If Left(buff, 1) = Chr(0) Then
buff = ""
End If
读取 = TrimNull(buff)
End Function
Public Function 写入(ByVal a As String, ByVal B As String, ByVal C As String) As String
On Error Resume Next
If Dir(路径 & App.EXEName & ".ini") = "" Then
Dim file As Integer
file = FreeFile
Open 路径 & App.EXEName & ".ini" For Append As file
Close file
End If
ret = WritePrivateProfileString(a, B, C, 路径 & App.EXEName & ".ini")
End Function
Function TrimNull(s As String) As String
On Error Resume Next
Do While Left(s, 1) = Chr(0)
s = Mid(s, 2)
If s = "" Then Exit Function
Loop
Do While Right(s, 1) = Chr(0)
s = Left(s, Len(s) - 1)
If s = "" Then Exit Function
Loop
TrimNull = s
End Function
Function 路径() As String
On Error Resume Next
Dim a As String
a = App.Path
If Right(a, 1) = "\" Then
Else
a = App.Path & "\"
End If
路径 = a
End Function
建议使用INI, 有现成的INI文件读写模块
我在网上找了一个
'保存为读写INI.bas
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Public Function 读取(ByVal a As String, ByVal B As String) As String
Dim ret As Long
Dim buff As String
buff = String(255, 0)
ret = GetPrivateProfileString(a, B, "", buff, 256, 路径 & App.EXEName & ".ini")
If Left(buff, 1) = Chr(0) Then
buff = ""
End If
读取 = TrimNull(buff)
End Function
Public Function 写入(ByVal a As String, ByVal B As String, ByVal C As String) As String
On Error Resume Next
If Dir(路径 & App.EXEName & ".ini") = "" Then
Dim file As Integer
file = FreeFile
Open 路径 & App.EXEName & ".ini" For Append As file
Close file
End If
ret = WritePrivateProfileString(a, B, C, 路径 & App.EXEName & ".ini")
End Function
Function TrimNull(s As String) As String
On Error Resume Next
Do While Left(s, 1) = Chr(0)
s = Mid(s, 2)
If s = "" Then Exit Function
Loop
Do While Right(s, 1) = Chr(0)
s = Left(s, Len(s) - 1)
If s = "" Then Exit Function
Loop
TrimNull = s
End Function
Function 路径() As String
On Error Resume Next
Dim a As String
a = App.Path
If Right(a, 1) = "\" Then
Else
a = App.Path & "\"
End If
路径 = a
End Function
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询