用VB来编程一个简易的计算机
Private Sub Command1_Click()
Select Case Text3.Text
Case "+"
Text4.Text = Val(Text1.Text) + Val(Text2.Text)
Case "-"
Text4.Text = Val(Text1.Text) - Val(Text2.Text)
Case "*"
Text4.Text = Val(Text1.Text) * Val(Text2.Text)
Case "/"
Text4.Text = Val(Text1.Text) / Val(Text2.Text)
End Select
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End Sub
Private Sub Text4_Change()
End Sub
:按[vb语言编写一个简易计算器]短语搜索一下,网站有现成例子.动一下手!
后面发了两个文件的内容,你创建两个文本文件按照那两个文件命名后,并把对应代码用记事本打开粘贴到里面,最好再用vb运行project1.vbp文件编译成exe文件或直接执行都可以。给你写了一个代码十分简单的计算器,真正手写代码就这么多。
Dim mem1 As Long, mem2 As Long, mem3 As Long
Dim calc As Integer
Private Sub Command1_Click(Index As Integer)
Text1.Text = Text1.Text & Index
End Sub
Private Sub Command2_Click(Index As Integer)
calc = Index
mem1 = Text1.Text: Text1.Text = ""
End Sub
Private Sub Command3_Click(Index As Integer)
Select Case Index
Case 0
Text1.Text = ""
mem1 = 0: mem2 = 0: mem3 = 0
Case 1
Text1.Text = Text1.Text & "."
Case 2
mem2 = Text1.Text: Text1.Text = ""
Select Case calc
Case 0 '+
mem3 = mem1 + mem2
Case 1 '-
mem3 = mem1 - mem2
Case 2 '*
mem3 = mem1 * mem2
Case 3 '/
mem3 = mem1 / mem2
End Select
Text1.Text = mem3
End Select
End Sub
以下是计算器完整代码文件内容-----------------------------------
因为百度知道不能上传压缩,只好把工程文件的文本代码发给你了。
以下是文件Project1.vbp的内容
Type=Exe
Form=Form1.frm
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINDOWS\system32\STDOLE2.TLB#OLE Automation
Startup="Form1"
Command32=""
Name="Project1"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="BaterStudio"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1
[MS Transaction Server]
AutoRefresh=1
以下是文件Form1.frm里包括按钮信息的文件内容
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 5835
ClientLeft = 60
ClientTop = 345
ClientWidth = 4380
LinkTopic = "Form1"
ScaleHeight = 5835
ScaleWidth = 4380
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command3
Caption = "="
Height = 615
Index = 2
Left = 1920
TabIndex = 17
Top = 4440
Width = 615
End
Begin VB.CommandButton Command3
Caption = "."
Height = 615
Index = 1
Left = 1200
TabIndex = 16
Top = 4440
Width = 615
End
Begin VB.CommandButton Command3
Caption = "C"
Height = 615
Index = 0
Left = 480
TabIndex = 15
Top = 4440
Width = 615
End
Begin VB.CommandButton Command2
Caption = "÷"
Height = 615
Index = 3
Left = 3360
TabIndex = 14
Top = 3120
Width = 615
End
Begin VB.CommandButton Command2
Caption = "×"
Height = 615
Index = 2
Left = 3360
TabIndex = 13
Top = 2400
Width = 615
End
Begin VB.CommandButton Command2
Caption = "-"
Height = 615
Index = 1
Left = 3360
TabIndex = 12
Top = 1680
Width = 615
End
Begin VB.CommandButton Command2
Caption = "+"
Height = 615
Index = 0
Left = 3360
TabIndex = 11
Top = 960
Width = 615
End
Begin VB.CommandButton Command1
Caption = "9"
Height = 615
Index = 9
Left = 1920
TabIndex = 10
Top = 960
Width = 615
End
Begin VB.CommandButton Command1
Caption = "8"
Height = 615
Index = 8
Left = 1200
TabIndex = 9
Top = 960
Width = 615
End
Begin VB.CommandButton Command1
Caption = "7"
Height = 615
Index = 7
Left = 480
TabIndex = 8
Top = 960
Width = 615
End
Begin VB.CommandButton Command1
Caption = "6"
Height = 615
Index = 6
Left = 1920
TabIndex = 7
Top = 1680
Width = 615
End
Begin VB.CommandButton Command1
Caption = "5"
Height = 615
Index = 5
Left = 1200
TabIndex = 6
Top = 1680
Width = 615
End
Begin VB.CommandButton Command1
Caption = "4"
Height = 615
Index = 4
Left = 480
TabIndex = 5
Top = 1680
Width = 615
End
Begin VB.CommandButton Command1
Caption = "3"
Height = 615
Index = 3
Left = 1920
TabIndex = 4
Top = 2400
Width = 615
End
Begin VB.CommandButton Command1
Caption = "2"
Height = 615
Index = 2
Left = 1200
TabIndex = 3
Top = 2400
Width = 615
End
Begin VB.CommandButton Command1
Caption = "1"
Height = 615
Index = 1
Left = 480
TabIndex = 2
Top = 2400
Width = 615
End
Begin VB.CommandButton Command1
Caption = "0"
Height = 615
Index = 0
Left = 480
TabIndex = 1
Top = 3120
Width = 615
End
Begin VB.TextBox Text1
Height = 285
Left = 480
TabIndex = 0
Top = 240
Width = 3495
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim mem1 As Long, mem2 As Long, mem3 As Long
Dim calc As Integer
Private Sub Command1_Click(Index As Integer)
Text1.Text = Text1.Text & Index
End Sub
Private Sub Command2_Click(Index As Integer)
calc = Index
mem1 = Text1.Text: Text1.Text = ""
End Sub
Private Sub Command3_Click(Index As Integer)
Select Case Index
Case 0
Text1.Text = ""
mem1 = 0: mem2 = 0: mem3 = 0
Case 1
Text1.Text = Text1.Text & "."
Case 2
mem2 = Text1.Text: Text1.Text = ""
Select Case calc
Case 0 '+
mem3 = mem1 + mem2
Case 1 '-
mem3 = mem1 - mem2
Case 2 '*
mem3 = mem1 * mem2
Case 3 '/
mem3 = mem1 / mem2
End Select
Text1.Text = mem3
End Select
End Sub
发你QQ邮箱了,看收到没
都是自己做的,分不分的无所谓
这个很简单,初学者都会
你先试着做,碰到具体问题了再来发问。。
VB编程实现:运行时,单击第一个按钮,生成20个(1,50)区间的随机整数,显 ...
Dim a(20) As IntegerPrivate Sub Command1_Click() Randomize For i = 1 To 20 a(i) = Int(Rnd * 50) + 1 Text1 = Text1 & a(i) & " " If i Mod 10 = 0 Then Text1 = Text1 & vbCrLf Next iEnd SubPrivate Sub Command2_Click() For i = 1 To 19 ...
vb中输入任意一个值,出现有此值组成的三角形编程
Dim x1, y1, x2, y2Private Sub Form_MouseDown(Button AsInteger, Shift As Integer, X As Single, Y As Single)If Button <> 1 Then Exit Subx1 = Xy1 = YEnd Sub Private Sub Form_MouseUp(Button As Integer,Shift As Integer, X As Single, Y As Single)If Button = 1 Thenbl...
关于VB的编程问题编,写一个加密程序。。。爆急啊
Private Sub Command1_Click()'用每个字母的Ascii码加7,相加之后的Ascii码值若超过90但不超过97,'则减去10,若超过122,则减去8。Dim a, b As Integer a = Asc(Left(Text1.Text, 1)) + 7 b = Asc(Right(Text1.Text, 1)) + 7 If ((a > 90) And (a < 97)) Then a = a ...
vb编程:随机产生10个1到20之间的整数,放在数组A中,然后将A的元素倒序...
Private Sub Command1_Click()Dim a(10) As Integer Randomize Print "原来的数:"For i = 1 To 10 a(i) = Int(Rnd * 20) + 1 Print a(i);Next i Print Print "交换以后的数:"i = 1: j = 10 Do While i < j t = a(i): a(i) = a(j): a(j) = t i = i + ...
VB:编程计算三角形面积
代码如下:Dim a!, b!, c!, s!, p!a = InputBox("请输入第一条边长")b = InputBox("请输入第二条边长")c = InputBox("请输入第三条边长")If a + b <= c Or b + c <= a Or c + a <= b Then Print "这样的三角形不存在"Else p = (a + b + c) \/ 2 s = ...
VB新手求助:VB简单编程问题,敬请VB高手指点!最好能写出详细程序代码...
Sub Command3_Click()dim k!K=1 IF K>3 THEN A=2*K ELSE A=3 END IF print k print a end 第三题的答案是:如果是求K值的话,此值依旧是1,如果是求A的值的话,A的值是3!我的意思是在消费在100到200的范围内打9折呀,超过200就打8折呀!楼下 的多了一个(end if)了哦 ...
VB编程实现:运行时,单击第一个按钮,生成50个[1,50]之间的随机整数...
Dim a(1 To 50) As Integer Private Sub Command1_Click()Randomize For i = 1 To 50 a(i) = Int(Rnd * 50) + 1 Text1 = Text1 & a(i) & " "If i Mod 10 = 0 Then Text1 = Text1 & vbCrLf Next i Text2 = Max End Sub Private Sub Command2_Click()For i = 1 To...
急求vb6.0编程~~~明天早上就要用啊!大家帮帮忙吧!
在窗体上画个文本框TEXT1,multi属性改为TRUE Private Sub Form_Load()Dim ArrayInt() As Integer Dim CheckNum As Integer Dim PrimeNo As Integer CheckNum = Val(InputBox("输入一个数", "质数判断"))PrimeNo = 1 ReDim Preserve ArrayInt(PrimeNo) As Integer ArrayInt(1) = 2 For j...
编程达人进,求一VB程序代码
首先我想问一下,你会设置控件的属性吗?如果会,将第三段不要;不会也没关系,,你在窗体上画2个按钮,画1个文本框,直接将代码复制过去就可以了。选中文本框,在属性窗口中找到 MultiLine,将它的属性值设为True;将ScrollBars属性设置为2,让文本框能多行显示,并有垂直滚动条。程序运行的结果是...
用VB编程:大家帮帮忙吧。。本人在此谢过啦!!!
22500(150)、44100(210)、44944(?)参考代码:for i = 100 to 316 '100平方10000;316平方99856.车牌号5位 e = i * i 'MsgBox i a = Int (e \/ 10000)b = Int ((e mod 10000) \/ 1000)c = Int ((e mod 100) \/ 10)d = e mod 10 'MsgBox b If a = b And c ...
金龙新帅: 值不能这样加的吧,应该要把它写进cint()的函数里,就是cint(name1.value)+cint(name2.value )
点军区13681651658: 用VB程序设计计算器用VB编程序设计一个简易的计算器.实验要求:1.设计合适的运行界面并编写相应的事件代码.2.要求用标签显示运算数据及运算结果.初始... - ?
金龙新帅:[答案] 帮你写了一个,调试通过,不过第5个条件很奇怪啊,这样做出来的计算器是不能连续运算的,每次都要按下等号给出结果,程序在附录中若满意请及时采纳,谢谢
点军区13681651658: VB编写简易计算机程序实例?
金龙新帅: 简易计算器 http://wenwen.soso.com/z/q29028948.htm?w=VB%D7%F6%BC%C6%CB%E3%C6%F7&spi=1&sr=2&w8=VB%E5%81%9A%E8%AE%A1%E7%AE%97%E5%99%A8&qf=10&rn=99&qs=4
点军区13681651658: 怎样用VB设计简单计算器 - ?
金龙新帅: Dim x As String Private Sub Command1_Click() Text1.Text = Text1.Text & "1" End Sub Private Sub Command10_Click() Text1.Text = Text1.Text & "6" End Sub Private Sub Command11_Click() Text1.Text = Text1.Text & "9" End Sub ...
点军区13681651658: 如何用VB编写最简单的计算器程序 - ?
金龙新帅: 组成包括Label控件2个,其中一个用来显示数字,一个在那个显示数字的上方空白显示,纯属修饰作用 按钮19个,分别为10个数字0~9,小数点,四则运算按钮,正负号按钮,求倒数按钮,等号按钮,清零按钮,C和CE有啥区别我还真不知道..所以就写了C了.
点军区13681651658: 用VB做一个最简单的计算器 - ?
金龙新帅: Dim a As Double, b As Double Dim c As StringPrivate Sub Command10_Click()Text2.Text = Text2.Text & "2" End SubPrivate Sub Command11_Click()Text2.Text = Text2.Text & "3" End SubPrivate Sub Command12_Click()a = Text2....
点军区13681651658: 用VB2010编写一个简单计算器 - ?
金龙新帅: 方法/步骤打开VB新建一个EXE.如图画上4个按钮控件表示加减乘除,再画上3个文本控件表示两个数与和数,再画一个标签控件加入“=”号.当然,界面可以自己发挥.画好之后,就可以把控件进行命名,注意是属性栏的Caption项命名,以便运行的时候方便识别.好的,现在可以进行最重要的代码编写啦.双击对应的按钮控件,进入代码编写界面.Text3.Text = Val(Text1.Text) + Val(Text2.Text),其实代码很简单,就这一句只要更换把'+'分别换成'-''*''/'即可.好了,现在可以点击运行或者F5键运行,即可得到第一个简单的计算器程序.
点军区13681651658: 我想用vb做一个简单的计算器,那位高手可以指点一下 - ?
金龙新帅: Private Sub Command1_Click()这是加法,其他的只需把+改为其他的 Dim a, b, c As Integer a = Val(Text1.Text) b = Val(Text2.Text) c = a + b MsgBox c '弹出答案 End Sub
点军区13681651658: 用VB做一个简单的计算器,该怎么做??
金龙新帅: val(text1.text)+val(text2.text2) '加 val(text1.text)-val(text2.text2) '减 val(text1.text)*val(text2.text2) '乘 val(text1.text)/val(text2.text2) '除
点军区13681651658: 用VB程序设计一个简单计算器 - ?
金龙新帅: 界面:text11 2 3 +4 5 6 -7 8 9 *0 = AC / 代码:dim newnum as boolean dim n1,n2 op as integer private sub ac_click() text1.text="" end sub private sub command1_click(index as integer) if newnum=true then text1="" text1=text1&index ...