Jabaco Source |
|
1 |
Open FileName For Binary/Input/Outrut/Random [Access][Read/Write] As FileNr |
Jabaco Source |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
Option Explicit Dim FNam As String Private Sub Form_Load() FNam = "C:\Test.txt" End Sub Private Sub Command1_Click() Dim FNr As Integer FNr = FreeFile 'Open FNam For Output As FNr OOpen FNam, Output, FNr PPrint FNr, "this is the first line" PPrint FNr, "this is the next line" PPrint FNr, "this is the last line" CClose FNr End Sub Private Sub Command2_Click() Dim FNr As Integer FNr = FreeFile Dim sFile As New StringBuilder Dim sLine As New StringBuffer 'Open FNam For Input As FNr OOpen FNam, Input, FNr Do Until EEOF(FNr) Line_Input FNr, sLine sFile.append(sLine & vbCrLf) Loop CClose FNr Text1.Text = sFile End Sub |
Jabaco Source |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
Option Explicit Import java#util Import java#lang Import javax#swing#text Import javax#swing#text#rtf Dim FHList As New java#util#ArrayList ' As VBFileHandler Dim CurIndex As Integer Dim CurFHnd As VBFileHandler Public Function FreeFile() As Integer Dim i As Integer For i = 0 To FHList.size - 1 If FHList.get(i) = Nothing Then CurIndex = i FreeFile = CurIndex Exit Function End If Next End Function Private Sub SetCurFileHandler(FNr As Integer) If CurIndex <> FNr Then CurIndex = FNr CurFHnd = FHList(CurIndex) End If End Sub Public Sub OOpen(aFileName As String, aFileMode As VBFileMode, aFileNr As Integer) CurFHnd = Open(aFileName, aFileMode) FHList(aFileNr) = CurFHnd End Sub Public Function EEOF(FNr As Integer) As Boolean SetCurFileHandler(FNr) EEOF = EOF(CurFHnd) End Function Public Sub PPrint(FNr As Integer, sLine As String) SetCurFileHandler(FNr) Call Write(CurFHnd, sLine & vbCrLf) End Sub Public Sub Line_Input(FNr As Integer, sBuff As StringBuffer) SetCurFileHandler(FNr) sBuff.setLength(0) sBuff.append(ReadLine(CurFHnd)) End Sub Public Sub CClose(FNr As Integer) SetCurFileHandler(FNr) Call Close(CurFHnd) CurFHnd = Nothing FHList(FNr) = Nothing End Sub |
Quoted
as well as basic graphics operations
Jabaco Source |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
Dim FNm As String Private Sub Form_Load() FNm = "C:\Test.txt" End Sub Private Sub Command1_Click() Dim FNr As Integer: FNr = FreeFile Open FNm For Output As FNr Print #FNr, "1. line" Write #FNr, "2. line quoted" Print #FNr, "3. line first entry + "; Print #FNr, "next entry + "; Write #FNr, "next entry quoted + "; Print #FNr, " + last entry" Print #FNr, "4. line"; Close FNr End Sub Private Sub Command2_Click() Dim FNr As Integer: FNr = FreeFile Open FNm For Input As FNr Dim sl As String Dim s As String While Not EOF(FNr) Line Input #FNr, sl s = s & sl & vbCrLf Wend Close FNr Text1.Text = s End Sub |
Jabaco Source |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
Dim FNm As String Private Sub Form_Load() FNm = "C:\Test.txt" End Sub Private Sub Command1_Click() Dim FNr As Integer: FNr = FreeFile Open FNm , Output , FNr Print(FNr, "1. line") Write(FNr, "2. line quoted") Print(FNr, "3. line first entry + ", 1) Print(FNr, "next entry + ", 1) Write(FNr, "next entry quoted + ", 1) Print(FNr, " + last entry") Print(FNr, "4. line", 1) Close FNr End Sub Private Sub Command2_Click() Dim FNr As Integer: FNr = FreeFile Open FNm , Input , FNr Dim sl As New java#lang#StringBuffer Dim s As String While Not EOF(FNr) Line_Input FNr, sl s = s & sl & vbCrLf Wend Close FNr Text1.Text = s End Sub |
OK I have changed the FileSystem module. Now it is possible to write File IO that is more similar to VB.
Let's consider the following VB-example:
Jabaco Source
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 Dim FNm As String Private Sub Form_Load() FNm = "C:\Test.txt" End Sub Private Sub Command1_Click() Dim FNr As Integer: FNr = FreeFile Open FNm For Output As FNr Print #FNr, "1. line" Write #FNr, "2. line quoted" Print #FNr, "3. line first entry + "; Print #FNr, "next entry + "; Write #FNr, "next entry quoted + "; Print #FNr, " + last entry" Print #FNr, "4. line"; Close FNr End Sub Private Sub Command2_Click() Dim FNr As Integer: FNr = FreeFile Open FNm For Input As FNr Dim sl As String Dim s As String While Not EOF(FNr) Line Input #FNr, sl s = s & sl & vbCrLf Wend Close FNr Text1.Text = s End Sub
in Jabaco it is:
Jabaco Source
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Dim FNm As String Private Sub Form_Load() FNm = "C:\Test.txt" End Sub Private Sub Command1_Click() Dim FNr As Integer: FNr = FreeFile Open FNm , Output , FNr Print(FNr, "1. line") Write(FNr, "2. line quoted") Print(FNr, "3. line first entry + ", 1) Print(FNr, "next entry + ", 1) Write(FNr, "next entry quoted + ", 1) Print(FNr, " + last entry") Print(FNr, "4. line", 1) Close FNr End Sub Private Sub Command2_Click() Dim FNr As Integer: FNr = FreeFile Open FNm , Input , FNr Dim sl As New java#lang#StringBuffer Dim s As String While Not EOF(FNr) Line_Input FNr, sl s = s & sl & vbCrLf Wend Close FNr Text1.Text = s End Sub
OlimilO
Beginner
Date of registration: Sep 21st 2009
Location: Firenze, Italy
Occupation: Software Developer
Hobbies: Sport, Music (I play the piano)
Jabaco Source |
|
1 2 3 4 5 6 7 8 9 10 11 12 |
Private Sub Command2_Click() Dim FNr As Integer: FNr = FreeFile Open FNm , Input , FNr Dim sl As New java#lang#StringBuffer Dim s As String While Not EOF(FNr) Line_Input FNr, sl s = s & sl & vbCrLf Wend Close FNr Text1.Text = s End Sub |
Beginner
Date of registration: Sep 21st 2009
Location: Firenze, Italy
Occupation: Software Developer
Hobbies: Sport, Music (I play the piano)
Beginner
Date of registration: Sep 21st 2009
Location: Firenze, Italy
Occupation: Software Developer
Hobbies: Sport, Music (I play the piano)
Source code |
|
1 2 3 4 5 |
i = FreeFile() Open fn For Input As #i j = FreeFile() Open fn2 For Output As #j ' i = 1 and j = 2 |
Jabaco Source |
|
1 2 3 4 5 |
i = FreeFile() Open fn, Input, i j = FreeFile() Open fn2, Output, j ' i = 1 and j = 1 |
Intermediate
Date of registration: Jan 1st 2009
Location: Hanover, Germany
Occupation: Software Engineer
Hobbies: Hilbert Curves
Jabaco Source |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
Private Sub Command1_Click() Dim fi As Integer Const maxI = 999 Dim i As Integer For i = 1 To maxI fi = FreeFile Debug.Print i & ": " & fi Open "c:\tmp\testFile" & i & ".tmp" For Output As #fi Next i For i = 1 To maxI Close #i Kill "c:\tmp\testFile" & i & ".tmp" Next i End Sub |