如combo1 下有 a b c 打开程序 选择了b 然后关闭程序 要想第二次打开显示的是b 而不是默认值 怎么弄啊
不行啊 第二次运行时说是无效属性值
vb combo 保存列表
答案:2 悬赏:10 手机版
解决时间 2021-01-28 05:11
- 提问者网友:半生酒醒
- 2021-01-27 05:09
最佳答案
- 五星知识达人网友:青灯有味
- 2021-01-27 05:57
文件或者注册表,以下为文件的方法
代码如下
Private Sub Form_load()
'原来的代码放在这里
If Dir(App.Path & "\combo.txt") <> "" Then
Open App.Path & "\combo.txt" For Input As #1
Line Input #1, tem
Combo1.ListIndex = tem
Close #1
End If
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Open App.Path & "\combo.txt" For Output As #1
Print #1, Combo1.ListIndex
Close #1
End Sub
我测试了没问题啊,除非你原来的代码有问题,比如combo初始没有设置值
这样吧,完整的代码是这样的,运行后随便选择一个,关闭窗口,然后再打开试下
Private Sub Form_load()
Combo1.AddItem "1"
Combo1.AddItem "2"
Combo1.AddItem "3"
If Dir(App.Path & "\combo.txt") <> "" Then
Open App.Path & "\combo.txt" For Input As #1
Line Input #1, tem
Combo1.ListIndex = tem
Close #1
End If
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Open App.Path & "\combo.txt" For Output As #1
Print #1, Combo1.ListIndex
Close #1
End Sub
代码如下
Private Sub Form_load()
'原来的代码放在这里
If Dir(App.Path & "\combo.txt") <> "" Then
Open App.Path & "\combo.txt" For Input As #1
Line Input #1, tem
Combo1.ListIndex = tem
Close #1
End If
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Open App.Path & "\combo.txt" For Output As #1
Print #1, Combo1.ListIndex
Close #1
End Sub
我测试了没问题啊,除非你原来的代码有问题,比如combo初始没有设置值
这样吧,完整的代码是这样的,运行后随便选择一个,关闭窗口,然后再打开试下
Private Sub Form_load()
Combo1.AddItem "1"
Combo1.AddItem "2"
Combo1.AddItem "3"
If Dir(App.Path & "\combo.txt") <> "" Then
Open App.Path & "\combo.txt" For Input As #1
Line Input #1, tem
Combo1.ListIndex = tem
Close #1
End If
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Open App.Path & "\combo.txt" For Output As #1
Print #1, Combo1.ListIndex
Close #1
End Sub
全部回答
- 1楼网友:神也偏爱
- 2021-01-27 07:10
使用combo1.listindex之前,在combo中必须有足够的选项才可以。你在窗体加载之前并没有给combox加载东西,当然会出错了
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