Print 000 As Numerical Variable - Printable Version +- Qbasicnews.com (http://qbasicnews.com/newforum) +-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html) +--- Forum: QB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-11.html) +--- Thread: Print 000 As Numerical Variable (/thread-10223.html) Pages:
1
2
|
Print 000 As Numerical Variable - Licentia - 07-30-2009 Hello! I know that I can print 001 as a "$tring Variable." But I want to print 001 as a "Numerical Variable." Any suggestions how I might do this? Licentia Re: Print 000 As Numerical Variable - Ninkazu - 07-30-2009 PRINT USING has formatting options for this I think. Re: Print 000 As Numerical Variable - Licentia - 07-31-2009 I cannot believe how ridiculously difficult it is to print 001 in a text file!!! How about this then, is there a way to take 3 numerical variables like 0 and 0 and 1 and combine them into one variable like so: 001 ? I tried switching my numeric variable to a string variable before printing but it still loses the zero(s) off the front. I tried switching to a decimal point number and that cuts the zero(s) off the back. I want to input Pick3 combinations from a text file. I can't do line input because that is only for strings. So I have to take each number one at a time N1;N2;N3 then try to convert them to a single integer. I thought I had done this successfully as follows: N = N1*100+N2*10+N3*1 But that dang zero keeps messing me up! Re: Print 000 As Numerical Variable - Clippy - 07-31-2009 The KEYWORD you used is TEXT. Text = String not numbers. Try this:   number$ = LTRIM$(STR$(num%)) ' convert number for string display   zeros$ = "00"   zeros$ = MID$(zeros$, 1, 3 - LEN(number$)) 'zero place values are allowed by MID$   result$ = zeros$ + number$ This will add zero's to the left up until 100. You can then use PRINT # or WRITE # to place it in a file. You can convert it back to a numerical value with VAL(result$), but num% already holds that value anyhow. PRINT USING cannot format 0's ahead of numbers either. Re: Print 000 As Numerical Variable - Licentia - 07-31-2009 I pasted the code above into my program but the output was the same. Perhaps I needed to modify the code to suit my program, I'm not sure as I haven't used code like that before. But your response did get me to thinking and I came up with the code inbetween the '******. My output is ugly with spaces between the string and the numeric variables but that's fine so long as it works. Output: 0 45 0 99 0 41 139 132 298 317 00 0 00 3 Code: CLS Thanks everyone! Stupid Microsoft won't let me print a dang zero! Re: Print 000 As Numerical Variable - Clippy - 07-31-2009 When you want to print consecutive numbers, you need to change them to a string value and edit it. number$ = STR$(num%) 'eliminates a number's end space To get rid of the leading space for the number's sign ( a space when positive), you have to use LTRIM$(number$) to get rid of that space. This is true when using PRINT or PRINT # or WRITE #. That is why there is a space in your returns. Number values will ALWAYS add that space! WRITE # will send a string value with quotation marks. PRINT # will send the value without quotation marks to a text file. INPUT # can read PRINT # text as numerical or string values! Re: Print 000 As Numerical Variable - Moneo - 07-31-2009 Print a positive number from 0 to 999, with leading zeros. ' x is a positive nuimber from 0 to 999. print right$("00"+ltrim$(str$(x)),3) Regards..... Moneo Re: Print 000 As Numerical Variable - Licentia - 08-03-2009 LOL! I don't even need to print N. I can just print N1;N2;N3. What was I thinking? I just need to compare N as an integer, there is no necessity of printing N when N1;N2;N3 are available. Sorry to waste everyone's time and thanks for trying to help! Re: Print 000 As Numerical Variable - Clippy - 08-03-2009 GIRL YOU JUST DON'T GET IT! NOW YOU ACT LIKE WE WERE CLUELESS? STICK TO KNITTING! I TOLD YOU THAT IN MY FIRST POST! Geeesh....learn how to read too while you're at it! Re: Print 000 As Numerical Variable - Moneo - 08-03-2009 (08-03-2009, 12:31 AM)Licentia link Wrote: LOL! I don't even need to print N. I can just print N1;N2;N3. I tried workng with N1, N2, and N3, and it's actually more code because you need to convert each of these three variable to a string and do a ltrim$ on each to get rid of the leading space on each of the string variables. Regards..... Moneo |