找出最小數字:從指定目錄中的"in.txt",讀入一數字字串,以逗號分隔,找出字串中最小字數。
輸出到指定目錄的"out.txt"。
(讀取指定目錄的in.txt, 請用 open app.path & "\in.txt" for input as #1 )
※今後皆以指定目錄形式完成VB
輸入範例:
26,56,78,99,15,13
輸出範例:
13
(讀取指定目錄的in.txt, 請用 open app.path & "\in.txt" for input as #1 )
※今後皆以指定目錄形式完成VB
輸入範例:
26,56,78,99,15,13
輸出範例:
13
Dim str As String
回覆刪除Dim k As Long
Private Sub Form_Load()
Open App.Path & "\in.txt" For Input As #1
Line Input #1, str
Close #1
num = Split(str, ",")
k = 99999
For i = 0 To UBound(num)
If num(i) < k Then k = num(i)
Next
Open App.Path & "\out.txt" For Output As #1
Print #1, k
Close #1
End Sub
Bob好
回覆刪除程式錯誤,用long很好,但如果輸入範例比K大呢?
想想看吧:)
Dim str As String
回覆刪除Dim k As Long
Private Sub Form_Load()
Open App.Path & "\in.txt" For Input As #1
Line Input #1, str
Close #1
num = Split(str, ",")
k = num(0)
For i = 1 To UBound(num)
If num(i) < k Then k = num(i)
Next
Open App.Path & "\out.txt" For Output As #1
Print #1, k
Close #1
End Sub
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, Min
Do Until EOF(1)
Input #1, x
If Min > x Then Min = x
Loop
Print #2, Min
Close
Close
End
End Sub
Private Sub Form_Load()
回覆刪除Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Dim num(5) As Integer
For j = 0 To 5
Input #1, n
num(j) = n
Next
For k = 0 To UBound(num)
For h = 0 To UBound(num) - 1
If Val(num(h)) > Val(num(h + 1)) Then
x = num(h)
num(h) = num(h + 1)
num(h + 1) = x
End If
Next
Next
Print #2, num(0)
Close
Close
End
End Sub