一道比较简单的VB程序题目,只需要代码即可 100
在上方文本框Text1中写入普通手机号码,点击转换按钮Command1,将普通手机号码转为加横线的手机号码写入Text2文本框中。相反,在下方文本框Text2中写入加横线...
在上方文本框Text1中写入普通手机号码,点击转换按钮Command1,将普通手机号码转为加横线的手机号码写入Text2文本框中。相反,在下方文本框Text2中写入加横线的手机号码,点击反转按钮Command2,将加横线的手机号码转为普通手机号码写入Text1文本框中。
展开
展开全部
1.用VB编程序设计一个简易的计算器
代码:
Dim num_1, num2, flagPrivate Sub Command1_Click(Index As Integer) Select Case Index Case 0 To 9 Label1.Caption = Label1.Caption + CStr(Command1(Index).Caption) Case 10 Label1.Caption = Label1.Caption + "." Case 11 To 14 num_1 = Val(Label1.Caption) Label1.Caption = "" flag = Index Case 15 num_2 = Val(Label1.Caption) Label1.Caption = "" If Command1(flag).Caption = "+" Then Label1.Caption = num_1 + num_2 ElseIf Command1(flag).Caption = "-" Then Label1.Caption = num_1 - num_2 ElseIf Command1(flag).Caption = "*" Then Label1.Caption = num_1 * num_2 Else Label1.Caption = num_1 / num_2 End If Case 16 num_1 = 0 num_2 = 0 Label1.Caption = "" End SelectEnd Sub Private Sub Form_Load() Me.AutoRedraw = True For i = 0 To 9 Command1(i).Caption = i Next iEnd Sub窗体界面设置:
在窗体上建立控件数组Command1(0),Command1(1),Command1(2),……,Command1(16),其Captint属性分别设置为0,1,2,3,4,5,6,7,8,9,.,+,-,*,/,=,C
2.用VB编程序实现十进制与二进制之间的相互转化
代码:
Private Sub Command1_Click() Text3.Text = "" Text4.Text = "0." n = Val(Text1.Text) Do While n > 0 Text3.Text = CStr(n Mod 2) + Text3.Text n = n \ 2 Loop n = Val(Text2.Text) Do While n > 0 Text4.Text = Text4.Text + CStr(Fix(2 * n)) n = 2 * n - Fix(2 * n) LoopEnd Sub Private Sub Command2_Click() Dim s1, s2 Text1.Text = "" Text2.Text = "" For i = 1 To Len(Text3.Text) s1 = s1 + Val(Mid(Text3.Text, i, 1)) * 2 ^ (Len(Text3.Text) - i) Next i Text1.Text = s1 For i = 3 To Len(Text4.Text) s2 = s2 + Val(Mid(Text4.Text, i, 1)) * 2 ^ (-(i - 2)) Next i Text2.Text = "0" + CStr(s2)End Sub Private Sub Command3_Click() Text1.Text = "" Text2.Text = "" Text3.Text = "" Text4.Text = ""End Sub Private Sub Form_Load() Me.AutoRedraw = TrueEnd Sub Private Sub Text1_KeyPress(KeyAscii As Integer) If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then KeyAscii = 0 Beep End IfEnd Sub Private Sub Text2_KeyPress(KeyAscii As Integer) If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> 46 Then KeyAscii = 0 Beep End IfEnd Sub Private Sub Text3_KeyPress(KeyAscii As Integer) If (KeyAscii < 48 Or KeyAscii > 49) And KeyAscii <> 8 Then KeyAscii = 0 Beep End IfEnd Sub Private Sub Text4_KeyPress(KeyAscii As Integer) If (KeyAscii < 48 Or KeyAscii > 49) And KeyAscii <> 8 And KeyAscii <> 46 Then KeyAscii = 0 Beep End IfEnd Sub运行界面:
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询