Private Sub Form_Activate() Open App.Path & "\in.txt" For Input As #1 Input #1, x If x < 40 Then ans = x * 2.2 + 30 If x >= 40 And x <= 100 Then ans = x * 3 + 30 If x > 100 Then ans = x * 3.5 + 30 Close #1 Open App.Path & "\out.txt" For Output As #2 Print #2, ans Close #2 End Sub
Private Sub Form_Activate() Dim xx(9) As Integer Open App.Path & "\in.txt" For Input As #1 Input #1, x Close #1 Select Case x Case Is < 40 coco = x * 2.2 + 30 Case 40 To 100 coco = x * 3 + 30 Case Is > 100 coco = x * 3.5 + 30 End Select Open App.Path & "/out.txt" For Output As #1 Print #1, coco Close #1 End Sub
Private Sub Form_Activate() Open App.Path & "\in.txt" For Input As #1 Input #1, x Select Case x Case Is < 40 m = x * 2.2 + 30 Case 40 To 100 m = x * 3 + 30 Case Is >= 100 m = x * 3.5 + 30 End Select Close #1
Open App.Path & "\out.txt" For Output As #2 Print #2, m Close #2
Dim num(9) As Integer Public Sub Form_Load() Me.Hide Open App.Path & "/in.txt" For Input As #1 Open App.Path & "/out.txt" For Output As #2 Input #1, x ans = 30 Select Case x Case Is < 40 ans = ans + x * 2.2 Case 40 To 100 ans = ans + x * 3 Case Is > 100 ans = ans + x * 3.5 End Select Print #2, ans Close #2 Close #1 End End Sub
Private Sub Form_Activate()
回覆刪除Open App.Path & "\in.txt" For Input As #1
Input #1, x
If x < 40 Then ans = x * 2.2 + 30
If x >= 40 And x <= 100 Then ans = x * 3 + 30
If x > 100 Then ans = x * 3.5 + 30
Close #1
Open App.Path & "\out.txt" For Output As #2
Print #2, ans
Close #2
End Sub
高仔,
回覆刪除這題這樣寫可以,三個if的地方,也可以改寫成
select case x
case is < 40
case 40 to 100
case is > 100
end select
熊掌
Private Sub Form_Activate()
回覆刪除Dim xx(9) As Integer
Open App.Path & "\in.txt" For Input As #1
Input #1, x
Close #1
Select Case x
Case Is < 40
coco = x * 2.2 + 30
Case 40 To 100
coco = x * 3 + 30
Case Is > 100
coco = x * 3.5 + 30
End Select
Open App.Path & "/out.txt" For Output As #1
Print #1, coco
Close #1
End Sub
Private Sub Form_Activate()
回覆刪除Open App.Path & "\in.txt" For Input As #1
Input #1, x
Select Case x
Case Is < 40
ans = 30 + x * 2.2
Case 40 To 100
ans = 30 + x * 3
Case Is > 100
ans = 30 + x * 3.5
End Select
Close #1
Open App.Path & "\out.txt" For Output As #1
Print #1, ans
Close #1
End Sub
沒有學過 App.Path啦。。
自己研究了一下。稍微懂了。
Y揚,皓好,
回覆刪除你們的程式都OK,app.path一回生兩回熟,就是個套路而已。
可以養成固定習慣開成#1,#2兩個不同的檔案編號,一個當成寫出到檔案的,一個當成從檔案讀入到程式的。
都用成一個號碼,關完再開另一個也不會錯啦。
加油,滴水穿石,聚沙成塔。
app.path的意思是程式所在位置的資料夾?
回覆刪除簡單來說的話 是這樣沒錯吧0.0?
Private Sub Form_Activate()
Open App.Path & "\in.txt" For Input As #1
Input #1, x
Select Case x
Case Is < 40
m = x * 2.2 + 30
Case 40 To 100
m = x * 3 + 30
Case Is >= 100
m = x * 3.5 + 30
End Select
Close #1
Open App.Path & "\out.txt" For Output As #2
Print #2, m
Close #2
End Sub
松鼠好,
回覆刪除oK的。
Private Sub Form_Load()
回覆刪除Open App.Path & "\in.txt" For Input As #1
Input #1, x
Close #1
Open App.Path & "\out.txt" For Output As #2
If x <= 40 Then
ans = 30 + x * 2.2
ElseIf x <= 100 Then
ans = 30 + x * 3
Else
ans = 30 + x * 3.5
End If
Print #2, ans
Close #2
End Sub
阿瑋好,
回覆刪除OK。一天一天向前吧。加油。
Private Sub Form_Activate()
回覆刪除Open App.Path & "\in.txt" For Input As #1
Input #1, x
Close #1
Select Case x
Case Is < 40
ans = 30 + x * 2.2
Case 40 To 100
ans = 30 + x * 3
Case Is > 100
ans = 30 + x * 3.5
End Select
Open App.Path & "\out.txt" For Output As #2
Print #2, ans
Close #2
End Sub
Gavin 好,
回覆刪除歡迎加入,慢慢習慣吧。
回頭又一次看這題,似乎簡單的過頭了,
不過,沒關係,還是上面那句話,累積吧。
你的程式是對的。
Dim num(9) As Integer
回覆刪除Public Sub Form_Load()
Me.Hide
Open App.Path & "/in.txt" For Input As #1
Open App.Path & "/out.txt" For Output As #2
Input #1, x
ans = 30
Select Case x
Case Is < 40
ans = ans + x * 2.2
Case 40 To 100
ans = ans + x * 3
Case Is > 100
ans = ans + x * 3.5
End Select
Print #2, ans
Close #2
Close #1
End
End Sub
2分18秒
Private Sub Form_Load()
回覆刪除Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, x
If x < 40 Then y = 30 + x * 2.2
If (40 <= x) And (x <= 100) Then y = x * 3 + 30
If x > 100 Then x = 30 + y * 3.5
Print #2, y
Close
Close
'電費算法為:電錶每月租金30元,用電在40度之內,每度2.2元,40度至100度,每度3元,超過100度,每度3.5元。
End
End Sub