【求救】高手们快来帮小妹解决一道VB组合框添加和删除操作程序

1.编写程序,用组合框显示选修课列表,用添加、删除按钮对选修课进行添加和删除操作一个combobox一个listbox一个text五个command按钮在combobox... 1.编写程序,用组合框显示选修课列表,用添加、删除按钮对选修课进行添加和删除操作 一个combobox 一个listbox 一个text 五个command按钮 在combobox手动添加课程 点“添加课程”按钮 加入到listbox 同时text1 里显示listbox的课程数,没有输入直接点command1,会出现提示MsgBox"请选择要添加的内容! command2删除时没有选中课程会提示MsgBox "请选择要删除的课程!",(注:command2删除时你还得选中它才能删除) 下面是界面图:
谢谢各位了!!!
"隐藏所有课程"的代码我知道,直接加上就行
Private Sub Command4_Click()
List1.Visible = Not List1.Visible
If List1.Visible = True Then
Command4.Caption = "隐藏所有课程"
Else
Command4.Caption = "显示所有课程"
End If
End Sub

谢谢各位了!!!能讲解一下再好不过了
展开
 我来答
qifeng031
2008-10-22 · TA获得超过130个赞
知道小有建树答主
回答量:236
采纳率:0%
帮助的人:0
展开全部
确实太繁琐了,现在上班忙啊,没时间写了。等晚上要是有时间就帮你写一个。
花了点时间写了一下。那个隐藏的功能你知道了就自己加进去,我就没写了。可能有bug,好久没用vb了,挺生疏的。
还有我在日本,机器都是日文系统,vb也是,显示不了中文,其中的名字什么的你自己改成对应的就可以了,我想这不难吧。

晕,果然有bug,改了一下。vb6.0 pass如果再有bug你自己改吧。

Public c As Boolean 'to make sure there are not same items in combo1
Public l As Boolean 'to make sure there are not same items in list1

Private Sub Command1_Click()

Call chklst(List1, Combo1.text)
Call chkcmb(Combo1, Combo1.text)
If l = True Then
If c = True Then

If Combo1.text = "" Then
MsgBox "Please enter one item", vbOKOnly, "Error" 'give a error messagebox
Exit Sub
End If

With Combo1 'add items in combo1
.AddItem Combo1.text
End With

End If

With List1 'add items in list1 and refresh the totalcount in text1
.AddItem Combo1.text
End With
Text1.text = List1.ListCount

End If

End Sub

Private Sub Command2_Click()

If List1.ListCount = 0 Then
MsgBox "No item", vbOKOnly, "error" 'give a error messagebox
Exit Sub
End If

For i = 0 To List1.ListCount - 1
If List1.Selected(i) = True Then

With List1 'delete items and refresh the totalcount in text1
If List1.ListIndex = -1 Then
MsgBox "select one item", vbOKOnly, "error" 'give a error messagebox
Exit Sub
End If
List1.RemoveItem List1.ListIndex 'delete items
End With

Text1.text = List1.ListIndex 'refresh the totalcount in text1
Exit Sub

End If
Next

MsgBox "select one item", vbOKOnly, "error" 'give a error messagebox
Exit Sub
End Sub

Private Sub Command3_Click()
List1.Clear
Text1.text = 0
End Sub

Private Sub Command5_Click()
End
End Sub
'************************************************************
'******Initialize
'************************************************************
Private Sub Form_Load()
With List1
.AddItem "course1"
.AddItem "course2"
.AddItem "course3"
.AddItem "course4"
End With
Command1.Caption = "add"
Command2.Caption = "delete"
Command3.Caption = "clear"
Command4.Caption = "hide"
Command5.Caption = "end"
Label1.Caption = "total count"
Text1.text = List1.ListCount

End Sub
'************************************************
'** to make sure there are not same items in combo1
'** true:there are not same items
'** false:there are same items
'************************************************
Public Function chkcmb(combobox As combobox, text As String)
If Combo1.ListCount = 0 Then
c = True
Exit Function
End If

For i = 0 To Combo1.ListCount - 1
If Combo1.List(i) = text Then
c = False 'there are same items
Exit Function
End If
Next
c = True 'there are no same items

End Function
'**********************************************
'** to make sure there are not same items in list1
'** true:there are not some items
'** false:there are same items
'**********************************************
Public Function chklst(listbox As listbox, text As String)
If List1.ListCount = 0 Then
l = True
Exit Function
End If

For i = 0 To List1.ListCount - 1
If List1.List(i) = text Then
l = False 'there are same items
Exit Function
End If
Next
l = True 'there are no same items

End Function

最后声明一点,不是为了要你的分,我玩c++头痛,想休息下,哈哈。
43295811
2008-10-21 · TA获得超过1529个赞
知道大有可为答主
回答量:1701
采纳率:0%
帮助的人:2163万
展开全部
小妹妹,问题很简单,就是繁琐,10分太少了,因为太浪费时间!!

Private Sub Command1_Click()
List1.AddItem Combo1.Text
Text1 = List1.ListCount
End Sub

Private Sub Command2_Click()
If List1.ListIndex = -1 Then Exit Sub
List1.RemoveItem List1.ListIndex
Text1 = List1.ListCount
End Sub

Private Sub Command3_Click()
List1.Clear
End Sub

Private Sub Command4_Click()
'不写了,按照你的代码就行了
End Sub

Private Sub Command5_Click()
Unload Me
End Sub

第4个按钮,就是切换list的可见状态用的!!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
すうちやん
2008-10-22 · TA获得超过132个赞
知道答主
回答量:152
采纳率:0%
帮助的人:0
展开全部
看书,看书,再难的知识点书上都会有,包括参考书,建议看清华出版社的,比较精髓
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
在白石湖写影评的匹诺曹
2008-10-22 · TA获得超过204个赞
知道答主
回答量:189
采纳率:0%
帮助的人:82.9万
展开全部
我对这些一窍不通
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式