vb关于combobox
combo1有:abcdeftxt的数据:abc=123def=213当选择了一个数据在combo1(假设是abc)时,要如何写才可以在txt里寻找有否数据?然后只显示(...
combo1有:
abc
def
txt的数据:
abc=123
def=213
当选择了一个数据在combo1(假设是abc)时,要如何写才可以在txt里寻找有否数据?然后只显示(123)在label1?我是新手,请给予代码。
private sub form_Load
Open App.Path & "\1.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, a
Combo1.AddItem (a)
Loop
Close #1
end sub
我只能把数据显示在combo1. 展开
abc
def
txt的数据:
abc=123
def=213
当选择了一个数据在combo1(假设是abc)时,要如何写才可以在txt里寻找有否数据?然后只显示(123)在label1?我是新手,请给予代码。
private sub form_Load
Open App.Path & "\1.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, a
Combo1.AddItem (a)
Loop
Close #1
end sub
我只能把数据显示在combo1. 展开
展开全部
'假设1.txt内容为:
'abc=123
'def = 213
'添加一个combobox和一个label,粘贴如下代码
Dim a() As String
Private Sub Combo1_Click()
Dim i As Integer
If Len(Combo1.Text) > 0 Then
For i = 0 To UBound(a) - 1
If Combo1.Text = Left(a(i), InStr(a(i), "=") - 1) Then
Label1.Caption = Mid(a(i), InStr(a(i), "=") + 1)
Exit Sub
End If
Next i
End If
End Sub
Private Sub Form_Load()
Open App.Path & "\1.txt" For Input As #1
Dim i As Integer
ReDim Preserve a(0 To i) As String
Do While Not EOF(1)
Line Input #1, a(i)
Combo1.AddItem Left(a(i), InStr(a(i), "=") - 1)
i = i + 1
ReDim Preserve a(0 To i) As String
Loop
Combo1.Text = ""
Close #1
End Sub
'abc=123
'def = 213
'添加一个combobox和一个label,粘贴如下代码
Dim a() As String
Private Sub Combo1_Click()
Dim i As Integer
If Len(Combo1.Text) > 0 Then
For i = 0 To UBound(a) - 1
If Combo1.Text = Left(a(i), InStr(a(i), "=") - 1) Then
Label1.Caption = Mid(a(i), InStr(a(i), "=") + 1)
Exit Sub
End If
Next i
End If
End Sub
Private Sub Form_Load()
Open App.Path & "\1.txt" For Input As #1
Dim i As Integer
ReDim Preserve a(0 To i) As String
Do While Not EOF(1)
Line Input #1, a(i)
Combo1.AddItem Left(a(i), InStr(a(i), "=") - 1)
i = i + 1
ReDim Preserve a(0 To i) As String
Loop
Combo1.Text = ""
Close #1
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询