简单点说就是form1里有一个text1
现在text1.text=500
我想在下一次启动程序时还是500
关闭程序时如果值发生变化了就保存
怎么做?
谁能给个例子
这个问题我问了好几天了
简单点说就是form1里有一个text1
现在text1.text=500
我想在下一次启动程序时还是500
关闭程序时如果值发生变化了就保存
怎么做?
谁能给个例子
这个问题我问了好几天了
你是不是想要实现用户在文本框输入的内容就保存其所输入的内容吗?我做了一个小例子详见下图
所需控件:
一个命令按钮
一个标签
一个文本框
另外你在程序根目录下做一个.txt的记事本(可以自由命名),这一个小例子的原理就是:窗体运行时text1.text=500,当text1.text不等于(<>)500时就将其所改变的值保存在其根目录的text1值发生改变记录.txt 下
好巧啊
我刚完成一个网上找的类模块,你新建个类模块,在模块中加入代码
Private Declare Function GetProfileInt Lib "kernel32" Alias "GetProfileIntA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpfilename As String) As Long Private Declare Function GetProfileString Lib "kernel32" Alias "GetProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, lpfilename As String) As Long Private Declare Function WriteProfileString Lib "kernel32" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String, lpfilename As String) As Long Private iniFileName As String Public ERRmsg As String Private Sub class_initialize() iniFileName = vbNullString ERRmsg = vbNullString End Sub Public Sub specifyini(FilePathName) iniFileName = Trim(FilePathName) End Sub Private Function noinifile() As Boolean noinifile = True If iniFileName = vbNullString Then ERRmsg = "没有找到ini文件" Exit Function End If ERRmsg = vbNullString noinifile = False End Function Public Function writestring(section As String, key As String, value As String) As Boolean writestring = False If noinifile = True Then Exit Function End If If WriteProfileString(section, key, value, iniFileName) = 0 Then ERRmsg = "写入INI文件失败" End If writestring = True End Function Public Function Readstring(section As String, key As String, size As Long) As String Dim returnstring As String Readstring = vbNullString If noinifile = True Then Exit Function End If returnstring = Space(size) GetProfileString section, key, vbNullString, returnstring, size, iniFileName Readstring = Trim(returnstring) End Function Public Function ReadInt(section As String, key As String) As Long Dim returnlng As Long ReadInt = 0 If noinifile = True Then Exit Function End If returnlng = GetProfileInt(section, key, 0, iniFileName) If returnlng = 0 Then returnlng = GetProfileInt(section, key, 1, iniFileName) If returnlng = 1 Then ERRmsg = "不能读取" Exit Function End If End If ReadInt = returnlng End Function 在text1_change()中写入代码
on error goto err1
dim txt as string
txt=text1.text
writestring "你的ini文件的段","你的ini文件的段里的某个值",txt
exit sub
errr1:
msgbox errmsg
end sub
存个文本文件在程序目录下,保存这个数值就可以了嘛