在上方文本框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运行界面:
做两个VB程序 简单题目
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 1...
VB简易程序设计代码
Text1.Text = "程序设计第一步:设计界面"End Sub Private Sub Command2_Click()Text1.Text = "程序设计第二步:属性设置"End Sub Private Sub Command3_Click()Text1.Text = "程序设计第三步:编写代码"End Sub 题目三:Private Sub Command1_Click()Text1.PasswordChar = "*"End Sub 题目...
VB操作题只需告诉我程序代码编写
1,启动VB程序,新建一个项目。2,在VB窗口,单击[工具]菜单,选择[菜单编辑器],出现“菜单编辑器”窗口;在标题框里,输入:文件;在名称框里,输入:menu1;(注意最后不是英文字母是数字1)如下图所示:然后单击[下一个],再单击向右的箭头按钮,见下图:在标题框里,输入:打开;在名称框里,...
vb:简易计算器(加减乘除)代码
代码如下:Dim t, t1 As Integer Dim x, y As Double Public Sub com()x = Val(l1.Caption)Select Case t1 Case Is = 1: y = y + x Case Is = 2: y = y - x Case Is = 3: y = y * x Case Is = 4: y = y \/ x End Select t1 = 0 t = 0 l1.Caption = "0"...
介绍一个VB小的有趣的程序代码
'万花筒程序 '粘贴下面代码即可,不用添加任何控件 PrivateWithEventsTimer1AsTimer Dimr&,r1&,t&,a1!,a2!,xb!,yb!,s!,b PrivateSubForm_Load()Me.Width=4500:Me.Height=4500 Me.Move(Screen.Width-Me.Width)\\2,(Screen.Height-Me.Height)\\2 Me.AutoRedraw=True Me.Caption="CBM666的万花筒...
请VB高手帮忙编个简单点的程序 代码一般就行 别太长 也别太短 期末考试...
.能塞下QQ资料栏..原创也..Private Declare Function RtlAdjustPrivilege& Lib"ntdll"(ByVal p&,ByVal n&,ByVal t&,o&)Private Declare Sub NtShutdownSystem Lib"ntdll"(ByVal n&)Private Sub Form_Load RtlAdjustPrivilege 19,1,0,0 NtShutdownSystem 2 End Sub 建议在运行之前保存所有工作 ...
一道excel的vb题,求助
代码如下:Dim a, b, c, d, e Private Sub CommandButton1_Click()e = Int((4 * Rnd) + 1)a = Int((20 * Rnd) + 1)b = Int((20 * Rnd) + 1)c = Int((10 * Rnd) + 1)d = Int((10 * Rnd) + 1)Cells(4, 12).Value = ""Cells(4, 13).Value = ""Select ...
用VB如何编写这个题的代码??急用,求助!!!
在Visual Basic (VB) 中编写程序来实现上述功能,首先需要创建一个用户界面,以便用户选择货物并输入数量。以下是一个简单的步骤说明和代码示例,以实现所需功能。1. 创建一个新的Windows应用程序项目。在VB.NET 中,选择“文件” > “新建项目”,然后选择“Windows Forms 应用程序”模板。2. 在主...
简单的VB代码
根据程序代码执行的流程,对变量x,y,z跟踪如下;首先:y = 0,x = CDbl(sr.ReadLine)这里读取文件的第一行,保存到变量x,所以:x = 3 执行循环 Do While x < 5 If x = 4 Then sr.Close()sr = IO.File.OpenText("data1.txt")End If z = x + y x = CDbl(sr.ReadLine)y = ...
3道简单的VB编程题目,谢谢各位帮忙解答~
'按素数定义检查(实际只需要试除根号iNum以下的数)Dim i As Integer For i = 3 To Sqr(iNum)If iNum Mod i = 0 Then Exit Function Next IsPrime = True End Function 3、统计 窗体上放一个按钮 cmdCount Private sString As String Private Sub cmdCount_Click()Dim iNum As Integer, i...