可以先插入兩個文字框控制元件用來放要輸入的兩個乘數,插入一個標籤控制元件來放得出的積,介面可以自己設計,程式碼如下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第一個文字框加了一個數位識別,如果要有新的變化,可以自己探索一下。
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