MULTIPLICATON OF A FIELD IN A FILE WITH A CONSTANT

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

GMCM
Newbie
Posts: 1
Joined: Wed Sep 14, 2005 2:51 pm

MULTIPLICATON OF A FIELD IN A FILE WITH A CONSTANT

Post by GMCM »

I HAVE ONLY USED QUICK BASIC 4.5 IN VERY BASIC WAYS. MAINLY FOR DATA MANIPULATION. WHAT I NEED TO DO IS MULTIPLY A FIELD FROM A TEXT FILE WITH A CONSTANT. FOR EXAMPLE MID$(LINE$, 79, 8)TIMES .9 AND SHOW THAT RESULT IN MY OUTPUT FILE. I KNOW HOW TO SHOW THE RESULT IN MY OUTPUT FILE, IT'S JUST THE CALCULATION I AM HAVING PROBLEMS WITH. JUST NOT SURE HOW TO DO THIS. ALSO SOME RESULTS NEED TO HAVE 2 DECIMAL PLACES WHILE OTHERS NEED TO HAVE 4 DECIMAL PLACES.

THANKS.
GMCM
User avatar
Kyle
Veteran
Posts: 107
Joined: Thu Apr 14, 2005 2:41 pm

Post by Kyle »

Try these:

Image
User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} »

all i saw was the caps, and now im saying screw you, noobie hippie. pay attn in school.
Image
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo »

Hey guys, be nice to this new guy. He has a legitimate question.

GMCM:
1) Can the number you get from MID$(LINE$, 79, 8) have a decimal point? Just in case it does, do this:
DIM IPNUM AS DOUBLE
IPNUM=VAL(MID$(LINE$,79,8))

2) Just to be consistent, and have all your variables as DOUBLE do this also:
DIM CONPT9 AS DOUBLE
CONPT9=.9

3) Then, you multiply as follows:
DIM PRODUCT AS DOUBLE
PRODUCT=IPNUM*CONPT9

4) Note that all the DIM statements should actually appear at the top of the code.

5) The PRODUCT will contain as many decimal places as the numbers determine. If the IPNUM had 2 decimals, then 2 + 1 of the .9 can give you a maximum of 3 decimal places in the PRODUCT.

6) You can use PRINT #n USING to control how many maximum decimal places you need in your result to the output file. If for some reason you're not gonna use the PRINT USING, then you will need some extra code to normalize the result before writing it to the output file. Tell us what you're going to do.
*****
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re »

WE'RE SORRY WE THINK YOU'RE STUPID, BUT TYPING IN ALL CAPS KIND OF GIVES THAT IMPRESSION!
I have left this dump.
Seb McClouth

Post by Seb McClouth »

Z!re wrote:WE'RE SORRY WE THINK YOU'RE STUPID, BUT TYPING IN ALL CAPS KIND OF GIVES THAT IMPRESSION!
I'd like to add something to Z!re's post: (not intended for Z!re) WE'RE NOT DEAF!!!
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo »

Z!re and Seb,

Please be a little more tolerant. You're right, by today's standards typing in all caps, or solid caps, is now pass?.

But you should consider that many of us oldtimers used systems, and wrote programs, when there was only 6-bit BCD codes which did not have any lowercase characters. If you used BCD for many years, you got in the habit of typing with all caps even after 7 and 8 bit ASCII became of common usage. I myself still coded programs in all caps until about 1992, when I noticed that the other programmers on a project were using lowercase, and that this code looked much better.

The same was true for electronic mail systems before Internet email, like General Electric's Worldcom mail system in 1969-1970, and Citibank's Citimail system in 1973 through the 1980's. Messages were typed in all caps, and you got into the habit.

One more point. In Spanish-speaking countries, many people still type emails today in all caps. The reason for this is that by using all caps they don't have to worry about putting accents and other diacritical marks on the Spanish words, which is time-consuming and truly a pain in the neck. Using all caps becomes a habit, and most of these people also use them when writing emails in English.
*****
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re »

It's called progress.

You dont see me running around nude, do you? We "evolved" past that.. just like we evolved past ALL UPPERCASE TYPING.


EDIT:
moneo wrote:5) The PRODUCT will contain as many decimal places as the numbers determine. If the IPNUM had 2 decimals, then 2 + 1 of the .9 can give you a maximum of 3 decimal places in the PRODUCT.

