✔ 最佳答案
舉一個例子,譬如你想做一個銀行戶口記錄;
資料包括Account Number、date、time、credit/debit、balance。
假設你己經在Form Set好哂D輸入介面,輸入controls包括txtAcc、dtpDate、dtpTime、optCr、optDr、txtBal。
寫入(Save)Subroutine係:
Private Sub cmdEnter_Click()
Open "c:\temp\acc.dat" For Append As #1
Write #1, txtAcc.Text, dtpDate.Value, dtpTime.Value, optCr.Value, txtBal.Text
Close #1
End Sub
只要你Click cmdEnter,個D介面control的data就寫入acc.dat檔案,如果你用notepad都開到;
讀出(Load)Subroutine係:
Private Sub cmdDisplay_Click()
Dim strAcc As String
Dim datDate As Date
Dim datTime As Time
Dim boolCredit As Boolean
Dim dblBalance As Double
Dim counter As Integer
counter = 1
Open "c:\temp\acc.dat" For Input As #1
Do While Not EOF(1)
If counter = 3 Then
'read file into valuable
Input #1, strAcc, datDate, datTime, boolCredit, dblBalance
Else
counter = counter +1
End If
Loop
Close #1
If strAcc <> "" Then
txtAcc.Text = strAcc
dtpDate.Value = datDate
dtpTime.Value = datTime
If boolCredit Then
optCr.Value = True
Else
optCr.Value = False
End If
txtBal.Text = dblBalance
End If
End Sub
上面係擷取第三個記錄,如果想擷取其他記錄,你可以改成counter = 其他數字,或者一些變數,待run time才輸入等等。
你可以跟住試試
參考: vb experience but NOT COPY AND PASTE