VB COMBOX添加选项问题
VB程序,我有2个TXT文本(命名.TXT和举例.TXT)还有COMBO1,COMBO2,COMBO3,COMBO4,COMBO5,COMBO6六个按钮,我想吧COMBO...
VB程序,
我有2个TXT文本(命名.TXT和举例.TXT)
还有COMBO1,COMBO2,COMBO3,COMBO4 ,COMBO5,COMBO6六个按钮,我想吧COMBO1的内容事先在“举例.TXT”里面写好。
“举例.TXT”内容为AA:国家,河流@小溪%贝纳溪
程序打开自动加载。
首先点了COMBO1后显示AA
点了COMBO2显示国家
点了COMBO3显示河流
点了COMBO4显示小溪
点了COMBO5显示贝纳溪
把COMBO6内容在“命名.TXT”也写好
“命名.TXT”内容是BB:
加载程序点他COMBO6显示BB
请大神给个VB代码吧,谢谢。 展开
我有2个TXT文本(命名.TXT和举例.TXT)
还有COMBO1,COMBO2,COMBO3,COMBO4 ,COMBO5,COMBO6六个按钮,我想吧COMBO1的内容事先在“举例.TXT”里面写好。
“举例.TXT”内容为AA:国家,河流@小溪%贝纳溪
程序打开自动加载。
首先点了COMBO1后显示AA
点了COMBO2显示国家
点了COMBO3显示河流
点了COMBO4显示小溪
点了COMBO5显示贝纳溪
把COMBO6内容在“命名.TXT”也写好
“命名.TXT”内容是BB:
加载程序点他COMBO6显示BB
请大神给个VB代码吧,谢谢。 展开
2个回答
展开全部
程序编制完毕,可以正常使用
建议“举例.TXT”中字符串中使用逗号或者空格作为字符串的分隔符,而不要使用像:,@%等分隔,白白增加编程量,如使用逗号分隔,可以删除下列程序
str1 = Replace((str1), ":", ",") '把分隔符替换为","
str1 = Replace((str1), ",", ",")
str1 = Replace((str1), "@", ",")
str1 = Replace((str1), "%", ",")
代码如下
Dim s1, s2
Private Sub Form_Load()
Open "举例.TXT" For Input As #1
Input #1, str1
str1 = "AA:国家,河流@小溪%贝纳溪"
Close #1
Open "命名.TXT" For Input As #2
Input #1, str2
str2 = "BB:"
Close #2
'如果用" " 或者","做分隔符号
str1 = Replace((str1), ":", ",") '把分隔符替换为","
str1 = Replace((str1), ",", ",")
str1 = Replace((str1), "@", ",")
str1 = Replace((str1), "%", ",")
str2 = Replace((str2), ":", "")
'可以取消上面的程序行
Dim a() As String, i As Integer
a = Split(str1, ",") '分割字符串,分割后内容存在数组a中
Combo1.AddItem (a(0))
Combo2.AddItem (a(1))
Combo3.AddItem (a(2))
Combo4.AddItem (a(3))
Combo5.AddItem (a(4))
Combo6.AddItem (str2)
End Sub
若满意请及时采纳,谢谢
建议“举例.TXT”中字符串中使用逗号或者空格作为字符串的分隔符,而不要使用像:,@%等分隔,白白增加编程量,如使用逗号分隔,可以删除下列程序
str1 = Replace((str1), ":", ",") '把分隔符替换为","
str1 = Replace((str1), ",", ",")
str1 = Replace((str1), "@", ",")
str1 = Replace((str1), "%", ",")
代码如下
Dim s1, s2
Private Sub Form_Load()
Open "举例.TXT" For Input As #1
Input #1, str1
str1 = "AA:国家,河流@小溪%贝纳溪"
Close #1
Open "命名.TXT" For Input As #2
Input #1, str2
str2 = "BB:"
Close #2
'如果用" " 或者","做分隔符号
str1 = Replace((str1), ":", ",") '把分隔符替换为","
str1 = Replace((str1), ",", ",")
str1 = Replace((str1), "@", ",")
str1 = Replace((str1), "%", ",")
str2 = Replace((str2), ":", "")
'可以取消上面的程序行
Dim a() As String, i As Integer
a = Split(str1, ",") '分割字符串,分割后内容存在数组a中
Combo1.AddItem (a(0))
Combo2.AddItem (a(1))
Combo3.AddItem (a(2))
Combo4.AddItem (a(3))
Combo5.AddItem (a(4))
Combo6.AddItem (str2)
End Sub
若满意请及时采纳,谢谢
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询