Qbasicnews.com

Full Version: Print 000 As Numerical Variable
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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
PRINT USING has formatting options for this I think.
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!
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.
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

CLEAR



RANDOMIZE TIMER



OPEN "Pick3" FOR INPUT AS #1

OPEN "000-499" FOR OUTPUT AS #2

OPEN "500-999" FOR OUTPUT AS #3



DO WHILE NOT EOF(1)



INPUT #1, N1

INPUT #1, N2

INPUT #1, N3



NN1 = N1 * 100 

NN2 = N2 * 10

NN3 = N3 * 1

N = NN1 + NN2 + NN3



'******************************
IF NN1 = 0 AND NN2 <> 0 THEN

  N$ = "0"

ELSEIF NN1 = 0 AND NN2 = 0 THEN

  N$ = "00"

ELSE

  N$ = "1"

END IF


'******************************

IF N < 500 THEN

 

  IF N$ = "1" THEN

   PRINT #2, N

  ELSE

   PRINT #2, N$; N

  END IF



END IF



IF N >= 500 THEN



  IF N$ = "1" THEN

   PRINT #3, N

  ELSE

   PRINT #3, N$; N

  END IF




END IF



LOOP

Thanks everyone! Stupid Microsoft won't let me print a dang zero!
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!
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
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!
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!
(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.

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!

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
Pages: 1 2