You are not logged in.

klctal

Trainee

  • "klctal" is male
  • "klctal" started this thread

Posts: 70

Date of registration: Jul 13th 2009

Location: Shanghai

Hobbies: Developing software

  • Send private message

1

Wednesday, July 22nd 2009, 2:55am

How to read multi lined documents

Hi everyone,

Could somebody tell me how to read a multi lined document? ;)

Thanks, klctal
:D

OlimilO

Intermediate

  • "OlimilO" is male

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

2

Wednesday, July 22nd 2009, 8:55am

Hi klctal,

Quoted

Could somebody tell me how to read a multi lined document?

Yes, please show me your code. How would you do it in VB?
we could try to post a code that is very close to the VB-syntax.



regards

OlimilO

klctal

Trainee

  • "klctal" is male
  • "klctal" started this thread

Posts: 70

Date of registration: Jul 13th 2009

Location: Shanghai

Hobbies: Developing software

  • Send private message

3

Wednesday, July 22nd 2009, 11:20am

Hi OlimilO,


Thanks for your time. :)
In VB, I would just use

RichTextBox1.LoadFile("C:\Text1.rtf")

or

Open CommonDialog1.FileName For Input As #1
Do Until EOF(1)
Line Input #1, lineoftext$
alltext$ = alltext$ & lineoftext$
RichTextBox1.Text = alltext$
Loop
Close #1



Thanks,
klctal
:D

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

4

Wednesday, July 22nd 2009, 12:16pm

Hi,
sorry, but I haven't been able to find a simpler solution for your LoadFile() question:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Option Explicit

Import javax#swing#text#rtf 

Public Sub Command1_Click()
   Dim kit As RTFEditorKit 
   Dim doc As DefaultStyledDocument 
   Dim fis As FileInputStream 
   
   kit = Cast(RichTextBox1.Parent.getEditorKitForContentType("text/rtf"), RTFEditorKit)
   doc = Cast(kit.createDefaultDocument, DefaultStyledDocument)      
   fis = New FileInputStream(New File("test.rtf"))
   
   Call RichTextBox1.Parent.setEditorKit(kit)
   Call kit.read(fis, doc, 0)
   Call RichTextBox1.Parent.setDocument(doc)
   
   fis.close
End Sub


Probably a good point to improve the Jabaco framework implementation of RichTextBox.

Greetings

A1880

This post has been edited 1 times, last edit by "A1880" (Jul 22nd 2009, 12:27pm)


klctal

Trainee

  • "klctal" is male
  • "klctal" started this thread

Posts: 70

Date of registration: Jul 13th 2009

Location: Shanghai

Hobbies: Developing software

  • Send private message

5

Wednesday, July 22nd 2009, 12:49pm

Hi A1880,

Thanks a lot!

Your source helped me out a lot.

But when I typed if in and ran started debuging, Jabaco said the DefaultStyledDocument class was not found. ;(

Is there a solution to this problem?



Thanks,

klctal
:D

OlimilO

Intermediate

  • "OlimilO" is male

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

6

Wednesday, July 22nd 2009, 1:08pm

@A1880: superspitzenmäßig! :)
@klctal:

Quoted

the DefaultStyledDocument class was not found
in Jabaco klick the menuitem "Project"->"References (Classpath)"
The dialog "Imports" appears, in the box "Classname" type: DefaultStyledDocument and click "Find Class"
You see that it will be found in the namespace javax#swing#text, now just activate the checkbox left from the class and close the dialog
Alternatively you could also write into your Code:
Import javax#swing#text
above the line:
Import javax#swing#text#rtf
but then the whole namespace text will be imported, which is big.
regards OlimilO

OlimilO

Intermediate

  • "OlimilO" is male

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

7

Wednesday, July 22nd 2009, 2:01pm

@A1880: habs mir nochmal angeschaut ...

@klctal: you could use this instead

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Import javax#swing#text
Import javax#swing#text#rtf 

Public Sub Command3_Click()
   CommonDialog1.ShowOpen
   If CommonDialog1.IsCanceled Then Exit Sub
   RichTextBox_LoadFile(RichTextBox1, CommonDialog1.FileName)
End Sub
Public Sub RichTextBox_LoadFile(RTB As RichTextBox, aFileName As String)
  Dim fis As New FileInputStream(aFileName)
  Dim doc As New DefaultStyledDocument(New StyleContext)
  Dim kit As New RTFEditorKit
  RTB.Parent.setEditorKit(kit)
  RTB.Parent.setDocument(doc)  
  kit.read(fis, doc, 0)
  fis.close
End Sub




regards

OlimilO

klctal

Trainee

  • "klctal" is male
  • "klctal" started this thread

Posts: 70

Date of registration: Jul 13th 2009

Location: Shanghai

Hobbies: Developing software

  • Send private message

8

Wednesday, July 22nd 2009, 2:21pm

Hi OlimilO and A1880,

The source code was great!! :thumbsup: :thumbup: Both of them worked!

Thanks,

klctal
:D

klctal

Trainee

  • "klctal" is male
  • "klctal" started this thread

Posts: 70

Date of registration: Jul 13th 2009

Location: Shanghai

Hobbies: Developing software

  • Send private message

9

Thursday, August 13th 2009, 8:30am

Another thing:
I found out a way to read textfiles with more than one line:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
Public Sub SingleLoad(FilePath As String) 
Dim FF As VBFileHandler 
Dim LineText As String 
FF = Open(FilePath) 
Do Until FF.EOF 
LineText = ReadLine(FF) 
TextMain.Text = TextMain.Text + LineText 
Loop 
FF.close()
End Sub
:D

This post has been edited 1 times, last edit by "klctal" (Aug 13th 2009, 10:07am)


Rate this thread
WoltLab Burning Board