如何在VB里实现两个变量相加,
发布网友
发布时间:2024-07-15 20:15
我来回答
共3个回答
热心网友
时间:2024-07-15 21:56
搞清楚过程级变量和模块级变量的声明方法,你用的变量C、V、S都是模块级变量,但你声明为过程级变量,所以不能正确运行。
首先在代码界面的最上面这样:
Option Explicit
Dim c As Single, v As Single, s As Single
然后删除在Private Sub Command1_Click() 过程中的声明:
Dim c As Single, v As Single
就可以了
热心网友
时间:2024-07-15 21:58
Option Explicit
Dim c As Single, v As Single, s As Single
Private Sub Command1_Click()
c = Val(Text1.Text)
v = (c * 0.0127 + 533) * 0.56
Label2.Caption = v
End Sub
Private Sub Command2_Click()
s = Val(Text2.Text)
v = s * 0.56
Label4.Caption = v
End Sub
Private Sub Command3_Click()
c = Label2
s = Label4
v = c + s
Label5.Caption = v
End Sub
Private Sub Form_Load()
Text1 = "": Text2 = ""
End Sub
热心网友
时间:2024-07-15 21:53
v和s变量 必须申明时 在Private外部进行.
即:Dim c As Single, v As Single,s as single '放在最上面几行
Private Sub Command1_Click()
另:c = val(Label2.caption)
s = val(Label4.caption)
v = c + s '因已申明单精度类型,转化类型后 才可相加