0 Then lstcity.AddItem txtcity.Text txtcity.Text = "" txtcity.SetFocus End If End Sub Private Sub cmdClear_Click() lstcity."/> 0 Then lstcity.AddItem txtcity.Text txtcity.Text = "" txtcity.SetF"/>
首页 > vb列表框控件的使用

vb列表框控件的使用

2017-12-27 19页 doc 45KB 35阅读

用户头像

is_569018

暂无简介

举报
vb列表框控件的使用vb列表框控件的使用 列表框控件的使用 Private Sub Form_Load() txtcity.Text = "" End Sub Private Sub cmdAppend_Click() If Len(Trim(txtcity.Text)) > 0 Then lstcity.AddItem txtcity.Text txtcity.Text = "" txtcity.SetFocus End If End Sub Private Sub cmdClear_Click() lstcity.Clear ...
vb列表框控件的使用
vb列框控件的使用 列表框控件的使用 Private Sub Form_Load() txtcity.Text = "" End Sub Private Sub cmdAppend_Click() If Len(Trim(txtcity.Text)) > 0 Then lstcity.AddItem txtcity.Text txtcity.Text = "" txtcity.SetFocus End If End Sub Private Sub cmdClear_Click() lstcity.Clear End Sub Private Sub cmdDelete_Click() If lstcity.ListIndex >= 0 Then lstcity.RemoveItem (lstcity.ListIndex) End If End Sub Private Sub lstcity_Click() lblresult.Caption = "你的选择是 - - " & lstcity.Text End Sub 日期时间及控件.计时器控件 Private Sub Command1_Click() Text1.Text = Date End Sub Private Sub Command2_Click() Text1.Text = Time End Sub Private Sub Command3_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Text1.Text = Date End Sub Private Sub Command3_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Text1.Text = Time End Sub 计时器控件 Private Sub Command1_Click() Timer1.Enabled = True End Sub Private Sub Command2_Click() Timer1.Enabled = False End Sub Private Sub Timer1_Timer() Label6.Caption = Label6.Caption + 1 If Label6.Caption = 60 Then Label6.Caption = 0 If Label6.Caption = 0 Then Label4.Caption = Label4.Caption + 1 If Label4.Caption = 60 Then Label4.Caption = 0 Label2.Caption = Label2.Caption + 1 End If End Sub KeyPress事件 Private Sub Command1_Click() Timer1.Enabled = True Label1.Caption = Chr(Int(Rnd() * 26 + 65)) Text1.SetFocus End Sub Private Sub Form_Load() Label1.Caption = "" Label2.Caption = 0 End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = Asc(Label1.Caption) Then Label2.Caption = Label2.Caption + 1 Label2.Top = 0 Label1.Caption = Chr(Int(Rnd() * 26 + 65)) Text1.SelLength = 0 Text1.SelLength = 1 End If End Sub Private Sub Timer1_Timer() Label1.Top = Label1.Top + 200 If Label1.Top > 8000 Then Label1.Top = 0 Label1.Caption = Chr(Int(Rnd() * 26 + 65)) End If End Sub 静态数组、动态数组 静态数组 Private Sub Command1_Click() Dim i As Integer Dim a(1 To 10) As Integer Dim sum As Integer sum = 0 For i = 1 To 10 a(i) = Int(Rnd * 10 + 1) Print a(i); sum = sum + a(i) Next i Print Print "平均值是:"; sum \ 10 End Sub 动态数组 Private Sub Command1_Click() Dim i As Integer Dim a(), sum As Integer sum = 0 n = InputBox("请输入个数", "输入", , 5000, 5000) ReDim a(1 To n) For i = 1 To n a(i) = Int(Rnd * 40) Print a(i); sum = sum + a(i) Next i Print Print n, "个数的平均值是:"; sum \ n End Sub 文本框控件的使用 text1 name txtusername maxlenth 8 tooltiptext 请输入用户名 text2 name txtpassword maxlenth 8 tooltiptext 请输入密码 passwordchar * command1 name cmdok caption (&o) default true command2 name cmdcancel caption (&c) cancel true Private Sub Form_Load() txtusername.Text = "" txtpassword.Text = "" End Sub Private Sub txtusername_GotFocus() txtusername.SelStart = 0 txtusername.SelLength = Len(txtusername.Text) End Sub 命令按钮控件的使用 Private Sub cmdcancel_Click() End End Sub Private Sub Form_Load() cmdsave.Caption = "保存(&S)" Cmddelete.Visible = False cmdappend.Enabled = False End Sub 电子邮件解析 Private Sub Command1_Click() Dim str As String Dim p As String str = Text1.Text p = InStr(1, str, "@") Text2.Text = Left(str, p - 1) Text3.Text = Mid(str, p + 1) End Sub 身份证解析 Private Sub Command1_Click() Dim str As String str = Text1.Text Text2.Text = Format(Mid(str, 7, 8), "&&&&年&&月&&日") If Mid(str, 11, 1) Mod 2 <> 0 Then Text3.Text = "男" Else: Text3.Text = "女" End If End Sub 调色板 Private Sub Command1_Click() Text4.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value) End Sub 调色板、 Private Sub HScroll1_Change() Label1.Caption = "红色" + Str(HScroll1.Value) Text1.BackColor = RGB(HScroll1.Value, 0, 0) End Sub Private Sub HScroll2_Change() Label1.Caption = "黄色" + Str(HScroll2.Value) Text2.BackColor = RGB(0, HScroll2.Value, 0) End Sub Private Sub HScroll3_Change() Label1.Caption = "蓝色" + Str(HScroll3.Value) Text3.BackColor = RGB(0, 0, HScroll3.Value) End Sub 矩形面积、显示最大值最小值、商品库存信息 Private Sub Command1_Click() Dim a, b, s As Single a = Text1.Text b = Text2.Text s = a * b Print Print "矩形的面积是"; s End Sub 或者 Private Sub Command1_Click() Dim a, b, s As Single a = InputBox("请输入矩形的长", "计算矩形面积") b = InputBox("请输入矩形的宽", "计算矩形面积") s = a * b MsgBox "矩形的面积是:" & s, vbOKOnly, "矩形的面积" End Sub 显示最大值最小值 Private Sub Command1_Click() Dim x, y As Integer a As String, b As String x = InputBox("请输入X的值", "输入信息") y = InputBox("请输入Y的值", "输入信息") If x > y Then a = x If x < y Then b = x choice = MsgBox("请选择", vbYesNo + vbQuestion + vbDefaultButton2, " 选择") If choice = vbYes Then MsgBox "最大值是:", a, vbOKOnly, "选择结果" Else MsgBox "最小值是:", b, vbOKOnly, "选择结果" End Sub 商品库存信息 Private Sub Command1_Click() Print Print Tab(18); "商品名称"; Spc(2); "单价"; Spc(6); "数量" Print Print Tab(18); "电视机"; Spc(2); "2580"; Spc(6); "150" Print Print Tab(18); "电脑"; Spc(2); "7850"; Spc(6); "50" Print Print Tab(18); "电冰箱"; Spc(2); "1600"; Spc(6); "5" End Sub 健康测试 Private Sub Command1_Click() Dim name As String, result As String Dim x As String, y As String name = InputBox("请输入您的名字~", "输入信息") x = InputBox("请输入您的身高(厘米)~", "输入信息") y = InputBox("请输入您的体重(公斤)~", "输入信息") result = "完全正常" If y > (x - 100) * 0.9 * 1.1 Then result = "偏胖" If y < (x - 100) * 0.9 * 0.9 Then result = "偏瘦" MsgBox "您的体形:" + result, vbOKOnly, "测试结果" Print Tab(4); "姓名", Spc(2); "身高", Spc(2); "体重", "结果" Print Tab(4); name, x; "厘米", y; "公斤", result choice = MsgBox("您对自己的体形满意吗,", vbYesNo + vbQuestion + vbDefaultButton2, "调查") If choice = vbYes Then MsgBox "恭喜你", , "调查结果" Else MsgBox "请努力吧~", , "调查结果" End If End Sub 比点数。。。 Dim x As Integer, y As Integer, z As Integer, s As Integer Private Sub Command1_Click() Timer1.Enabled = True End Sub Private Sub Command2_Click() Timer1.Enabled = False If Option1.Value = True Then Picture4.Picture = LoadPicture(IIf(s >= 9, App.Path & "\v.gif", App.Path & "\cry.gif")) If Option2.Value = True Then Picture4.Picture = LoadPicture(IIf(s < 9, App.Path & "\v.gif", App.Path & "\cry.gif")) End Sub Private Sub Timer1_Timer() Randomize x = Int(Rnd() * 6 + 1) y = Int(Rnd() * 6 + 1) z = Int(Rnd() * 6 + 1) s = x + y + z Picture1.Picture = LoadPicture(App.Path & "\" & CStr(Int(x)) & ".jpg") Picture2.Picture = LoadPicture(App.Path & "\" & CStr(Int(y)) & ".jpg") Picture3.Picture = LoadPicture(App.Path & "\" & CStr(Int(z)) & ".jpg") Label1.Caption = IIf(s >= 9, CStr(s) + "点大", CStr(s) + "点小") End Sub 按钮练习 Private Sub Command1_Click() If Command1.Caption = "开始" Then Command1.Enabled = False Command2.Enabled = True End If End Sub Private Sub Command2_Click() If Command2.Caption = "第一步" Then Command2.Enabled = False Command3.Enabled = True End If End Sub Private Sub Command3_Click() If Command3.Caption = "第二步" Then Command3.Enabled = False Command4.Enabled = True End If End Sub Private Sub Command4_Click() If Command4.Caption = "第三步" Then Command4.Enabled = False Command5.Enabled = True End If End Sub Private Sub Command5_Click() If Command5.Caption = "第四步" Then Command5.Enabled = False Command6.Enabled = True End If End Sub Private Sub Command6_Click() If Command6.Caption = "结束" Then Command6.Enabled = False Command1.Enabled = True End If End Sub &运算符、找小偷、KeyPressl 练习、循环练习 &运算符 Private Sub Command1_Click() Label1.Caption = "x+y=" & Text1.Text & "+" & Text2.Text & "=" & Val(Text1.Text) + Val(Text2.Text) End Sub 整除和取余运算的应用 Private Sub Command1_Click() Dim num As Double num = Text1.Text Text2.Text = num \ 10000 Text3.Text = (num Mod 10000) \ 1000 Text4.Text = (num Mod 1000) \ 100 Text5.Text = (num Mod 100) \ 10 Text6.Text = num Mod 10 End Sub 找小偷 Private Sub Command1_Click() Text2.Text = Not (Text1.Text <> "A") Text3.Text = Not (Text1.Text = "C") Text4.Text = Not (Text1.Text = "D") Text5.Text = Not (Text1.Text <> "D") End Sub KeyPressl 练习 Private Sub Text1_KeyPress(KeyAscii As Integer) Text1.SelStart = 0 Text1.SelLength = 1 If KeyAscii < 65 Or KeyAscii > 90 Then KeyAscii = 0 End If End Sub Private Sub Text2_KeyPress(KeyAscii As Integer) Text2.SelStart = 0 Text2.SelLength = 1 If KeyAscii < 97 Or KeyAscii > 122 Then KeyAscii = 0 End If End Sub Private Sub Text3_KeyPress(KeyAscii As Integer) Text3.SelStart = 0 Text3.SelLength = 1 If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0 End If End Sub 循环练习 Private Sub Command1_Click() Dim i As Integer, n As Integer, num As Integer, largest As Integer Dim smallest As Integer, sum As Integer Cls n = Val(Text1.Text) smallest = 100 largest = 0 sum = 0 For i = 1 To n If i Mod 20 = 0 Then Print num = Int(Rnd() * 100 + 1) Print num; sum = sum + num If largest < num Then largest = num If smallest > num Then smallest = num Next i Label2.Caption = "最大数为" & largest Label3.Caption = "最小数为" & smallest Label4.Caption = "总和为" & sum End Sub Private Sub Command1_Click() Dim i As Integer, c As Integer, num As Integer Cls c = 0 Do num = Int(Rnd * 100 + 1) Print num; c = c + 1 If c Mod 20 = 0 Then Print Loop While num < 100 Label2.Caption = "次数为" & c End Sub 平行四边形,倒三角,菱形,空心菱形 平行四边形 Private Sub Command1_Click() Dim i As Integer, j As Integer, n As Integer Cls n = Val(Text1.Text) For i = 1 To n Print Spc(n - i + 1); For j = 1 To n Print "*"; Next j Print Next i End Sub 倒三角 Private Sub Command2_Click() Dim i As Integer, j As Integer, n As Integer Cls n = Val(Text1.Text) For i = 1 To n Print Spc(i); For j = 1 To 2 * (n - i) + 1 Print "*"; Next j Print Next i End Sub 菱形 Private Sub Command3_Click() Dim i As Integer, j As Integer, n As Integer Cls n = Val(Text1.Text) For i = 1 To n Print Spc(n - i + 1); For j = 1 To 2 * i - 1 Print "*"; Next j Print Next i For i = 1 To n Print Spc(i); For j = 1 To 2 * (n - i) + 1 Print "*"; Next j Print Next i End Sub 空心菱形 Private Sub Command4_Click() Dim i As Integer, j As Integer, n As Integer Cls n = Val(Text1.Text) Print Spc(n); "*" For i = 2 To n Print Spc(n - i + 1); "*"; For j = 1 To 2 * i - 3 Print Spc(1); Next j Print "*" Next i For i = 1 To n - 1 Print Spc(i); "*"; Print Spc(2 * (n - i) - 1); "*" Next i Print Spc(n); "*" End Sub 水仙花、do loop 循环、exit for练习 上机题 (4)水仙花 Private Sub Command1_Click() Dim i As Integer, c As Integer For i = 100 To 999 Step 1 If (i \ 100) ^ 3 + (i \ 10 Mod 10) ^ 3 + (i Mod 10) ^ 3 = i Then c = c + 1 Print "第"; c; "个水仙花数是:"; i End If Next i End Sub (5)do loop 循环 Private Sub Command1_Click() Dim i As Integer Dim s As Integer Dim a As Integer a = Text1.Text i = 1 Do While s < a s = s + i i = i + 1 Loop Text2.Text = i - 1 Text3.Text = s End Sub (6)exit for练习 Private Sub Command1_Click() Cls Randomize Dim c As Integer, i As Integer, n As Integer For i = 1 To 10 n = Int(Rnd * 90 + 10) If n Mod 2 = 0 Then c = c + 1 Print n; " "; "***" Else Print n End If If c = 4 Then i = i + 1 Exit For End If Next i Print Print "共产生了"; i; "个数" End Sub 里程与折扣 里程与折扣标准 Private Sub Command1_Click() Dim a As Single, b As Single, c As Single, d As Single a = Val(Text1.Text) b = Val(Text2.Text) c = Val(Text3.Text) If c < 500 Then d = a * b * c ElseIf c < 1000 Then d = a * b * c * 0.98 ElseIf c < 2000 Then d = a * b * c * 0.97 ElseIf c < 4000 Then d = a * b * c * 0.95 Else d = a * b * c * 0.92 End If Text4.Text = d End Sub Private Sub Command1_Click() Dim a As Single, b As Single, c As Single, d As Single a = Val(Text1.Text) b = Val(Text2.Text) c = Val(Text3.Text) Select Case c Case Is < 500 d = a * b * c Case Is < 1000 d = a * b * c * 0.98 Case Is < 2000 d = a * b * c * 0.97 Case Is < 4000 d = a * b * c * 0.95 Case Else d = a * b * c * 0.92 End Select Text4.Text = d End Sub
/
本文档为【vb列表框控件的使用】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索