Code: Select all

DIM a AS DOUBLE
DIM b AS DOUBLE
DIM c AS DOUBLE
a = 1.1
b = 2.7
c = a / b
PRINT c
:roll:
I have left this dump.
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

Z!re wrote:You dont see me running around nude, do you?
What was that last night then?!? :shock:
Seb McClouth

Post by Seb McClouth »

Nekrophidius wrote:
Z!re wrote:You dont see me running around nude, do you?
What was that last night then?!? :shock:
That's sumfin we call:
None of your business and not for your eyes
Caps or no caps that is the question... my answer: no caps... I'm tolerant but you would understand what's is like when ppl start swearing at you when your using a chatbox and you forget to turn of your Caps Lock...

grtz
Seb
Seb McClouth

Post by Seb McClouth »

Nekrophidius wrote:
Seb McClouth wrote:
Nekrophidius wrote: What was that last night then?!? :shock:
That's sumfin we call:
None of your business and not for your eyes
Err...I wasn't talking to you...so stfu, eh?
Eey mate... don't tell me to stfu ever... I don't like that sh... crap...

grtz
Seb McClouth

Post by Seb McClouth »

Last words to you: act your age... until that time... my kind regards to you...

grtz
Seb
User avatar
SebMcClouth
Veteran
Posts: 240
Joined: Fri Apr 29, 2005 2:20 am
Location: Inside the Matrix

Post by SebMcClouth »

Fine... have it your way...
I know why you're here. I know what you've been doing... why you hardly sleep, why you live alone, and why night after night, you sit by your computer...<br>
Unfortunately, no one can be told what Qbinux is. You have to see it for yourself.
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re »

:lol:

*blows sodacan (aka: nekrophidius) a kiss*
Don't be so mean to the new people :P

And about last night nek.. I was drunk ok.. shame on you!
I have left this dump.
User avatar
Zamaster
Veteran
Posts: 174
Joined: Wed Jun 15, 2005 1:51 pm

Post by Zamaster »

Thats the funniest picture ever! Where'd you get it?
C:\DOS
C:\DOS\RUN
RUN\DOS\RUN
User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} »

Seb McClouth wrote:Last words to you: act your age... until that time... my kind regards to you...

grtz
Seb
Ever heard Grow Up by Simple Plan?
Image
User avatar
Michael Calkins
Veteran
Posts: 76
Joined: Tue Apr 05, 2005 8:40 pm
Location: Floresville, Texas
Contact:

Post by Michael Calkins »

All caps does make text harder to read, but you would expect that MS-DOS programmers like us would be used to that. For example: file names in DOS are usually all caps, as are license agreements and some documentation for MS-DOS programs. All caps is no reason to flame, and absolutely not an indication of stupidity, anymore than all lowercase is.
Regards,
Michael
Long live MS-DOS! Long may it reign!! :-D
Bring on the Maulotaurs! oops...
I like to slay Disciples of D'Sparil...
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo »

Thanks for speaking up, Michael.
*****
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Post by Patz QuickBASIC Creations »

I use this when I need to make a number have 4 decimal places.

Code: Select all

NumberTesting$ = STR$(Number)
IF NOT INSTR(".", NumberTesting$) THEN NumberTesting$ = NumberTesting$ + ".0000"
While LEN(NumberTesting$-INSTR(".", NumberTesting$) < 4
Let NumberTesting$ = NumberTesting$ + "0"
WEND
Last edited by Patz QuickBASIC Creations on Sat Sep 17, 2005 12:48 pm, edited 1 time in total.
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo »

PQBC wrote:I use this when I need to make a number have 4 decimal places.

Code: Select all

NumberTesting$ = STR$(Number)
IF NOT INSTR(".", NumberTesting$) THEN NumberTesting$ = NumberTesting + ".0000"
While LEN(NumberTesting)-INSTR(".", NumberTesting$) < 4
Let NumberTesting$ = NumberTesting$ + "0"
WEND
Other than the fact that you left the dollar sign off of NumberTesting$ twice, and that the code is a little verbose, it looks like it should get the job done.
*****
If you are ahead of me, lead.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.
Post Reply