我寫了以下的程式﹐但是執行時出現compile error. Expected array。請問該如何寫arrar的code呢﹖
Private Sub cmdCreate_Click()
Dim name As String
Dim score As Integer
Open "c:\tempfile.txt" For Output As #1
For i = 1 To 4
name$ = InputBox("Student Name?", "Seq")
score = InputBox("Score?", "Seq")
Write #1, name$(i), score(i)
Next i
Close #1
End Sub
Private Sub cmdCreate_Click()
Dim name As String
Dim score As Integer
Open "c:\tempfile.txt" For Output As #1
For i = 1 To 4
name$ = InputBox("Student Name?", "Seq")
score = InputBox("Score?", "Seq")
Write #1, name$(i), score(i)
Next i
Close #1
End Sub
文章標籤
全站熱搜

Dim name(4) As String Dim score(4) As Integer For i = 1 To 4 name(i) = InputBox("Student Name?", "Seq") score(i) = InputBox("Score?", "Seq") next i Open "c:\tempfile.txt" For Output As #1 for i=1 to 4 Write #1, name(i), score(i) Next i Close #1
謝謝水瓶天賞。 當我執行這程式時﹐出現compile error. Expected As. 怎麼解決呢﹖
name是內定的字,改個名字name_s ps:程式已試過可以了,原來的只是看看就直接改,抱歉
name是內定的字(保留字)...不能夠用
Thanks, and I got part of my program solved. May need your help if I got other problems... ^_^
如果我想要讀取已輸入的資料﹐那我是否用 open “c:\tempfile.txt” for input as #1 (#1) 是否可以重覆使用﹐還是當read時用#2 ﹐append時用#3 ﹖
i can't look your next prouble so you can e-mail to me or go to my http http://home.kimo.com.tw/bill_chen5024/
謝謝﹐我已sent email給你﹐若你看不到中文﹐請通知我﹐因為我用英文windows加中文南極星﹐故此可能會有問題﹐如你真的看不到中文﹐我會再post我的問題在這裡。謝謝。
你好﹐我是Snow。想請教一些關於array的問題。我要做一個program﹐有四個command button﹐它們分別是CREATE FILE﹐READ DATA﹐ADD DATA﹐及DELETE FILE。 下面是我的coding ********************************************** Dim StudentName(4) As String Dim Score(4) As Integer ------------------------------- Private Sub cmdAdd_Click() Open "C:\grade.txt" For Input As #1 For i = 1 To 4 Input #1, StudentName(i), Score(i) Next i Close #1 Open "C:\grade.txt" For Append As #1 For i = 1 To 4 StudentName(i) = InputBox("Student Name?", "Seq") Score(i) = InputBox("Score?", "Seq") Next i Close #1 End Sub (如果我只加一個DATA到FILE內﹐是否不應該用 For i = 1 to 4? 如不能又該如何code呢﹖) ------------------------------------------- Private Sub cmdCreate_Click() For i = 1 To 4 StudentName(i) = InputBox("Student Name?", "Seq") Score(i) = InputBox("Score?", "Seq") Next i Open "C:\grade.txt" For Output As #1 For i = 1 To 4 Write #1, StudentName(i), Score(i) Next i Close #1 End Sub (這個經你的指點應該沒有問題了。) --------------------------------------------- Private Sub cmdDelete_Click() Open "c:\grade.txt" For Input As #1 MsgBox "Do you want to delete the file?", vbOKCancel, "Seq" If Value = 1 Then Kill "c:\grade.txt" Else End End If End Sub (我試過這個程式﹐它只會delete C:\grade.txt"內的data﹐如果我想將整個file刪掉﹐該如何coding呢﹖) --------------------------------------------- Private Sub cmdRead_Click() Open "c:\grade1.txt" For Input As #1 For i = 1 To 4 Input #1, StudentName(i), Score(i) MsgBox StudentName(i) & " " & Score(i) & vbCrLf Next i Close #1 End Sub (這個都應該沒有問題﹐但如果我想將所有資料一次過顯示出來﹐除了用message box之外﹐還可以怎樣做呢﹖)
同樣內容勿重貼。