VB读写配置INI文件

我用VB写了个登录界面,登录模块已写好,已成功连接,但每次都要输入主机名和数据,有没有方法写个配置文件,只需第一次输入,然后点击一下数据库检查按钮,如果输入信息正确,然后... 我用VB写了个登录界面,登录模块已写好,已成功连接,但每次都要输入主机名和数据,有没有方法写个配置文件,只需第一次输入,然后点击一下数据库检查按钮,如果输入信息正确,然后生成一个文件,下次登录时自动读取这个文件里的内容,以后就用输入了 展开
 我来答
匿名用户
2013-09-12
展开全部
用INI文件的读写函数比较好
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

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 Function WriteIniFileString(StandKey As String, keyName As String, keyValue As String, FileName) As Long
'写INI文件函数
Dim leninikey As Long
Dim strkey As String * 255
WriteIniFileString = WritePrivateProfileString(StandKey, keyName, keyValue, FileName)

End Function

Private Function GetIniFileString(StandKey As String, keyName As String, Default As String, FileName As String) As String
'读取INI文件函数
Dim leninikey As Long
Dim strkey As String * 255
leninikey = GetPrivateProfileString(StandKey, keyName, Default, strkey, Len(strkey), FileName)
匿名用户
2013-09-12
展开全部
'添加一个复选控件,如果有什么不明白可以加我的Q,,,,8 5 81 38 Dim szUserName As String
Dim szPassWord As String
Private Sub Command1_Click()
szUserName = Text1.Text
szPassWord = Text2.Text
If Check1.Value = 1 Then
Open App.Path & "\v2.ini" For Output As #1
Print #1, szUserName
Print #1, szPassWord
Close #1
Else
Kill App.Path & "\v2.ini"
End If
End SubPrivate Sub Form_Load()
Check1.Caption = "记住密码"
Check1.Value = 1
Open App.Path & "\v2.ini" For Input As #1
Line Input #1, szUserName
Line Input #1, szPassWord
Close #1
If szUserName <> "" And szPassWord <> "" Then
Text1.Text = szUserName
Text2.Text = szPassWord
End If
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2013-09-12
展开全部
'API信息Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
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自己修改下'每次运行程序后执行下面代码ok
Private Sub Command1_Click()
'读 ini 文件
Dim F As String, nStr As String, nSize As Long, S As Long
F = "d:\optionv5.ini"
F = App.Path & "\optionv5.ini"
nSize = 255: nStr = String(nSize, 0)
dl = GetPrivateProfileString("Option", "FilterVer", "", nStr, nSize, F)
S = InStr(nStr, Chr(0))
If S > 0 Then nStr = Left(nStr, S - 1)
MsgBox "读出为:" & nStr '字符串 nStr 就是读出的等号后的内容
'可以换成ladle的方式提醒'或者text1.text=nStr就可以了End Sub'然后是写入信息,每次关闭时自己写入form_upload()什么的忘记了
Private Sub Command2_Click()
'写 ini 文件
Dim F As String
F = "C:My.ini"
dl = WritePrivateProfileString("Option", "FilterVer", "写入的信息", F)
If dl <> 0 Then MsgBox "写 ini 文件成功"'写入的信息可以这样("..","..",text1.text,F)End Subini文件信息[Option]FilterVer=4
MusicZoneOpenPercent=0
KeepLiveTick=45000("Public", "FilterVer", "CCC", F)
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式