老師布置了一道題窗體上設置兩個文本框和兩到三個按鈕,實現華氏和攝氏溫度的轉換。我的解答:Private Sub Command1_Click()If Not IsNumeric(Text1) ThenMsgBox "非法字符"Text1.Text = ""Text1.SetFocusEnd Ifn = Text1.Text * 9 / 5 + 32MsgBox n, vbOKOnlyEnd SubPrivate Sub Command2_Click()If Not IsNumeric(Text2) ThenMsgBox "非法字符"Text2.Text = ""Text2.SetFocusEnd Ifn = (Text2.Text - 32) * 5 / 9MsgBox n, vbOKOnlyEnd SubPrivate Sub Command3_Click()EndEnd Sub我調試沒問題,各位高手覺得呢???

熱心網友

如果字符非法,就不要去計算和顯示了。可以在 tfocus后面寫exit sub或者用else語句。IsNumeric函數里面,Text1或者Text2最好加上。text屬性,雖然。text是默認屬性,但是加上以后給讀程序會帶來方便。Private Sub Command1_Click()If Not IsNumeric(Text1。text) Then MsgBox "非法字符" Text1。Text = "" Text1。SetFocusElse n = Text1。Text * 9 / 5 + 32 MsgBox n, vbOKOnlyEnd IfEnd SubPrivate Sub Command2_Click()If Not IsNumeric(Text2。text) Then MsgBox "非法字符" Text2。Text = "" Text2。SetFocusElse n = (Text2。Text - 32) * 5 / 9 MsgBox n, vbOKOnlyEnd IfEnd SubPrivate Sub Command3_Click()EndEnd Sub。

熱心網友