再请假一下VB编程的问题
1.输入三门课的成绩,计算其平均值。2.输入一个思维整数,计算其各位数字之和。3.统计字符个数。在文本框中任意输入一串字符,统计字符个数。4.设计一个计算器,实现加减乘数...
1.输入三门课的成绩,计算其平均值。
2.输入一个思维整数,计算其各位数字之和。
3.统计字符个数。在文本框中任意输入一串字符,统计字符个数。
4.设计一个计算器,实现加减乘数四则运算。
麻烦您了,就是像您指教大小写一样的格式,不要只说用什么函数哈。。。。
不好意思啊,最高好像只能给100财富
第一个已解决,不用麻烦发回答了 展开
2.输入一个思维整数,计算其各位数字之和。
3.统计字符个数。在文本框中任意输入一串字符,统计字符个数。
4.设计一个计算器,实现加减乘数四则运算。
麻烦您了,就是像您指教大小写一样的格式,不要只说用什么函数哈。。。。
不好意思啊,最高好像只能给100财富
第一个已解决,不用麻烦发回答了 展开
2个回答
展开全部
第二题看不明白,3,窗体放一个text控件,一个按钮控件,按钮事件输入msgbox len(text1.text)
4
'这个很简单的了,你用记事本把这段代码复制过去,然后另存为.frm就可以了
'然后用vb打开。看看效果。
'以下保存为 任务名称.frm
VERSION 5.00
Begin VB.Form Form1
Caption = "计算机"
ClientHeight = 4230
ClientLeft = 60
ClientTop = 750
ClientWidth = 3165
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 4230
ScaleWidth = 3165
StartUpPosition = 2 '屏幕中心
Begin VB.Frame Frame1
Height = 3495
Left = 120
TabIndex = 1
Top = 600
Width = 2895
Begin VB.CommandButton cmdResult
Caption = "="
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 1080
TabIndex = 20
Top = 3000
Width = 1695
End
Begin VB.CommandButton cmdOff
Caption = "OFF"
Height = 375
Left = 1560
TabIndex = 19
Top = 240
Width = 495
End
Begin VB.CommandButton cmdCE
Caption = "CE"
Height = 375
Left = 2280
TabIndex = 18
Top = 240
Width = 495
End
Begin VB.CommandButton cmdchu
Caption = "/"
Height = 375
Left = 2280
TabIndex = 17
Top = 2520
Width = 495
End
Begin VB.CommandButton cmdjia
Caption = "+"
Height = 375
Left = 2280
TabIndex = 16
Top = 720
Width = 495
End
Begin VB.CommandButton cmd0
Caption = "0"
Height = 375
Left = 840
TabIndex = 15
Top = 2520
Width = 495
End
Begin VB.CommandButton cmd6
Caption = "6"
Height = 375
Left = 1560
TabIndex = 14
Top = 1320
Width = 495
End
Begin VB.CommandButton cmd8
Caption = "8"
Height = 375
Left = 840
TabIndex = 13
Top = 720
Width = 495
End
Begin VB.CommandButton cmd4
Caption = "4"
Height = 375
Left = 120
TabIndex = 12
Top = 1320
Width = 495
End
Begin VB.CommandButton cmd9
Caption = "9"
Height = 375
Left = 1560
TabIndex = 11
Top = 720
Width = 495
End
Begin VB.CommandButton cmd2
Caption = "2"
Height = 375
Left = 840
TabIndex = 10
Top = 1920
Width = 495
End
Begin VB.CommandButton cmdjian
Caption = "-"
Height = 375
Left = 2280
TabIndex = 9
Top = 1320
Width = 495
End
Begin VB.CommandButton cmdPoint
Caption = "."
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 1560
TabIndex = 8
Top = 2520
Width = 495
End
Begin VB.CommandButton cmdcheng
Caption = "*"
Height = 375
Left = 2280
TabIndex = 7
Top = 1920
Width = 495
End
Begin VB.CommandButton cmd5
Caption = "5"
Height = 375
Left = 840
TabIndex = 6
Top = 1320
Width = 495
End
Begin VB.CommandButton cmd3
Caption = "3"
Height = 375
Left = 1560
TabIndex = 5
Top = 1905
Width = 495
End
Begin VB.CommandButton cmd1
Caption = "1"
Height = 375
Left = 120
TabIndex = 4
Top = 1920
Width = 495
End
Begin VB.CommandButton cmd7
Caption = "7"
Height = 375
Left = 120
TabIndex = 3
Top = 720
Width = 495
End
Begin VB.CommandButton cmdChange
Caption = "+/-"
Height = 375
Left = 120
TabIndex = 2
Top = 2520
Width = 495
End
End
Begin VB.TextBox txt
Alignment = 1 'Right Justify
Enabled = 0 'False
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 120
Locked = -1 'True
TabIndex = 0
Top = 120
Width = 2895
End
Begin VB.Menu meuFile
Caption = "文件(&F)"
Begin VB.Menu meuExit
Caption = "退出(&X)"
Shortcut = ^X
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim XiaoShu As Boolean
'在窗体变量中声明一个布尔值来判断是否按下了小数点键,防止txt中出现多个小数。如果已经输入了小数点则Xiaoshu为True,否则为False
Dim FuHao As Byte
'声明一个Byte来记录我们按下了什么符号,1为"+",2为"-",3为"*",4为"/"
Dim FirstNumber As Double
'声明一个变量来记录操作数的第一个数,如A+B,那么FirstNumber来记下A的值。
Dim DengHao As Boolean
'声明一个变量来记录是否按下了=号,如果按下了则为True
Private Sub cmd0_Click()
If txt.Text <> "" Then txt.Text = txt.Text + "0" '防止多个0在文本中出现
End Sub
Private Sub cmd1_Click() '按下1时
If Not DengHao Then '没按下等号
txt.Text = txt.Text + "1"
Else
txt.Text = "1" '按下了等号
DengHao = False
End If
End Sub
Private Sub cmd2_Click() '按下2时
If Not DengHao Then '没按下等号
txt.Text = txt.Text + "2"
Else
txt.Text = "2" '按下了等号
DengHao = False
End If
End Sub
Private Sub cmd3_click() '按下3时
If Not DengHao Then '没按下等号
txt.Text = txt.Text + "3"
Else
txt.Text = "3" '按下了等号
DengHao = False
End If
End Sub
Private Sub cmd4_Click() '按下4时
If Not DengHao Then '没按下等号
txt.Text = txt.Text + "4"
Else
txt.Text = "4" '按下了等号
DengHao = False
End If
End Sub
Private Sub cmd5_Click() '按下5时
If Not DengHao Then '没按下等号
txt.Text = txt.Text + "5"
Else
txt.Text = "5" '按下了等号
DengHao = False
End If
End Sub
Private Sub cmd6_Click() '按下6时
If Not DengHao Then '没按下等号
txt.Text = txt.Text + "6"
Else
txt.Text = "6" '按下了等号
DengHao = False
End If
End Sub
Private Sub cmd7_Click() '按下7时
If Not DengHao Then '没按下等号
txt.Text = txt.Text + "7"
Else
txt.Text = "7" '按下了等号
DengHao = False
End If
End Sub
Private Sub cmd8_Click() '按下8时
If Not DengHao Then '没按下等号
txt.Text = txt.Text + "8"
Else
txt.Text = "8" '按下了等号
DengHao = False
End If
End Sub
Private Sub cmd9_Click() '按下9时
If Not DengHao Then '没按下等号
txt.Text = txt.Text + "9"
Else
txt.Text = "9" '按下了等号
DengHao = False
End If
End Sub
Private Sub cmdCE_Click()
txt.Text = ""
XiaoShu = False
End Sub
Private Sub cmdChange_Click()
If (Sgn(Val(txt.Text))) = 1 Then txt.Text = "-" + txt.Text: Exit Sub '用Sgn来判断txt文本框内的值的符号。大于0的话就在前面加上"-"
If (Sgn(Val(txt.Text))) = -1 Then txt.Text = Abs(Val(txt.Text)) 'txt文本框的文本为大于0的数txt前面的"-"去掉。
End Sub
Private Sub cmdcheng_Click()
FirstNumber = Val(txt.Text)
FuHao = 3
txt.Text = ""
XiaoShu = False
End Sub
Private Sub cmdchu_Click()
FirstNumber = Val(txt.Text)
FuHao = 4
txt.Text = ""
XiaoShu = False
End Sub
Private Sub cmdjia_Click()
FirstNumber = Val(txt.Text)
FuHao = 1
txt.Text = ""
XiaoShu = False
End Sub
Private Sub cmdjian_Click()
FirstNumber = Val(txt.Text)
FuHao = 2
txt.Text = ""
XiaoShu = False
End Sub
Private Sub cmdOff_Click()
End
End Sub
Private Sub cmdPoint_Click()
If txt.Text = "" Then txt.Text = "0"
If Not XiaoShu Then '当我们以前没有按下小数点键时在txt中加上小数点
txt.Text = txt.Text + "."
XiaoShu = True
End If
End Sub
Private Sub cmdResult_Click()
If FuHao = 1 Then '按下了+号
txt.Text = FirstNumber + Val(txt.Text)
End If
If FuHao = 2 Then '按下了-号
txt.Text = FirstNumber - Val(txt.Text)
End If
If FuHao = 3 Then '按下了*号
txt.Text = FirstNumber * Val(txt.Text)
End If
If FuHao = 4 Then '按下了、号
txt.Text = FirstNumber / Val(txt.Text)
End If
DengHao = True '记录下按了=号
XiaoShu = False
End Sub
Private Sub meuExit_Click()
End
End Sub
4
'这个很简单的了,你用记事本把这段代码复制过去,然后另存为.frm就可以了
'然后用vb打开。看看效果。
'以下保存为 任务名称.frm
VERSION 5.00
Begin VB.Form Form1
Caption = "计算机"
ClientHeight = 4230
ClientLeft = 60
ClientTop = 750
ClientWidth = 3165
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 4230
ScaleWidth = 3165
StartUpPosition = 2 '屏幕中心
Begin VB.Frame Frame1
Height = 3495
Left = 120
TabIndex = 1
Top = 600
Width = 2895
Begin VB.CommandButton cmdResult
Caption = "="
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 1080
TabIndex = 20
Top = 3000
Width = 1695
End
Begin VB.CommandButton cmdOff
Caption = "OFF"
Height = 375
Left = 1560
TabIndex = 19
Top = 240
Width = 495
End
Begin VB.CommandButton cmdCE
Caption = "CE"
Height = 375
Left = 2280
TabIndex = 18
Top = 240
Width = 495
End
Begin VB.CommandButton cmdchu
Caption = "/"
Height = 375
Left = 2280
TabIndex = 17
Top = 2520
Width = 495
End
Begin VB.CommandButton cmdjia
Caption = "+"
Height = 375
Left = 2280
TabIndex = 16
Top = 720
Width = 495
End
Begin VB.CommandButton cmd0
Caption = "0"
Height = 375
Left = 840
TabIndex = 15
Top = 2520
Width = 495
End
Begin VB.CommandButton cmd6
Caption = "6"
Height = 375
Left = 1560
TabIndex = 14
Top = 1320
Width = 495
End
Begin VB.CommandButton cmd8
Caption = "8"
Height = 375
Left = 840
TabIndex = 13
Top = 720
Width = 495
End
Begin VB.CommandButton cmd4
Caption = "4"
Height = 375
Left = 120
TabIndex = 12
Top = 1320
Width = 495
End
Begin VB.CommandButton cmd9
Caption = "9"
Height = 375
Left = 1560
TabIndex = 11
Top = 720
Width = 495
End
Begin VB.CommandButton cmd2
Caption = "2"
Height = 375
Left = 840
TabIndex = 10
Top = 1920
Width = 495
End
Begin VB.CommandButton cmdjian
Caption = "-"
Height = 375
Left = 2280
TabIndex = 9
Top = 1320
Width = 495
End
Begin VB.CommandButton cmdPoint
Caption = "."
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 1560
TabIndex = 8
Top = 2520
Width = 495
End
Begin VB.CommandButton cmdcheng
Caption = "*"
Height = 375
Left = 2280
TabIndex = 7
Top = 1920
Width = 495
End
Begin VB.CommandButton cmd5
Caption = "5"
Height = 375
Left = 840
TabIndex = 6
Top = 1320
Width = 495
End
Begin VB.CommandButton cmd3
Caption = "3"
Height = 375
Left = 1560
TabIndex = 5
Top = 1905
Width = 495
End
Begin VB.CommandButton cmd1
Caption = "1"
Height = 375
Left = 120
TabIndex = 4
Top = 1920
Width = 495
End
Begin VB.CommandButton cmd7
Caption = "7"
Height = 375
Left = 120
TabIndex = 3
Top = 720
Width = 495
End
Begin VB.CommandButton cmdChange
Caption = "+/-"
Height = 375
Left = 120
TabIndex = 2
Top = 2520
Width = 495
End
End
Begin VB.TextBox txt
Alignment = 1 'Right Justify
Enabled = 0 'False
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 120
Locked = -1 'True
TabIndex = 0
Top = 120
Width = 2895
End
Begin VB.Menu meuFile
Caption = "文件(&F)"
Begin VB.Menu meuExit
Caption = "退出(&X)"
Shortcut = ^X
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim XiaoShu As Boolean
'在窗体变量中声明一个布尔值来判断是否按下了小数点键,防止txt中出现多个小数。如果已经输入了小数点则Xiaoshu为True,否则为False
Dim FuHao As Byte
'声明一个Byte来记录我们按下了什么符号,1为"+",2为"-",3为"*",4为"/"
Dim FirstNumber As Double
'声明一个变量来记录操作数的第一个数,如A+B,那么FirstNumber来记下A的值。
Dim DengHao As Boolean
'声明一个变量来记录是否按下了=号,如果按下了则为True
Private Sub cmd0_Click()
If txt.Text <> "" Then txt.Text = txt.Text + "0" '防止多个0在文本中出现
End Sub
Private Sub cmd1_Click() '按下1时
If Not DengHao Then '没按下等号
txt.Text = txt.Text + "1"
Else
txt.Text = "1" '按下了等号
DengHao = False
End If
End Sub
Private Sub cmd2_Click() '按下2时
If Not DengHao Then '没按下等号
txt.Text = txt.Text + "2"
Else
txt.Text = "2" '按下了等号
DengHao = False
End If
End Sub
Private Sub cmd3_click() '按下3时
If Not DengHao Then '没按下等号
txt.Text = txt.Text + "3"
Else
txt.Text = "3" '按下了等号
DengHao = False
End If
End Sub
Private Sub cmd4_Click() '按下4时
If Not DengHao Then '没按下等号
txt.Text = txt.Text + "4"
Else
txt.Text = "4" '按下了等号
DengHao = False
End If
End Sub
Private Sub cmd5_Click() '按下5时
If Not DengHao Then '没按下等号
txt.Text = txt.Text + "5"
Else
txt.Text = "5" '按下了等号
DengHao = False
End If
End Sub
Private Sub cmd6_Click() '按下6时
If Not DengHao Then '没按下等号
txt.Text = txt.Text + "6"
Else
txt.Text = "6" '按下了等号
DengHao = False
End If
End Sub
Private Sub cmd7_Click() '按下7时
If Not DengHao Then '没按下等号
txt.Text = txt.Text + "7"
Else
txt.Text = "7" '按下了等号
DengHao = False
End If
End Sub
Private Sub cmd8_Click() '按下8时
If Not DengHao Then '没按下等号
txt.Text = txt.Text + "8"
Else
txt.Text = "8" '按下了等号
DengHao = False
End If
End Sub
Private Sub cmd9_Click() '按下9时
If Not DengHao Then '没按下等号
txt.Text = txt.Text + "9"
Else
txt.Text = "9" '按下了等号
DengHao = False
End If
End Sub
Private Sub cmdCE_Click()
txt.Text = ""
XiaoShu = False
End Sub
Private Sub cmdChange_Click()
If (Sgn(Val(txt.Text))) = 1 Then txt.Text = "-" + txt.Text: Exit Sub '用Sgn来判断txt文本框内的值的符号。大于0的话就在前面加上"-"
If (Sgn(Val(txt.Text))) = -1 Then txt.Text = Abs(Val(txt.Text)) 'txt文本框的文本为大于0的数txt前面的"-"去掉。
End Sub
Private Sub cmdcheng_Click()
FirstNumber = Val(txt.Text)
FuHao = 3
txt.Text = ""
XiaoShu = False
End Sub
Private Sub cmdchu_Click()
FirstNumber = Val(txt.Text)
FuHao = 4
txt.Text = ""
XiaoShu = False
End Sub
Private Sub cmdjia_Click()
FirstNumber = Val(txt.Text)
FuHao = 1
txt.Text = ""
XiaoShu = False
End Sub
Private Sub cmdjian_Click()
FirstNumber = Val(txt.Text)
FuHao = 2
txt.Text = ""
XiaoShu = False
End Sub
Private Sub cmdOff_Click()
End
End Sub
Private Sub cmdPoint_Click()
If txt.Text = "" Then txt.Text = "0"
If Not XiaoShu Then '当我们以前没有按下小数点键时在txt中加上小数点
txt.Text = txt.Text + "."
XiaoShu = True
End If
End Sub
Private Sub cmdResult_Click()
If FuHao = 1 Then '按下了+号
txt.Text = FirstNumber + Val(txt.Text)
End If
If FuHao = 2 Then '按下了-号
txt.Text = FirstNumber - Val(txt.Text)
End If
If FuHao = 3 Then '按下了*号
txt.Text = FirstNumber * Val(txt.Text)
End If
If FuHao = 4 Then '按下了、号
txt.Text = FirstNumber / Val(txt.Text)
End If
DengHao = True '记录下按了=号
XiaoShu = False
End Sub
Private Sub meuExit_Click()
End
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询