当前位置:科普知识站>综合知识>

vb两个数相乘怎么写程序|怎么用vb制作两位数相乘的程序

综合知识 阅读(2.86W)
1.怎么用vb制作两位数相乘的程序

可以先插入两个文本框控件用来放要输入的两个乘数,插入一个标签控件来放得出的积,界面可以自己设计,代码如下Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then If Len(Text1.Text) <= 2 Then Text2.SetFocus Else Text1.Text = "" End If End IfEnd SubPrivate Sub Text2_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Label1.Caption = "=" & Str(Val(Text1.Text) * Val(Text2.Text)) End IfEnd Sub第一个文本框加了一个数位识别,如果要有新的变化,可以自己探索一下。

vb两个数相乘怎么写程序 怎么用vb制作两位数相乘的程序
2.怎么用vb制作两位数相乘的程序

可以先插入两个文本框控件用来放要输入的两个乘数,插入一个标签控件来放得出的积,界面可以自己设计,代码如下

Private Sub Text1_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then

If Len(Text1.Text) Text2.SetFocus

Else

Text1.Text = ""

End If

End If

End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then

Label1.Caption = "=" & Str(Val(Text1.Text) * Val(Text2.Text))

End If

End Sub

第一个文本框加了一个数位识别,如果要有新的变化,可以自己探索一下。

3.怎样用VB产生两个随机数相乘后累加的小程序

Dim zhi1 as Integer

Dim zhi2 as Integer

zhi1 =Int(100*Rnd)

zhi2 =Int(100*Rnd)

Print “结果算式:" & zhi1 & “+" & zhi2 & “=" & zhi1 + zhi2

//把上面代码的过程放到一个按钮事件就可以了。 Rnd是会随机生成一个大于等于0小于1的一个随机单精度数,int((最大数-最小数)*Rnd-最小数)

4.【VB6.0】两数相乘

'输出成绩的文本框的enabled属性设为false

'三个文本框的名称分别为text1,text2,text3

'两个按钮名称分别为command1,command2

Private Sub Command1_Click()

Text1.Text = ""

Text2.Text = ""

Text3.Text = ""

End Sub

Private Sub Command2_Click()

Text3.Text = Str(Val(Text1.Text) * Val(Text2.Text))

End Sub

Private Sub Text1_Change()

If Not (IsNumeric(Text1.Text) Or Text1.Text = "-" Or Text1.Text = "+" Or Text1.Text = "") Then

Text1.Text = ""

MsgBox "请输入数字!"

End If

End Sub

Private Sub Text2_Change()

If Not (IsNumeric(Text2.Text) Or Text2.Text = "-" Or Text2.Text = "+" Or Text2.Text = "") Then

Text1.Text = ""

MsgBox "请输入数字!"

End If

End Sub