首页 > 电脑 > VB程序设计题目

VB程序设计题目

电脑 2026-11-17

VB程序设计题

1.新建工程:工程1;

2.新建一下ComboBox控件:Combo1,并将属性Style改为2;

3.新建五个Label:Label1,Label2,Label3,Label4,Label5;

4.新建两个Text文本框:Text1,Text2

5.新建一个CommandButton按钮:Command1;

以上的相关控件不要改名字,位置也不用设定,程序会自动设定好。

将下面的代码COPY进去就行了

PrivateSubForm_Load()

Form1.Caption="加油站计费程序"

Form1.Width=3800

Form1.Height=3300

Label1.Caption="种类"

Label1.Move900,200

Label1.AutoSize=1

WithCombo1

.AddItem("90号")

.AddItem("95号")

.AddItem("100号")

.Move500,500,1200

EndWith

Label2.Caption="单价(元/升)"

Label2.Move2000,200

Label2.AutoSize=1

Label3.Caption="0"

Label3.Move2200,550

Label3.Width=500

Label4.Caption="数量"

Label4.Move900,1000

Label4.AutoSize=1

Text1.Move500,1300,1200,300

Text1.Text=0

Text1.Alignment=1

Label5.Caption="总价(元)"

Label5.Move2100,1000

Label5.AutoSize=1

Text2.Move1900,1300,1200,300

Text2.Text=0

Text2.Enabled=False

Text2.Alignment=1

Command1.Caption="计算"

Command1.Move1320,1920,1095,375

EndSub

PrivateSubCombo1_Click()

SelectCaseCombo1.Text

Case"90号":Label3.Caption="2.30"

Case"95号":Label3.Caption="2.45"

Case"100号":Label3.Caption="2.60"

EndSelect

Text1.SetFocus

Text1.SelLength=Len(Text1.Text)

EndSub

PrivateSubCommand1_Click()

OnErrorResumeNext

Text2.Text=Format(Val(Text1.Text)*Val(Label3.Caption),"0.00")

EndSub

VB编程题目

Private Sub Command1_Click()

Label1.Caption = "多预习,问题在心中"

End Sub

Private Sub Command2_Click()

Label1.Caption = "认真听,知识记脑里"

End Sub

Private Sub Command3_Click()

Label1.Caption = "多练习,实践出真知"

End Sub

Private Sub Form_Load()

Label1.FontSize = 20

Label1.Caption = "欢迎学习Visual Basic"

Command1.Caption = "上课前"

Command2.Caption = "上课时"

Command3.Caption = "上课后"

End Sub

求教一道VB程序设计题,题目如下

代码部分如下: sub command1_click() dim a(1 to 3, 1 to 3) as integer, s as integer, i as integer,j as integer s=0 for i=1 to 3 for j=1 to 3 a(i,j)=int(rnd*9)+1 s=s+a(i,j) print a(i,j)," "; next j print next i print s end sub

VB程序设计练习题?

设计界面:

代码:

Private Sub Command1_Click()

Dim n As Long

n = Val(InputBox("输入", "请输入您个年龄", 12))

If n < 18 Then

Print n; "少年"

ElseIf n >= 18 And n < 45 Then

Print n; "青年"

ElseIf n >= 45 And n <= 59 Then

Print n; "中年"

ElseIf n > 59 Then

Print n; "老年"

Else

Print n; "输入年龄错误"

End If

End Sub


Private Sub Command2_Click()

Dim n As Long

n = Val(InputBox("输入", "请输入您个年龄", 12))

Select Case n

Case Is < 18

Print n; "少年"

Case Is > 59

Print n; "老年"

Case Is >= 18

Select Case n

Case Is < 45

Print n; "青年"

Case Else

Print n; "中年"

End Select

Case Else

Print n; "输入年龄错误"

End Select

End Sub

vb编程题目

Private Sub Command1_Click()

If Len(Text1) >= 2 Then

Text1 = Left(Text1, 2)

End If

End Sub

Private Sub Command2_Click()

Text1 = ""

End Sub

Private Sub Form_Load()

Label1.Caption = "新字符串"

Command1.Caption = "左边2个字符"

Command2.Caption = "清空"

Text1 = ""

'这里不知道 三号是多大时,可以手动设置文本框字体大小为三号,然后显示下字体大小,就知道三号字体等于15.75

Print Text1.FontSize

Text1.FontSize = 15.75

Text1.ForeColor = vbRed

Text1 = "aBcDeF"

End Sub


标签:编程语言 编程 信息技术 计算机 电脑网络

大明白知识网 Copyright © 2020-2022 www.wangpan131.com. Some Rights Reserved. 京ICP备11019930号-18