Qbasicnews.com

QBasic => QB Discussion & Programming Help => Topic started by: jgr on March 22, 2004, 10:14:30 PM



Title: string and numeric variable questions
Post by: jgr on March 22, 2004, 10:14:30 PM
Can you or how can you let a string variable equal a numeric variable and vice versa.

for example

a$=num  Where num is inputed

or

num = a$  the numeric of a$


Title: string and numeric variable questions
Post by: whitetiger0990 on March 22, 2004, 10:17:57 PM
string$ = STR$(num)
num = VAL(string$)


there.
but the STR$ adds a space to the left (or right I forget) os if you want you need to LTRIM$ it.


Title: string and numeric variable questions
Post by: RST on March 22, 2004, 10:40:50 PM
STR$() Adds spaces to both the left *and* right. The one to the left holds the negative sign if needed.


Title: string and numeric variable questions
Post by: Moneo on March 23, 2004, 12:10:20 AM
RST, I don't recall the string of a value having a space on the right end. As a matter of fact I just ran a test, and there is definitely no space on the right end.
*****


Title: string and numeric variable questions
Post by: whitetiger0990 on March 23, 2004, 12:26:39 AM
yup Moneo is correct (((unless by some miraculous event i get killed and a temporal rift opens up that NO DUCT TAPE SHALL CLOSE!)))
Code:
PRINT "a" + STR$(1) + "a"
PRINT "a" + STR$(-1) + "a"


Title: string and numeric variable questions
Post by: R@dioman on March 23, 2004, 02:44:37 AM
jgr: If you want to get rid of that extra space at the beginning, use LTRIM$(variable$). This function returns the string with any spaces removed starting from the left(RTRIM$ does it from the right). To use it, do this:
variable$ = LTRIM$(variable$)


Title: string and numeric variable questions
Post by: 1000101 on March 23, 2004, 07:31:43 AM
Or, you can use FORMAT$ to control how the string is generated from the number.

ie:

Code:
PRINT FORMAT$(12345)
PRINT FORMAT$(12345, "##,###")


Title: string and numeric variable questions
Post by: jgr on March 23, 2004, 09:14:21 AM
Thanks fella's. I appreciate it, and I am sure there will be more questions to follow.


Title: string and numeric variable questions
Post by: adosorken on March 23, 2004, 12:01:17 PM
For QB, I usually just say "screwit" and use something like this:

string$ = LTRIM$(RTRIM$(STR$(num)))

Old habits die hard I suppose...but there was a time when spaces appeared on both sides. Maybe it's not with integers, maybe it's with singles and doubles? Anyone want to confirm?

For VB, we get to use something like this:

string$ = Trim(Str(num))

so much easier ;)


Title: string and numeric variable questions
Post by: oracle on March 23, 2004, 06:58:06 PM
A space appears when you're converting a positive number to a string, the space is the reserved space for the "-" sign that never appeared.

And you could do this:

Code:
DEF FNtrim(strng$) = LTRIM$(RTRIM$(strng$))


^^ not sure on the syntax of DEF FN but that's the basis of how I'd make a TRIM$ function...


Title: string and numeric variable questions
Post by: 1000101 on March 23, 2004, 07:05:02 PM
Quote from: "adosorken"
For QB, I usually just say "screwit" and use something like this:

string$ = LTRIM$(RTRIM$(STR$(num)))


I used to do that too, but I found FORMAT$ which does the exact same thing with no string parameter.

ie:

string$ = FORMAT$(num)


Title: string and numeric variable questions
Post by: oracle on March 23, 2004, 07:09:50 PM
^^^ I wrote that, not ado ;)

I've never heard of FORMAT$ before... if that works fine then use that ;)


Title: string and numeric variable questions
Post by: 1000101 on March 23, 2004, 07:15:52 PM
Odd, I just clicked the 'reply with quote' and stripped the rest of the message, I didn't touch the usename.


Title: string and numeric variable questions
Post by: adosorken on March 23, 2004, 07:38:42 PM
*checks the posts*

Oracle, I wrote that ya momo ;) you never even say "screwit" to my knowledge :D

I find that I never have use for string formatting...I guess it's different when you need to represent large numbers by triples though...


Title: string and numeric variable questions
Post by: jgr on March 23, 2004, 08:23:50 PM
I used

trim$=str$(carnumber)
trim$=ltrim$(trim$)
mid$(raceentry.finishorder,p)=trim$

