Printing format
Printing format
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
Printing format
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
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
Printing format
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
` 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
Printing format
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
`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 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
Printing format
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
`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 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
Printing format
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
Mel
-
- Posts: 11
- Joined: Thu Jul 30, 2009 10:41 am
Printing format
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
Currently using the previous non-2010 version
Printing format
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
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
-
- Posts: 11
- Joined: Thu Jul 30, 2009 10:41 am
Printing format
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.