2017-10-17 11 views
0

私自身の目的のために番号ジェネレータを作成しています。 私はすでにそれがこれらの機能で動作するように作られた: - 私はしたいどのような機能に生成された番号保存されたファイルから保存されたテキストを取得する方法

保存: を - 私はそれをメモ帳から最後に生成された番号をロード閉じると。ここ

はコードです:使用バイナリモードの

Private Const FilePath As String = "C:\Users\sto0007404\Documents\Numbers.txt" 
Private CurrentNumber As Long 

Private Sub Command1_Click() 
    CurrentNumber = CurrentNumber + 1 
    txtRefNo.Text = "EM" & Format(CurrentNumber, String(4, "0")) 
End Sub 

Private Sub Form_Load() 
    Dim TextFileData As String, MyArray() As String, i As Long 

    ' Open file as binary 
    Open "FilePath" For Binary As #1 

    ' Read entire file's data in one go 
    TextFileData = Space$(LOF(1)) 
    Get #1, , TextFileData 

    ' Close File 
    Close #1 

    ' Split the data in separate lines 
    MyArray() = Split(TextFileData, vbCrLf) 

    For i = 0 To UBound(MyArray()) 
     ' Set CurrentNumber equal to the current max 
     CurrentNumber = Val(Mid$(MyArray(i), 2)) 
    Next 
End Sub 

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) 
    Dim i As Long 

    ' delete the old file 
    If Not LenB(Dir(FilePath)) = 0 Then Kill FilePath 

    'open the file for writing 
    Open FilePath For Output As #1 

    For i = 1 To CurrentNumber 
     Write #1, "EM" & Format(i, String(4, "0")) 
    Next 

    'close the file (if you dont do this, you wont be able to open it again!) 
    Close #1 
End Sub 
+1

ようこそstackoverflow。 https://stackoverflow.com/help/how-to-askを読んでください。 – jac

+0

どの部分に問題がありますか?何がうまくいくのですか、特に何がうまくいかないのですか?どのように行動し、何を期待しましたか? – Hrqls

+0

問題は何か、説明してください。 – vbdevelp

答えて

0

独立した...#1 印刷#1として出力用

開いているファイル、 "いくつかのテキスト" 近い#1

#1 ライン入力#1として入力用

オープンファイル、MYVARIABLE 近い#1

msgbox myvariable

フローは同じですが、問題は何ですか?

関連する問題