File operations and basic graphics operations
I would like to suggest once again that it would be good to accept VB6 syntax for file opening, reading, writing and closing operations, as well as basic graphics operations. This would make it much easier to port larger programs from VB6 to Jabaco. It would be much more convenient if we don't have to maintain two different versions, and I think it will attract more users also.
Hi,
here you can see what is possible until now, the syntax is as close as possible für reading and writing (printing in) lines from/in text files. by using Line Input
I try to implement something like this in the framework.
if you want to have a syntax similar to VB for the Open statement
than this is of course not possible to realize in the framework, this must be supported and done by the compiler
Modul: VBIO
well, the double-letters are a habit of mine, resp. it is necessary for now because the methods with the original names are impossible in a module separate from the Jabaco-framework. I hope I can solve this problem
OlimilO
here you can see what is possible until now, the syntax is as close as possible für reading and writing (printing in) lines from/in text files. by using Line Input
I try to implement something like this in the framework.
if you want to have a syntax similar to VB for the Open statement
|
|
Jabaco Source |
1 |
Open FileName For Binary/Input/Outrut/Random [Access][Read/Write] As FileNr |
than this is of course not possible to realize in the framework, this must be supported and done by the compiler
|
|
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 |
Modul: VBIO
|
|
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 |
well, the double-letters are a habit of mine, resp. it is necessary for now because the methods with the original names are impossible in a module separate from the Jabaco-framework. I hope I can solve this problem

OlimilO
PS
yes of course it should be possible to implement scaled VB-like graphics, but also it is a huge hill of work.
My idea is to translate the sourcecode of this VB.Net-package from Dario a very good programmer.
OlimilO
Quoted
as well as basic graphics operations
yes of course it should be possible to implement scaled VB-like graphics, but also it is a huge hill of work.
My idea is to translate the sourcecode of this VB.Net-package from Dario a very good programmer.
OlimilO
VB#FileSystem
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:
in Jabaco it is:
OlimilO
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
RE: VB#FileSystem
This is very good progress. I understand that the differences between Jabaco and VB6 are relatively small, but if I have to make 800 changes in 40 forms, I will not be able to do that often. I will then have to maintain separate versions and any additions to one will have to be done to the other also.
Can Jabaco now accept
Input #4, i, j, k
or does it have to follow the syntax with parentheses?
Perhaps it is not a very big task to accept the Line and PSet syntax from VB6 because Jabaco already has these methods taken care of; only the syntax is a bit different. I think it is not a big task to read the VB6 syntax and convert it to Jabaco. For a start, you can decide to accept only the simplest syntax of the Line command in VB6 (like Line (100,200)-(300,400),RGB(0,255,0)) and later extend it. This would make it possible for me and others to convert the other forms of the Line command to this simple form in the VB6 code which would then be acceptable to Jabaco.
Can Jabaco now accept
Input #4, i, j, k
or does it have to follow the syntax with parentheses?
Perhaps it is not a very big task to accept the Line and PSet syntax from VB6 because Jabaco already has these methods taken care of; only the syntax is a bit different. I think it is not a big task to read the VB6 syntax and convert it to Jabaco. For a start, you can decide to accept only the simplest syntax of the Line command in VB6 (like Line (100,200)-(300,400),RGB(0,255,0)) and later extend it. This would make it possible for me and others to convert the other forms of the Line command to this simple form in the VB6 code which would then be acceptable to Jabaco.
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
Hi,
I'm sorry your code fails:
ERROR: Method 'Close' not found witn these parameters.
I'm sorry your code fails:
|
|
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 |
ERROR: Method 'Close' not found witn these parameters.
Hi OlimilO,
thanks to your suggestion, now the project works!
Also the function Print must be called as FileSystem.Print
(i guess for the same reason).
If these semantics differences could be uniformed
to VB language, Jabaco will be more flexible importing
old vb projects that uses files.
Regards,
Andrea
thanks to your suggestion, now the project works!
Also the function Print must be called as FileSystem.Print
(i guess for the same reason).
If these semantics differences could be uniformed
to VB language, Jabaco will be more flexible importing
old vb projects that uses files.
Regards,
Andrea
Hi OlimilO,
please take a look a these line, that give
different result between Jabaco and VB:
in jabaco i = 1 and j = 1 (instead of 2 that is correct)
is it a bug in FreeFile
please take a look a these line, that give
different result between Jabaco and VB:
|
|
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 |
in jabaco i = 1 and j = 1 (instead of 2 that is correct)
is it a bug in FreeFile
My VB allowed 255 files:
Might be a limit of my Windows XP.
Cheers
A1880
|
|
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 |
Might be a limit of my Windows XP.
Cheers
A1880
Similar threads
-
General topics, questions and discussions »-
FAQ - HOW TO?
(Sep 10th 2009, 7:49am)
-
Bugreports and known bugs »-
[VERSION 1.4.0] Bug Report: Arithmetic operations
(Mar 24th 2009, 2:20pm)
-
General topics, questions and discussions »-
ListBox operations
(Feb 28th 2009, 6:15pm)
-
General topics, questions and discussions »-
File operations don't work for me
(Dec 14th 2008, 7:32pm)

I had a better approach in the first, then decide to do another one. Do you know something about hashcode? how would you program it? you could help in figuring out how many open files are possible in VB6.