Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dBase Code translation required 2

Status
Not open for further replies.

ox161xs

Programmer
Mar 22, 2005
3
0
0
GB
Hi,
I am re-writing a general program (coded in dBase for DOS)& would appreciate explanation of following two code segments please.

First segment .......

381 DO WHILE NUMB6 <= GEARQTY + 10
382 GEARNUM2 = "G" + STR(NUM6,2)
383 DN3 = &GEARNUM2
384 NUM6 = NUM6 + 1

Q. What does &GEARNUM2 signify, GEARNUM2 being an integer?

Second segment .......

386 * xxxxxxxxxx checks if already used xxxxxxxxxxxxx
387 *
388 IF GEARNUM2 <> USED1 .AND. GEARNUM2 <> USED2 .AND. ; GEARNUM2 <> USED3
389 *
390 * xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Q. What does line 388 achieve? I can't identify the result of this bit of (Boolean?) code

Any help gratefully received.

Kind Regards, Barry
 
First:

DN3 = &GEARNUM2
This will create or update a string variable DN3 and set it's value to the contents of GEARNUM2. The & is the "macro" operator which returns the the value of a variable, and in this case I believe is unnecessary. GEARNUM2 has been created as a string variable with the value beginning with "G" followed by the value of NUM6 converted to a string, with 2 decimal places. Note that it appears to me there is a typo in your code, in that the DO WHILE loop references variable NUMB6, while the STR() function applies to NUM6 (no "B"). This may be correct if they are in fact two different variables.

Second:
388 IF GEARNUM2 <> USED1 .AND. GEARNUM2 <> USED2 .AND. ; GEARNUM2 <> USED3
This will cause the statements between 388 and it's associated ENDIF statement to be executed if GEARNUM2 is not equal to the variables USED1, USED2, or USED3.

hth
Dennis
 
One correction to my post. The "&" operator is referred to as the macro substitution, not just macro.

dennis
 
Dennis, many thanks - all becomes crystal clear now.

It was just those missing hints!! As you so rightly say, a typo crept into line 381 which should read ... NUM6 ... and not NUMB6

The "&" in line 383 I found misleading..... and what threw me in line 388 was the semi-colon, which I now guess reads as "statement continued on next line".


Many, many thanks again. I am ready to rewrite this code now thanks to your very prompt input.

Kind Regards, Barry
 
Correct on the semi-colon. It is the statement line continuation character.

dennis
 
Also, please note that if ever num6 is less than 10, then the macrosubstitution will fail. So I presume it is never below that value.

382 GEARNUM2 = "G" + STR(NUM6,2)
383 DN3 = &GEARNUM2

Say, for example that num6=9. Then line 382 stores "G 9" to gearnum2. Line 383 then tries to put the contents[/] of the variable named in gearnum2 into dn3. But "G 9" is not a valid variable name and wil error. That's why I say num6 is always between 10 and 99.

dbMark
 
Note Mark's post offers subtle (he's too nice) clarification on an important point that was unclear/misstated in my post. That is, that the macro substitution returns the contents of a variable and that value gets used in the program statement in which it occurs. For example :

NUM6 = 56 && Set the value of variable NUM6 to 56
GEARNUM2 = "G" + STR(NUM6,2) && The value of GEARNUM2 is now a string "G56"
DN3 = &GEARNUM2 && The value of DN3 is set to the value contained in a variable named G56.

Also the STR(NUM6,2) returns the value character value of NUM6 with a length of 2, not 2 decimal places. A
STR(NUM6,5,2) would return length of 5 with 2 decimal places.

That's what I get for trying to do too many things at once. Sorry if I created some confusion.

dennis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top