print using "###"; val(mid$(raceentry.finshorder,p,3))


coming from programing business basic years back, qbasic is a lot more work.  In my opion, Using gosub's and goto's is ok as long as you keep everything structured and easy to follow.  Also there is good spagetti and very bad spagetti.


Title: string and numeric variable questions
Post by: whitetiger0990 on March 23, 2004, 10:31:42 PM
yup. that code works but i think it's better using 2 lines of code to do the same thing rather than 4

Code:
MID$(raceentry.finishorder, p) = LTRIM$(STR$(carnumber))
PRINT USING "###"; VAL(MID$(raceentry.finshorder, p, 3))

it just combines the three lines


and what you said about structured spagetti.... i think that too (Yummm spagetti)


Title: string and numeric variable questions
Post by: jgr on March 24, 2004, 12:25:53 AM
Yes, you are right.  I'm still trying to get used to all these different commands.


Title: string and numeric variable questions
Post by: Moneo on March 26, 2004, 01:36:38 AM
I did some work myself using Business BAsic for several machines including the BAsic IV and the NCR Tower. What I liked in particular was the I/O, lots more sophisticated than what QB has. The rest of the language is fair.
*****


Title: string and numeric variable questions
Post by: 1000101 on March 26, 2004, 04:19:26 AM
Nobody has caught on to what I said yet about FORMAT$

If you use FORMAT$(num) then you don't need to use LTRIM$ since there is no leading space.  Why make two function calls when you can make one.  Especially when QB is so slooooow about function calls.


Title: string and numeric variable questions
Post by: jgr on March 26, 2004, 11:06:00 AM
Quote from: "Moneo"
I did some work myself using Business BAsic for several machines including the BAsic IV and the NCR Tower. What I liked in particular was the I/O, lots more sophisticated than what QB has. The rest of the language is fair.
*****




I miss the direct files...this random stuff sucks


Title: string and numeric variable questions
Post by: jgr on March 26, 2004, 11:07:57 AM
Quote from: "1000101"
Nobody has caught on to what I said yet about FORMAT$

If you use FORMAT$(num) then you don't need to use LTRIM$ since there is no leading space.  Why make two function calls when you can make one.  Especially when QB is so slooooow about function calls.


Tried it but get subscript out of range error


Title: string and numeric variable questions
Post by: 1000101 on March 26, 2004, 02:28:55 PM
hrm, maybe QB doesn't have Format$?

Yup, just checked, wasn't introduced until PDS (QB7).

Sorry about that, but then, who still uses QB45 when the VBDOS compiler is a better one?  ;P


Title: string and numeric variable questions
Post by: Moneo on April 03, 2004, 11:53:46 PM
Quote from: "jgr"

I miss the direct files...this random stuff sucks

I totally agree.
*****


Title: string and numeric variable questions
Post by: Moneo on April 03, 2004, 11:59:26 PM
Quote from: "1000101"
hrm, maybe QB doesn't have Format$?
Yup, just checked, wasn't introduced until PDS (QB7).
Sorry about that, but then, who still uses QB45 when the VBDOS compiler is a better one?  ;P

I don't consider PDS(QB7) as part of the QB or QuickBASIC family. It has entirely too many different features. Including PDS feature in a conversation is like mentioning C++ or C# features in a C programming discussion.
*****


Title: string and numeric variable questions
Post by: TheBigBasicQ on April 04, 2004, 07:11:44 AM
Hey! QB7.1 was just an improvement over the previous versions of QB and they did add a lot of new features. So dont say that its not a part of QB family =P.


Title: string and numeric variable questions
Post by: na_th_an on April 04, 2004, 10:30:10 AM
It is not. The last QB version was QB 4.5

What you call (wrongly) "QB 7.1" is MS Basic Professional Development System 7.1 which included the Basic Compiler 7, following the BASCOM product line. It is a different product line.


Title: string and numeric variable questions
Post by: TheBigBasicQ on April 04, 2004, 10:35:45 AM
Whatever. All I know that I can make my QB programs using it and compile it into an .exe =P. So for me it belongs to the QB family  :wink:


