Reading everyline from a TXT?
-
sharkbate24
- User

- Posts: 50
- Joined: Sat Aug 30, 2008 3:21 pm
Reading everyline from a TXT?
Hey everyone,
So I have a TXT file with 3 lines in it. I use SetGadgetText to put the txt in, but for some reason, only the last line is being added.
Any idea's what script I should use?
I'm using While Eof = 0.
Thanks.
So I have a TXT file with 3 lines in it. I use SetGadgetText to put the txt in, but for some reason, only the last line is being added.
Any idea's what script I should use?
I'm using While Eof = 0.
Thanks.
[Registed PB User]
[Windows XP SP2 | PureBasic 4.20]
[Windows XP SP2 | PureBasic 4.20]
Add #CRLF$ at the end of each line
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Now now Kaeru, what kind of help is that? tut tut!
@sharkbate24 : read the ****ing manual!
Only kidding; do what ts-soft suggests and append each read string to a string variable with #CRLF$ added to each string and then, when you've read all the data, use SetGadgetText() etc.
@sharkbate24 : read the ****ing manual!
Only kidding; do what ts-soft suggests and append each read string to a string variable with #CRLF$ added to each string and then, when you've read all the data, use SetGadgetText() etc.
I may look like a mule, but I'm not a complete ass.
-
sharkbate24
- User

- Posts: 50
- Joined: Sat Aug 30, 2008 3:21 pm
Thanks guys. Sorry about that hehe, I kept browsing the manual and there was nothing about a new line. My apologies.srod wrote:Now now Kaeru, what kind of help is that? tut tut!
@sharkbate24 : read the ****ing manual!
![]()
Only kidding; do what ts-soft suggests and append each read string to a string variable with #CRLF$ added to each string and then, when you've read all the data, use SetGadgetText() etc.
EDIT: I got another problem. The code I have so far is:
Code: Select all
While Eof(#UpdateInfo) = 0
updateinfo$ = ReadString(#UpdateInfo) + #CRLF$
Wend
SetGadgetText(#String_1, updateinfo$)Thanks!
[Registed PB User]
[Windows XP SP2 | PureBasic 4.20]
[Windows XP SP2 | PureBasic 4.20]
Code: Select all
If ReadFile(0, "text.txt")
While Not Eof(0)
AddGadgetItem(#edit, -1, ReadString(0))
Wend
CloseFile(0)
EndIf
; next way:
If ReadFile(0, "text.txt")
While Not Eof(0)
Text.s + ReadString(0) + #CRLF$
Wend
SetGadgetText(#edit, Text)
CloseFile(0)
EndIf
; next way:
If ReadFile(0, "text.txt")
length = Lof(0)
Text.s = Space(length)
ReadData(0, @Text, length)
SetGadgetText(#edit, Text)
CloseFile(0)
EndIfPureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Alternatively, if for example filling an editor gadget, then you can use AddGadgetItem() to add each line separately (no #CRLF$ required).
**EDIT : sharkbate, the debugger will substitute EOL's for squares etc.
****EDIT : @ts-soft, that 3rd method is not really advisable in case the text file holds text in utf-8 format.
**EDIT : sharkbate, the debugger will substitute EOL's for squares etc.
****EDIT : @ts-soft, that 3rd method is not really advisable in case the text file holds text in utf-8 format.
I may look like a mule, but I'm not a complete ass.
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
in every loopturn you completely overwrite the previous line.The code I have so far is:Code: Select all
While Eof(#UpdateInfo) = 0 updateinfo$ = ReadString(#UpdateInfo) + #CRLF$ Wend SetGadgetText(#String_1, updateinfo$)
if you want to add up lines, you have to use a "+", not "="
oh... and have a nice day.
-
sharkbate24
- User

- Posts: 50
- Joined: Sat Aug 30, 2008 3:21 pm
Thanks guys. Yeah, I realised that after looking at what each line did.Kaeru Gaman wrote:in every loopturn you completely overwrite the previous line.The code I have so far is:Code: Select all
While Eof(#UpdateInfo) = 0 updateinfo$ = ReadString(#UpdateInfo) + #CRLF$ Wend SetGadgetText(#String_1, updateinfo$)
if you want to add up lines, you have to use a "+", not "="
Also I've tried what everyone has told me here, but I'm still getting squares in between each line.
Any idea's?
Thanks everyone.
[Registed PB User]
[Windows XP SP2 | PureBasic 4.20]
[Windows XP SP2 | PureBasic 4.20]
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
I forgot the last methode (windows only)
Code: Select all
Procedure StreamFileIn_Callback(hFile, pbBuff, cb, pcb)
ProcedureReturn ReadFile_(hFile, pbBuff, cb, pcb, 0)!1
EndProcedure
Procedure Editor_LoadText(Gadget, File.s)
Protected FF
Protected StreamData.EDITSTREAM
FF = ReadFile(#PB_Any, File)
If FF
StreamData\dwCookie = FileID(FF)
StreamData\dwError = #Null
StreamData\pfnCallback = @StreamFileIn_Callback()
SendMessage_(GadgetID(Gadget), #EM_STREAMIN, #SF_TEXT, @StreamData)
CloseFile(FF)
EndIf
EndProcedurePureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

-
sharkbate24
- User

- Posts: 50
- Joined: Sat Aug 30, 2008 3:21 pm
Basically, where the new lines are, it's getting replaced by a square. It's a TXT file. The gadget is a text box.Kaeru Gaman wrote:so there are additional chars in your textfile that can't be displayed properly.
... what kind of textfile is it?
Thanks.
[Registed PB User]
[Windows XP SP2 | PureBasic 4.20]
[Windows XP SP2 | PureBasic 4.20]
Try the following. Any squares?
Code: Select all
If OpenWindow(0, 0, 0, 270, 160, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
TextGadget(0, 10, 10, 250, 60, "TextGadget Standard (Left)")
a$ = "line 1" + #CRLF$ + "line 2"
SetGadgetText(0, a$)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
I may look like a mule, but I'm not a complete ass.
-
sharkbate24
- User

- Posts: 50
- Joined: Sat Aug 30, 2008 3:21 pm
Nope, no squares.srod wrote:Try the following. Any squares?
Code: Select all
If OpenWindow(0, 0, 0, 270, 160, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) TextGadget(0, 10, 10, 250, 60, "TextGadget Standard (Left)") a$ = "line 1" + #CRLF$ + "line 2" SetGadgetText(0, a$) Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow EndIf
Thanks.
[Registed PB User]
[Windows XP SP2 | PureBasic 4.20]
[Windows XP SP2 | PureBasic 4.20]

