高手指点下 万分感谢! VB - INI
各位VB爱好者 , 如何在 COMBOX 下拉框中 选择 INI 文件里保存的数据 如没有 则手动输入内容并保存到INI中
急求指点 再次感谢大家 。
[解决办法]
getprivateprofilestring() api
[解决办法]
ini文件的读写有很多,站内直接搜吧
[解决办法]
给段代码你参考下:
VB中读取ini配置文件中内容的方法
If Not FileExists(App.Path & "\tool.ini") Then '确认文件是否存在
MsgBox "Can't find tool.ini!", vbInformation, "Information Message:"
End If
Open App.Path & "\tool.ini" For Input As #1 '打开文件
Do While Not EOF(1)
Line Input #1, strTextLine '以回车符为界读取数据
strTextLine = Trim$(strTextLine)
If Left(strTextLine, 3) = "con" Then '客制的判断
strTextLine = Right(strTextLine, Len(strTextLine) - 4)
strArray = Split(strTextLine, ";")
StrDsn = strArray(0)
strDBUserID = strArray(1)
strDBPassword = strArray(2)
Else
strcom = Right(strTextLine, Len(strTextLine) - 4)
End If
Loop
Close #1 '关闭文件
[解决办法]
我这里有个 INI 文件读写操作的例子,楼主参考一下。
【点这里下载 INI.rar 1.9KB】
[解决办法]
正好我有:
Public Function comboLoadFromIni(cmb As ComboBox, cini As cInifile, secname As String) As Long
Dim i As Long, s As String, n As Long
On Error GoTo errr
cini.section = secname
With cmb
.Clear
cini.key = "条数"
s = cini.Value
n = Val(s)
If n = 0 Then GoTo errr
For i = 1 To n
cini.key = "条目" & CStr(i)
s = cini.Value
If s <> "" Then .AddItem s
Next i
cini.key = "当前"
s = cini.Value
If s <> "" Then cmb.Text = s
End With
errr:
End Function
Public Function comboSaveToIni(cmb As ComboBox, cini As cInifile, secname As String) As Long
Dim i As Long, s As String
Dim c As New cInifile
On Error GoTo errr
cini.section = secname
With cmb
cini.key = "条数"
cini.Value = CStr(.ListCount)
cini.key = "当前"
cini.Value = cmb.Text
For i = 0 To .ListCount - 1
s = .List(i)
cini.key = "条目" & CStr(i + 1)
cini.Value = s
Next i
End With
errr:
End Function
[解决办法]
Friendly Up!