VB中怎样设置将文本框中的数据保存下来?
- 提问者网友:喧嚣尘世
- 2021-05-08 06:50
- 五星知识达人网友:拜訪者
- 2021-05-08 08:00
这个方法可以利用API函数读写配置文件实现,参考例子如下:
首先申明API:
Private 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
Private 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
将Text1的内容保存到E:\a.ini中:
Private Sub Command1_Click()
WritePrivateProfileString "UserName", "User", Text1.Text, "E:\a.ini"
End Sub
将E:\a.ini的内容读取到text2中
Private Sub Command2_Click()
Dim inistring As String
inistring = Space$(254)
GetPrivateProfileString "Username", "User", "", inistring, 255, "E:\a.ini"
Text2.Text = CStr(inistring)
End Sub
- 1楼网友:渡鹤影
- 2021-05-08 11:04
字量少的话,写入注册表,getsettings,savesettings
- 2楼网友:千夜
- 2021-05-08 10:05
- 3楼网友:一把行者刀
- 2021-05-08 08:54