Printing format

In this category you can exchange your programming questions and solutions.
Post Reply
Mel
Posts: 32
Joined: Mon Dec 22, 2008 1:19 pm

Printing format

Post: # 378Post Mel
Fri Jan 02, 2009 1:44 pm

Hello everyone.  This is my first post here.  My question is this.  In other Basic languages that I have used combining ;(semi-colon), (,(comma)) with a "Print" statement is used to format the output.  I cannot get them to work with fnxBasic.  Am I missing something?

Mel

Mel
Posts: 32
Joined: Mon Dec 22, 2008 1:19 pm

Printing format

Post: # 379Post Mel
Wed Jan 07, 2009 2:03 pm

Well, since no one has replied to this post, I will assume that using semi-colon`s and comma`s with a "Print" statement is not supported in this version of FnxBasic.

What I am trying to do is to generate a series of random numbers (in this case 7) and print them across the screen. (When I get the code to work I will be sending to a printer).  My code would look something like this.  This code is just an outline of what I am trying to do.

Dim Num(7) as integer
Dim n as byte
Dim l as byte

for n = 1 to 7
Num(n) = rnd(9) + 1
l = len(Num(n))
Print space$(9 - l); Num(n);
next

The semi-colons will cause everything in the loop to be printed on the same line.  I realize that I could set it up like this,,Print space$(9-l)+Str$(Num(1) +space$(9-a)+Str$(Num(2)+..........., but I am a bit lazy and I think the loop code looks a little better.

Maybe in the next version this will be added???

Mel

PaPi
Posts: 114
Joined: Wed May 16, 2007 11:55 am

Printing format

Post: # 380Post PaPi
Wed Jan 07, 2009 3:26 pm

Hi, so is better:


` another solution by PaPi
Dim Num(7) as integer
Dim n as byte
Dim l as byte
dim s as string
dim w as string
w=""
for n = 1 to 7
Num(n) = rnd(12) + 1   ` 12 for test
s=str$(Num(n))
l=len(s)
w=w+space$(9 - l)+s
next
print w
showmessage "end of program"


PaPi


Mel
Posts: 32
Joined: Mon Dec 22, 2008 1:19 pm

Printing format

Post: # 381Post Mel
Fri Jan 09, 2009 2:10 pm

Thanks PaPi, that was just what I needed to get me started.  I have expanded on your code some.  I will post below.  I am in the process of converting and old DOS program that will print a sheet of math problems for a student to practice on.  I have the program working with "FreeBasic" but I dont like the "front end".  I have looked at RapidQ, but I think I will use FnxBasic to write the porgram.

`MyCode (well yours & mine)

dim Num(7) as integer
dim dash(7) as string
dim n as byte
dim nn as byte
din l as byte
dim s as string
dim Line1 as string
dim Line2 as string
dim Line3 as string
dim minus as string `perhaps I could have thought of a better name here
dim op as string
dim row as byte

for row = 1 to 3

line1 = ""
line2 = ""
line3 = ""
op = "+" ` or "x" or "-"
minus = "-"

for n = 1 to 7
Num(n) = rnd(12) + 1
s = str$(Num(n))
l = len(s)
line1 = line1 + space$(10 - l) + s
next
print
print
print line1

for n = 1 to 7
dash(n) = ""
Num(n) = rnd(12) + 1
s = str$(Num(n))
l = len(s) + 1 `to allow for "op"
  for nn = 1 to l
  dash(n) = dash(n) + minus
  next
line2 = line2 + space$(10 - l) + op + s
line3 = line3 + space$(10 - l) + dash(n)
next
print line2
print line3
next row
showmessage "End Program" `I like this method to pause the program


Thanks again
Mel

PaPi
Posts: 114
Joined: Wed May 16, 2007 11:55 am

Printing format

Post: # 382Post PaPi
Fri Jan 09, 2009 3:30 pm

Mel, this is better, I think:

`MyCode (well yours & mine) & PaPi now

const CRLF=chr$(13)+chr$(10)   ` PaPi
dim sheet as string                          `PaPi
` 2 objects by PaPi:
object myform as form
     autosize=true
`      center=true
     object textwindow as richedit
           width=800 : height=600
           fontname="Courier"
           fontsize=12
           text=""
     end object `textwindow
end object `myform      

dim Num(7) as integer
dim dash(7) as string
dim n as byte
dim nn as byte
dim l as byte
dim s as string
dim Line1 as string
dim Line2 as string
dim Line3 as string
dim minus as string `perhaps I could have thought of a better name here
dim op as string
dim row as byte

sheet="" `PaPi
for row = 1 to 3

line1 = ""
line2 = ""
line3 = ""
op = "+" ` or "x" or "-"
minus = "-"

for n = 1 to 7
Num(n) = rnd(12) + 1
s = str$(Num(n))
l = len(s)
line1 = line1 + space$(10 - l) + s
next
`3 deleted lines by PaPi:
`print
`print
`print line1

for n = 1 to 7
dash(n) = ""
Num(n) = rnd(12) + 1
s = str$(Num(n))
l = len(s) + 1 `to allow for "op"
  for nn = 1 to l
  dash(n) = dash(n) + minus
  next
line2 = line2 + space$(10 - l) + op + s
line3 = line3 + space$(10 - l) + dash(n)
next
`2 deleted lines by PaPi:
`print line2
`print line3
sheet=sheet+CRLF+CRLF+line1+CRLF+line2+CRLF+line3+CRLF   `PaPi
next row

`You must here make as comment 1. OR  2  solution(s):.  !!!!

` first solution:  (...but better the 2nd method)
print sheet `PaPi       JUST printing with  only 1 print statement...  

`OR
`second solution:
textwindow.Text=sheet `PaPi


myform.ShowModal
`showmessage "End Program" `I like this method to pause the program

best regards
PaPi

Mel
Posts: 32
Joined: Mon Dec 22, 2008 1:19 pm

Printing format

Post: # 383Post Mel
Sun Jan 11, 2009 1:47 pm

PaPi, thank you again for your help.  I ran your latest code last night, but have not had time to fully understand the new objects that you included.  I will work with it for a few days and get back with you.  

Mel  

Quartermars
Posts: 11
Joined: Thu Jul 30, 2009 10:41 am

Printing format

Post: # 384Post Quartermars
Sat May 01, 2010 10:57 am

With regard to using the print statement.  The one issue perhaps I noticed, strings.  When I try to print a string from a Richedit or edit window it simply does not appear.  On the otherhand handlerichedit.text or edit.text that can be printed and of course sent to the print window.  Integers are also immediately put in the print window.  Any thoughts about this behavior.

Currently using the previous non-2010 version

PaPi
Posts: 114
Joined: Wed May 16, 2007 11:55 am

Printing format

Post: # 385Post PaPi
Sun May 02, 2010 6:51 am

Hi,
see you this:
-------begin program
`print_test by PaPi 2-5-2010
object myform as form
     autosize=true
     onactivate=main
     object textwindow as richedit
           text="123 456"
     end object `textwindow
end object `myform      
myform.ShowModal

sub main()
print textwindow.text
end sub ` main

---------end program

best regards PaPi

Quartermars
Posts: 11
Joined: Thu Jul 30, 2009 10:41 am

Printing format

Post: # 386Post Quartermars
Sun May 02, 2010 7:32 pm

Thank you Papi.  That is exactly what I noted as well.  Placing the string variable in the subroutine and letting it take the value of .text it does not display.  Not a major problem simply an inconvenience.

Post Reply