VB中怎么样使前一次运行的参数值保持不变,在下一次运行时值为前一次运行结束后的值,而不是为0,谢谢!

 我来答
diyddt
2011-11-30
知道答主
回答量:11
采纳率:0%
帮助的人:15.3万
展开全部
使用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
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友e1f44b2
2011-11-30 · TA获得超过715个赞
知道小有建树答主
回答量:1223
采纳率:0%
帮助的人:425万
展开全部
找个文件 把上次的结果存起来.
建议使用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
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式