MULTIPLICATON OF A FIELD IN A FILE WITH A CONSTANT
MULTIPLICATON OF A FIELD IN A FILE WITH A CONSTANT
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.
THANKS.
GMCM
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.
*****
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 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.
*****
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.
*****
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:
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
I have left this dump.
That's sumfin we call:Nekrophidius wrote:What was that last night then?!?Z!re wrote:You dont see me running around nude, do you?
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...None of your business and not for your eyes
grtz
Seb
- SebMcClouth
- Veteran
- Posts: 240
- Joined: Fri Apr 29, 2005 2:20 am
- Location: Inside the Matrix
- Michael Calkins
- Veteran
- Posts: 76
- Joined: Tue Apr 05, 2005 8:40 pm
- Location: Floresville, Texas
- Contact:
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
Regards,
Michael
Long live MS-DOS! Long may it reign!! :-D
Bring on the Maulotaurs! oops...
I like to slay Disciples of D'Sparil...
I like to slay Disciples of D'Sparil...
-
- Veteran
- Posts: 399
- Joined: Wed Mar 02, 2005 9:01 pm
- Location: Nashville, Tennessee
- Contact:
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.
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.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
*****
If you are ahead of me, lead.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.