You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

turkulainen

Beginner

  • "turkulainen" is male
  • "turkulainen" started this thread

Posts: 20

Date of registration: Jun 30th 2009

Location: Turku, Finland

Occupation: engineer

  • Send private message

1

Saturday, September 19th 2009, 7:47pm

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.

OlimilO

Intermediate

  • "OlimilO" is male

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

2

Saturday, September 19th 2009, 9:23pm

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

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

OlimilO

Intermediate

  • "OlimilO" is male

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

3

Saturday, September 19th 2009, 9:43pm

PS

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

OlimilO

Intermediate

  • "OlimilO" is male

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

4

Monday, September 21st 2009, 10:41pm

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:

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

turkulainen

Beginner

  • "turkulainen" is male
  • "turkulainen" started this thread

Posts: 20

Date of registration: Jun 30th 2009

Location: Turku, Finland

Occupation: engineer

  • Send private message

5

Monday, October 12th 2009, 7:56pm

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.




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

OlimilO

Intermediate

  • "OlimilO" is male

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

6

Monday, October 12th 2009, 10:07pm

Quoted

or does it have to follow the syntax with parentheses?

normally it should be possible without parentheses, I really do not know why it's unfortunately not possible until now...
It's a question for the Jabaco parser / compiler I guess



regards

OlimilO

dolcevita

Beginner

  • "dolcevita" is male

Posts: 12

Date of registration: Sep 21st 2009

Location: Firenze, Italy

Occupation: Software Developer

Hobbies: Sport, Music (I play the piano)

  • Send private message

7

Thursday, October 22nd 2009, 1:08pm

Hi,

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.

OlimilO

Intermediate

  • "OlimilO" is male

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

8

Thursday, October 22nd 2009, 1:17pm

Hi Andrea,



yes it's a kind of beta state. The reason is that there is also a close-method in the form.

please instead use:

FileSystem.Close(FNr)



hmm normally the right function should be found when giving it a parameter.

but inside the form the Form.Close will be prefered



OlimilO

dolcevita

Beginner

  • "dolcevita" is male

Posts: 12

Date of registration: Sep 21st 2009

Location: Firenze, Italy

Occupation: Software Developer

Hobbies: Sport, Music (I play the piano)

  • Send private message

9

Thursday, October 22nd 2009, 2:22pm

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

dolcevita

Beginner

  • "dolcevita" is male

Posts: 12

Date of registration: Sep 21st 2009

Location: Firenze, Italy

Occupation: Software Developer

Hobbies: Sport, Music (I play the piano)

  • Send private message

10

Thursday, October 22nd 2009, 3:26pm

Hi OlimilO,

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 :?:

OlimilO

Intermediate

  • "OlimilO" is male

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

11

Friday, October 23rd 2009, 3:18pm

Yes the source is totally for the garbage collector. :rolleyes: 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.

regards

OlimilO

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

12

Friday, October 23rd 2009, 4:12pm

My VB allowed 255 files:

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

Rate this thread
WoltLab Burning Board