[DONE] Writing to a file from a stringgadet

Just starting out? Need help? Post your questions and find answers here.
PresFox
User
User
Posts: 33
Joined: Sat Jan 19, 2008 9:30 am

[DONE] Writing to a file from a stringgadet

Post by PresFox »

Hello,

I have a stringgadget in my window, and i want to take the input from it and write it to a file.

I am not sure how to go about this.

I have tried this:

Code: Select all

Procedure Open_Window_1()
  If OpenWindow(#Window_1, 308, 114, 391, 76, "New window ( 1 )",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
    If CreateGadgetList(WindowID(#Window_1))
      StringGadget(#String_0, 20, 10, 340, 30, newlander$)
      ButtonGadget(#Button_3, 290, 50, 70, 20, "add")
      
    EndIf
  EndIf
EndProcedure
and this is the in the main loop:

Code: Select all

 ElseIf GadgetID = #Button_3
    
    ; add a landing page to the list
    
    If OpenFile(0, "Landers.dat")    ; opens an existing file or creates one, if it doesn't exist yet
    FileSeek(0, Lof(0))         ; jump to the end of the file (result of Lof() is used)
    WriteStringN(0, newlander$)
    CloseFile(0)
  EndIf
The file gets created, but nothing is written in it?
Last edited by PresFox on Sat Apr 03, 2010 6:20 pm, edited 1 time in total.
User of PB 4.41 - x86
On Windows 7
Intel Core I5 2.26GHZ
8 GB RAM
ATI Mobility Radeon HD 5650
gnasen
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Sep 24, 2008 12:21 am

Re: Writing to a file from a stringgadet

Post by gnasen »

As far as I can see there may be different mistakes, however I can only guess, because the code is not working.
Pleass post next time copy-able code which can be run immediatly.

1. newlander$ seems to be an empty string
2. #String_0, #Button_3 may have the same value

A very very useful command is by the way enable explicit. It forces you to declare every variable. At first it seems annoying, but you wont miss it in future.
pb 5.11
User avatar
Arctic Fox
Enthusiast
Enthusiast
Posts: 609
Joined: Sun Dec 21, 2008 5:02 pm
Location: Aarhus, Denmark

Re: Writing to a file from a stringgadet

Post by Arctic Fox »

Have you checked the value of the newlander$ string? (send it to the debug output window using 'Debug')

If you want the contents of the StringGadget you should use GetGadgetText().
For instance

Code: Select all

WriteStringN(0, GetGadgetText(#String_0))
Edit
Beaten by gnasen :lol:
Last edited by Arctic Fox on Sat Apr 03, 2010 4:17 pm, edited 1 time in total.
User avatar
KJ67
Enthusiast
Enthusiast
Posts: 218
Joined: Fri Jun 26, 2009 3:51 pm
Location: Westernmost tip of Norway

Re: Writing to a file from a stringgadet

Post by KJ67 »

You may be looking for GetGadgetText()?
The best preparation for tomorrow is doing your best today.
PresFox
User
User
Posts: 33
Joined: Sat Jan 19, 2008 9:30 am

Re: Writing to a file from a stringgadet

Post by PresFox »

Thanks, indeed i was!

Works :)
User of PB 4.41 - x86
On Windows 7
Intel Core I5 2.26GHZ
8 GB RAM
ATI Mobility Radeon HD 5650
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Writing to a file from a stringgadet

Post by Michael Vogel »

Hi PresFox, welcome to the board :wink:

Just a note how to indicate that a question has been solved: just edit your first posting and write something like "[Done] " at the front of the subject...

Michael
UserOfPure
Enthusiast
Enthusiast
Posts: 469
Joined: Sun Mar 16, 2008 9:18 am

Re: Writing to a file from a stringgadet

Post by UserOfPure »

Putting [Done] at the start just means better solutions (when possible) may be ignored, though. People with better solutions may just skip the thread. Something to be aware of. I wouldn't be so quick to close off future solutions to lurkers.
Post Reply