Private Sub Command2_Click() a = Val(Text1.Text) b = Val(Text3.Text) Select Case Text2.Text Case "+" c = a + b: Text5.Text = Str$(c) Case "-" c = a - b: Text5.Text = Str$(c) Case "*" c = a * b: Text5.Text = Str$(c) Case "/" c = a / b: Text5.Text = Str$(c) Case Else Print "運算符錯!": Text5.Text = "" End Select End Sub 我很想知道VB中Str$(c)代表的是什么意思.還有,運算符錯為什么不能顯示在text5內啊?希望高手教教我..初學,很多東西不懂.
3 回答

SMILET
TA貢獻1796條經驗 獲得超4個贊
在Visual Basic 6.0 中,某些函數有兩個版本,一個返回 String 值,一個返回 Variant 值。這些函數對通過美元符號 ($) 后綴來與 String 版本區分開來。

白衣非少年
TA貢獻1155條經驗 獲得超0個贊
text5.text=Str$(c)指定把數字c轉換為字符串并賦給text5.text
要顯示在text5內可以用以下這個程序:
Private Sub Command2_Click()
a = Val(Text1.Text)
b = Val(Text3.Text)
Select Case Text2.Text
Case "+"
c = a + b: Text5.Text = Str$(c)
Case "-"
c = a - b: Text5.Text = Str$(c)
Case "*"
c = a * b: Text5.Text = Str$(c)
Case "/"
c = a / b: Text5.Text = c
Case Else
Text5.Text = "運算符錯!"
End Select
End Sub

慕桂英546537
TA貢獻1848條經驗 獲得超10個贊
問題一:
Str$(c)
意思是,將變量c的值轉換成字符串;
問題二:
Case Else
Print "運算符錯!": Text5.Text = ""
規定了,如果運算符錯誤時,在窗體上顯示“運算符錯!”,并且令text5內容為空。
添加回答
舉報
0/150
提交
取消