Title: string and numeric variable questions
Post by: Moneo on April 04, 2004, 10:29:58 PM
Sorry, BIgBasicQ, but that's my opinion. My QuickBASIC came with 3 half-inch thick manuals and a few disketttes. When PDS came out, a software distributor here lent me the complete set of PDS which came in a very huge box full of manuals and I can't remember how many diskettes. I installed this behemoth language and tested it for about a week. Needless to say I didn't like it, so I returned the whole lot to the distributor and deleted it from my harddisk.

I didn't like PDS because:
* It's not portable. I can carry QuickBASIC 4.5 with the BC, linker, a library, etc. on a diskette, wherever I need to go.
* It made changes, not just enhancements to the Basic language.
* The much raved about ISAM, stinks. I used the real Indexed Sequential Access Method on IBM mainframes, so I know how it's supposed to work.
* I especially didn't like the IDE environment or whatever it was called. I don't need all that stuff which makes me feel like I'm in a prison --- reminds me of XTree which wants you to live inside their environment and do only those things which it envisions for you. I'm perfectly happy working from the command line where I have all the utilities I need, and if I don't, I write them.
* The bottom line: PDS does not enhance my programming capabilites at all.

But then again, that's my opinion --- you're entitled to yours.
*****


Title: string and numeric variable questions
Post by: 1000101 on April 04, 2004, 10:50:19 PM
Quote from: "Moneo"
I don't consider PDS(QB7) as part of the QB or QuickBASIC family. It has entirely too many different features. Including PDS feature in a conversation is like mentioning C++ or C# features in a C programming discussion.
*****


Whether you 'consider' it to be or not, it is.

Also, comparing PDS and QB to C++ and C is stupid.

It's more like comparing MSC 4.0 to MSC 6.0, yes, there are lots of improvements and chages, but aside from a couple things the programmer has to worry about, they are mostly internal.


Title: string and numeric variable questions
Post by: TheBigBasicQ on April 05, 2004, 07:11:42 AM
Thats exactly what I've been trying to tell everyone. BASIC is a language while 4.5 and PDS(7.1) provide different compilers/libraries. So they are different versions of the *same* software.

BTW nath i dunno why you keep saying QB 7.1 is not a part of the Qbasic line of products but this is what I see at the bottom of the IDE:

Quote from: "Qb 7.1"
Microsoft (R) QuickBASIC Extended v7.1 (C) Copyright Microsoft Corp, 1982-1990


Quote from: "Qb 4.5"
Microsoft (R) QuickBASIC 4.50 (C) Copyright Microsoft Corporation, 1985-1988


Title: string and numeric variable questions
Post by: na_th_an on April 05, 2004, 11:17:20 AM
Because it is not: QBX is the IDE for the suite. The compiler is called BC7, which comes after BC6 which comes after BASCOM v.5.

MS abandoned the BASCOM product line and focused more in the new QB product line (Quick stands for the IDE, no more hassle (:lol: he he) with the command line). QB4.5 was downgraded to Qbasic 1.0 (slowed down and without the compiler), and MS continued on the BASCOM product line in 1990 releasing BC 6.

Just a matter of nomenclature :D In fact, QB, PDS and VBDOS use the same BASIC dialect, just like VB.


Title: string and numeric variable questions
Post by: TheBigBasicQ on April 05, 2004, 04:08:25 PM
Ok, it may be a different line of product but the dialect is the same. Thats what I am trying to tell ya, it doesnt matter to me which line of product it is so long as I can make QB programs using it =P.


Title: string and numeric variable questions
Post by: relsoft on April 06, 2004, 08:30:15 AM
Hohum.....  Its the coder guys, not the version. :*)

Whatever works.


Title: string and numeric variable questions
Post by: TheBigBasicQ on April 06, 2004, 02:14:46 PM
Its more like Coder is 80% while the Language is 20%


Title: string and numeric variable questions
Post by: Moneo on April 09, 2004, 09:53:34 PM
Nathan, I totally agree with you, and thanks for the documented history.

BigBasicQ, your statement of 80% coder and 20% language is true. You can say that about almost any language. However, we were discussing whether PDS belongs to the QB family. If your solutions using PDS work for you, that's great. You can't argue with success.
*****


Title: string and numeric variable questions
Post by: na_th_an on April 09, 2004, 11:17:11 PM
Y'know, I had to do some research to build my web. That has a drawback: I've became over-reactive about MS Basic version misconceptions ;)


Title: string and numeric variable questions
Post by: TheBigBasicQ on April 10, 2004, 04:13:21 AM
Stop with the petty bickering already  :lol: