You are not logged in.

Nisheeth

Beginner

  • "Nisheeth" is male
  • "Nisheeth" started this thread

Posts: 8

Date of registration: Oct 27th 2010

Location: India

Occupation: Researcher

  • Send private message

1

Tuesday, December 28th 2010, 3:07pm

file handling :(

Confused
how to convert this into jabaco

VB Code
----------

Private Sub Command1_Click()
Open "c:\a.txt" For Output As #1
Print #1, "abc"
Print #1, "123"
Print #1, "aaaaaa"
Close #1
End Sub
Private Sub Command2_Click()

Open "c:/a.txt" For Input As #1
Line Input #1, x
Line Input #1, y
Line Input #1, z
Text1.Text = x
Text2.Text = y
Text3.Text = z
Close #1
End Sub

found a function open() (Open ("c:\a.txt", Output) but then, To what should I assign it to????

This post has been edited 1 times, last edit by "Nisheeth" (Dec 28th 2010, 3:12pm)


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

2

Tuesday, December 28th 2010, 11:27pm

This can be accomplished either by using the Jabaco Framework File handling.
Or you could do it "the Java way" as follows:

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

Import java#io#File
Import java#io#FileReader
Import java#io#FileWriter 
Import java#io#LineNumberReader
Import java#io#PrintWriter

Public Sub Command1_Click()
   Dim f As New File("myFile.txt")
   Dim fw As New FileWriter(f)
   Dim pw As New PrintWriter(fw)
           
   pw.println "abc"
   pw.println "123"
   pw.println "aaaaaa"
   pw.close
End Sub   

Public Sub Command2_Click()
   Dim f As New File("myFile.txt")
   Dim fr As New FileReader(f)
   Dim lnr As New LineNumberReader(fr)
        
   Text1.text = lnr.readLine
   Text2.text = lnr.readLine
   Text3.text = lnr.readLine
   lnr.close
End Sub


File handling has been discussed in numerous posts. You might want to have a look at the tutorial.

An example:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
Public Sub Command1_Click()
Dim myFile As VBFileHandler
   ' write
   myFile = Open("C:\test.txt", Random, ReadAndWrite, Shared)
   Call write(myFile, "testtesttest")
   Call Close(myFile)
   'read
   myFile = Open("C:\test.txt", Random, ReadAndWrite, Shared)
   MsgBox readline(myFile)
   Call Close(myFile)
End Sub


My impression is that the Framework is not complete here.
But the Java constructs should work quite well.
For real applications, appropriate error handling would be necessary.

Greetings

A1880

Rate this thread
WoltLab Burning Board