第4題解題程式
FOR迴圈版
Private Sub cmd_no4_Click()
'**************************
'*119-940304 Program Start*
'**************************
Open "C:\940304.SM" For Input As #1 '開啟檔案
Dim BMI, BMImin As Integer 'BMI體脂數,BMImin最小體脂數
BMImin = 999
For i = 1 To 3 '讀入三筆資料
Input #1, a, b
a = a / 100 '轉成公尺
BMI = b / (a * a) '計算BMI
If BMI < BMImin Then BMImin = BMI '取出最小值
Next i
Close #1 '關檔
If BMImin >= 20 And BMImin <= 25 Then '顯示BMI是否正常,20-25
S = "最小BMI值=" & BMImin & ",正常"
Else
S = "最小BMI值=" & BMImin & ",不正常"
End If
Txt_no4.Text = "第四題結果:" & S
End Sub
DO WHILE迴圈前測版
Private Sub cmd_no4_Click()
'**************************
'*119-940304 Program Start*
'**************************
Open "A:\940304.SM" For Input As #1
Dim BMI, BMIS As Integer
BMIS = 999
i = 1
Do While i <= 3
Input #1, a, b
a = a / 100
BMI = b / (a * a)
If BMI < BMIS Then BMIS = BMI
i = i + 1
Loop
If BMIS >= 20 And BMIS <= 25 Then
S = "最小BMI值=" & BMIS & ",正常"
Else
S = "最小BMI值=" & BMIS & ",不正常"
End If
Close #1
Txt_no4.Text = "第四題結果:" & S
End Sub
DO WHILE 迴圈後測版
Private Sub Cmd_no4_Click()
'**************************
'*119-940304 Program Start*
'**************************
Open "A:\940304.SM" For Input As #1
Dim BMI, BMIS As Integer
BMIS = 999
i = 1
Do
Input #1, a, b
a = a / 100
BMI = b / (a * a)
If BMI < BMIS Then BMIS = BMI
i = i + 1
Loop While i <= 3
If BMIS >= 20 And BMIS <= 25 Then
S = "最小BMI值=" & BMIS & ",正常"
Else
S = "最小BMI值=" & BMIS & ",不正常"
End If
Close #1
txt_no4.Text = "第四題結果:" & S
End Sub
執行畫面