VB 操作INI问题

来源:百度知道 编辑:UC知道 时间:2024/05/16 15:21:34
已知一个例子,如何把文本框换为组合框?
比如 ini文件内容:xxxx=fast(有fastnormal,slow可选)
组合框内容“快速”“中等”“最慢”如何对应?

请於form中放3个TextBox,一个CommandBox
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 Sub Command1_Click()
Dim success As Long
success = WritePrivateProfileString("MyApp", "text1", Text1.Text, "c:\aa.ini")
'叁数一 Section Name
'叁数二 於.ini中的项目
'叁数三 项目的内容


不太看明你想要求怎要对应组合框内容,是要从INI读取来对应?

能说清楚点吗?

vb里有CommandBox控件吗? 汗!

================================================================
补充例子:

Private Sub Form_load()
Dim ret As Long
Dim buff As String * 256
Dim mVal As Long

Combo1.AddItem "是"
Combo1.AddItem "否"

ret = GetPrivateProfileString("Myapp", "xxxx", "0", buff, 256, "c:\aa.ini")
mVal = Val(Left(buff, InStr(1, buff, vbNullChar) - 1))

If mVal > 1 Then mVal = 1

Select Case mVal
Case 0: Combo1.Text = "否"
Case 1: Combo1.Text = "是"
End Select

End Sub

Private Sub Command1_Click()
Dim success As Long
'保存
Select Case Trim(Combo1.Text)
Case "是"
success = WritePrivateProf