Writing text in collumns to file

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.

Hey folks, i've been missing some functions in Powerbasic like "Print Using" and "space$" commands. I used those to write text to defined collumns in my output file.

Is there an easy way to do this in PureBasic? Been trying a few things and not getting very far.

Regards

Fangles
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.
Hey folks, i've been missing some functions in Powerbasic like "Print Using" and "space$" commands. I used those to write text to defined collumns in my output file.
Mr Skunk has created a library to do both of these called "String2".
You can downloaded it directly from here:
http://perso.wanadoo.fr/mr.skunk/Libraries/String2.zip

Check out his other useful libraries at his home page:
http://www.skunknet.fr.st/
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.
Mr Skunk has created a library to do both of these called "String2".
You can downloaded it directly from here:
http://perso.wanadoo.fr/mr.skunk/Libraries/String2.zip
Yes, the space command works well, thank you. But the Using command does not do what I asked in the post. I think you didn't understand or I didn't give enough information.

I need to print TEXT data to collumns in a file. His USING command only works on numerical data, namely integers. It does not format text.

The Print Using command in PowerBasic works on text and/or numbers. I need both.

Regards, Fang.

Fangles
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.
The Print Using command in PowerBasic works on text and/or numbers. I need both.
Hmm... in every basic that I've ever used, "Print Using" is only used for
formatting numbers. Perhaps Power Basic changed the rules. :wink:

UPDATE: Can you please give me an example of what you want to do with "Print Using" ?

Edited by - PB on 30 October 2001 20:08:10
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Mr.Skunk.

Hi,

If you use non proportional fonts, you can use this

Code: Select all

 If OpenWindow(0, 200, 200,400 , 300, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget, "PureBasic Window")

drawingoutput(windowid())

a$="First text"
b$="This is a second text"
tab=200
a=textlength(a$)
b=textlength(b$)
locate(tab-a,40):drawtext(a$)
locate(tab-b,60):drawtext(b$)
stopdrawing()

  Repeat
    EventID.l = WaitWindowEvent()

    If EventID = #PB_EventCloseWindow
      Quit = 1
    EndIf

  Until Quit = 1
  
EndIf

End 
And if you use proportional fonts, you can use this :

Code: Select all

 If OpenWindow(0, 200, 200,400 , 300, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget, "PureBasic Window")

drawingoutput(windowid())

a$="First text"
b$="This is a second text"
tab=20
a=len(a$)
b=len(b$)
locate(tab-a,40):drawtext(a$)
locate(tab-b,60):drawtext(b$)
stopdrawing()

  Repeat
    EventID.l = WaitWindowEvent()

    If EventID = #PB_EventCloseWindow
      Quit = 1
    EndIf

  Until Quit = 1
  
EndIf

End 
Hope it helps...

Mr Skunk

Mr Skunk's PureBasic Web Page
http://www.skunknet.fr.st
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.
Hi,

If you use non proportional fonts, you can use this

Hope it helps...
Mr Skunk
No Mr Skunk, it doesn't, sorry. I said in my earlier post, "printing in collumns to a FILE, NOT the screen. Thanks anyway.

Fangles
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.
Hmm... in every basic that I've ever used, "Print Using" is only used for
formatting numbers. Perhaps Power Basic changed the rules. :wink:

Edited by - PB on 30 October 2001 20:08:10
Could be right, it's been a few months since I used PowerBasic. Not at all since I got PureBasic. What I really need however, is the ability of MID to insert data back into a string (Like PowerBASIC's MID$) but with the ability to truncate extra data if it doesn't fit.

Franco posted an insert template but it pads the string out with extra data if it doesn't fit but I don't the string to grow (for neat formatting reasons).

I want to be able to print to a text file in neat collums with tabs predetermined by me. If the data in each collumn impinges on the next, it must be truncated.

regards, Fang.

Fangles
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by wavemaker.

Is this what you need? I don't think it's worth a new function, this procedure should work quite as fast as coding it in Asm:

Code: Select all

Procedure.s Fit(string.s, size.l)
  If sizeLen(string)
      string = string + Space(size-Len(string))
    EndIf
  EndIf
  ProcedureReturn string
EndProcedure
Bye,

Juan Calderón Alonso
Registered user
Post Reply