问题:VB用Combo下拉菜单循环读取,并显示在tetx里

读取txt或ini文件,文件里内容:[config]name1=aaaapass1=xxxxname2=bbbbpass2=xxxxname3=ccccpass3=xxx... 读取txt或ini文件,文件里内容:
[config]
name1=aaaa
pass1=xxxx
name2=bbbb
pass2=xxxx
name3=cccc
pass3=xxxx
........不知道会有多少个

两个text,一个Combo下拉菜单

在Combo下拉菜单显示name(i),选择后在text1显示name(i),在text2显示pass(i)

需要详细的代码,谢谢!!!
效果是:
Combo下拉菜单里只显示“aaaa,bbbb,cccc”
点击里面的项目,text1里才显示“aaaa”在text2显示"xxxx"

一楼的代码,显示不出来下拉菜单里的列表项啊
请帮我再写一下吧,我再给你加分
展开
 我来答
aa4681464
2009-11-14 · TA获得超过1138个赞
知道小有建树答主
回答量:922
采纳率:0%
帮助的人:826万
展开全部
100%你的要求
测试成功,,config.ini请放到C盘 当然可以自己更改路径
1个combo,2个text复制代码就可以了
config.ini 的文件内容
[config]
name1=aaaa
pass1=xxxx
name2=bbbb
pass2=xxx
name3=cccc
pass3=xx

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

Function GetFromIni(strSectionHeader As String, strVariableName As String, strFileName As String) As String
Dim strReturn As String
strReturn = String(255, Chr(0))
GetFromIni = Left$(strReturn, GetPrivateProfileString(strSectionHeader, ByVal strVariableName, "", strReturn, Len(strReturn), strFileName))
End Function
' =================
Private Sub Combo1_Click()
Text1.Text = Combo1.Text
Text2.Text = GetFromIni("config", "PASS" & Combo1.ListIndex + 1, "c:\config.ini")
End Sub

Private Sub Form_Load()
Dim a As String, b As Integer
If Dir("c:\config.ini") = "" Then MsgBox "文件不存在": Exit Sub
Do
b = b + 1
a = GetFromIni("config", "name" & b, "c:\config.ini")
If a <> "" Then Combo1.AddItem a
Loop Until a = ""
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式