Dim strr As String Dim ans As Integer Private Sub Form_Load() Me.Hide Open App.Path & "\test2.txt" For Input As #1 Open App.Path & "\result2.txt" For Output As #2 Input #1, strr Do ans = 0 Line Input #1, strr For i = 1 To Len(strr) If Val(Mid(strr, i, 1)) <> 0 Then ans = ans + 1 Next Print #2, ans Loop Until EOF(1) Close #2 Close #1 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 Input #1, x For i = 1 To x Input #1, n y = 0 For k = 1 To Len(n) If Val(Mid(n, k, 1)) <> 0 Then y = y + 1 Next Print #2, y Next End Close Close End Sub
Dim num As Integer 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, n For j = 1 To n Line Input #1, w lon = Len(w) For i = 1 To lon X = Asc(Mid(w, i, 1)) If X > 47 And X < 58 Then num = num + 1 Next Print #2, num num = 0 Next Close #2 Close #1 End End Sub
Dim strr As String
回覆刪除Dim ans As Integer
Private Sub Form_Load()
Me.Hide
Open App.Path & "\test2.txt" For Input As #1
Open App.Path & "\result2.txt" For Output As #2
Input #1, strr
Do
ans = 0
Line Input #1, strr
For i = 1 To Len(strr)
If Val(Mid(strr, i, 1)) <> 0 Then ans = ans + 1
Next
Print #2, ans
Loop Until EOF(1)
Close #2
Close #1
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
Input #1, x
For i = 1 To x
Input #1, n
y = 0
For k = 1 To Len(n)
If Val(Mid(n, k, 1)) <> 0 Then y = y + 1
Next
Print #2, y
Next
End
Close
Close
End Sub
題目輸入沒有0的阿拉伯數字串,那<>0 ANS = ANS + 1 是可行的,但如果題目出現阿拉伯數字0呢?
回覆刪除Dim num As Integer
回覆刪除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, n
For j = 1 To n
Line Input #1, w
lon = Len(w)
For i = 1 To lon
X = Asc(Mid(w, i, 1))
If X > 47 And X < 58 Then num = num + 1
Next
Print #2, num
num = 0
Next
Close #2
Close #1
End
End Sub