笨鳥慢飛-寫寫VB吧

偷偷放點暑假,不可以無所事事
學點東西最好得方法就是動手做做

針對上一篇夏天-濕度與不快指數寫了計算機
就當作練習,程式碼如下 
 discomfort index
---------------------------------------------------------------
Private Sub Command1_Click()
If Text1.Text = "" Then
MsgBox "請輸入攝氏氣溫", 16, "氣溫"
Exit Sub
End If

If Text2.Text = "" Then
MsgBox "請輸入濕度", 16, "濕度"
Exit Sub
End If

A = Text1.Text
B = Text2.Text
Text3.Text = 0.81 * A + 0.01 * B * (0.99 * A - 14.3) + 46.3
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii >= 48 And KeyAscii <= 57 Then Exit Sub
If KeyAscii = 46 Then Exit Sub
If KeyAscii = 8 Then Exit Sub
KeyAscii = 0
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii >= 48 And KeyAscii <= 57 Then Exit Sub
If KeyAscii = 46 Then Exit Sub
If KeyAscii = 8 Then Exit Sub
KeyAscii = 0
End Sub
---------------------------------------------------------------3小段每一段都以Private Sub開頭、End Sub結尾
Command1_Click()指按下"開始計算"按鈕
Text1_KeyPress(KeyAscii As Integer)是指鍵盤的輸入動作,在此為防止數字以外的數值被輸入
MsgBox "請輸入濕度", 16, "濕度" 表示跳出訊息視窗並顯示"請輸入濕度",16表示紅色叉叉圖案,最後面"濕度"是此訊號視窗的顯示標題

下載簡易計算-不快指數

留言

這個網誌中的熱門文章

用EXCEL計算student's t test之p value

Excel error bar(誤差線)(office2007)

圓周率(π) 世界紀錄