4个text,输入四个数字;一个command “计算”;一个label label1。 Private Sub command1_click() label1.caption=val(text1.text)+val(text2.text)+val(text3.text)+val(text4.text) end sub
Dim s As Integer s = CInt(Text1.Text) + CInt(Text2.Text) + CInt(Text3.Text) + CInt(Text4.Text) MsgBox s
如果不是数字的话, val("abdc") 返回的是0 如果要判断是否是数字 用isnumeric if(isnumeric(text1.text ) and (isnumeric(text2.text ) and (isnumeric(text3.text ) and (isnumeric(text4.text ) then debug.print val(text1.text)+val(text2.text)+val(text3.text)+val(text4.text)end if
Dim a As Integer a = Val(Text1.Text) + Val(Text2.Text) + Val(Text3.Text) + Val(Text4.Text) msgbox a
你也可以 dim a(4) as integer a(1)=text1.text a(2)=text2.text a(3)=text3.text a(4)=text4.text msgbox ("四个数的和是:"& a(1)+a(2)+a(3)+a(4)))
Private Sub command1_click()
label1.caption=val(text1.text)+val(text2.text)+val(text3.text)+val(text4.text)
end sub
s = CInt(Text1.Text) + CInt(Text2.Text) + CInt(Text3.Text) + CInt(Text4.Text)
MsgBox s
val("abdc") 返回的是0
如果要判断是否是数字 用isnumeric
if(isnumeric(text1.text ) and (isnumeric(text2.text ) and (isnumeric(text3.text ) and (isnumeric(text4.text ) then
debug.print val(text1.text)+val(text2.text)+val(text3.text)+val(text4.text)end if
a = Val(Text1.Text) + Val(Text2.Text) + Val(Text3.Text) + Val(Text4.Text)
msgbox a
dim a(4) as integer
a(1)=text1.text
a(2)=text2.text
a(3)=text3.text
a(4)=text4.text
msgbox ("四个数的和是:"& a(1)+a(2)+a(3)+a(4)))