13

I'm translating an excessively old GW-BASIC program into JavaScript, and I've come across a piece of syntax that has me stumped. Note (again): totally not my code, and the variable names are all insane, which is why I'm porting it in the first place.

1380 Z = 1
1390 RATIO = FCO2 /(1-FCO2-10^REFFO2)
1400 AA =(1 - 2*RATIO*(100 / MIXRATIO - 1))/(1 + 2*(100 / MIXRATIO - 1))
1410 PART = LOG(1 - AA)- LOG(100 / MIXRATIO - 1)
1420 FOR I = 1 TO - 1 STEP -2
1430 H = I
1440 W = T + H 
1450 GG = 62.110326# - .02144446#*W + 4.720326E-07*(W^ 2)+(- 4.5574288#)*(10^(- 12))*(W^ 3)- 7.343018200000001#*(10^(- 15))*(W^ 4) 
1460 KK = EXP(- GG /(R*(W + 273.18)))
1470 Q(Z)= KK 
1480 Z = Z + 1
1490 NEXT I
1500 NEWFO21 = LOG(10)*.5*(LOG(Q(1))+ PART):NEWFO22 = LOG(10)*.5*(LOG(Q(2))+ PART)
1510 DELEMFDELT =(FN EMF (TREF + 1,NEWFO21) - FN EMF (TREF - 1, NEWFO22))/2
1520 RETURN

The question mark is line 1470: Q(Z) = KK. Q is defined Q$ earlier in the program as a yes/no input variable, so it makes no sense for me to be putting a float in it. There's no Q() function defined in the program earlier, and I can't find a reference to a Q() function in GW-BASIC, either.

Any help?

Brian Webster
  • 30,033
  • 48
  • 152
  • 225
b. e. hollenbeck
  • 6,493
  • 7
  • 32
  • 47

2 Answers2

14

Q and Q$ are separate variables. Anything with $ is a string variable. Q(Z) is an array of numbers.

The 1 and 2 character names are common because in earlier versions of Basic, variable names were restricted to 2 characters max.

xpda
  • 15,585
  • 8
  • 51
  • 82
  • So far as I can tell, Q is never defined before it's used in this particular loop. Is that possible in BASIC? And thank you for the array syntax hint for BASIC. – b. e. hollenbeck Jan 24 '13 at 16:36
  • I think arrays were required to be declared in DIM, but not scalar variables. It's been a while and I don't remember for sure. – xpda Jan 24 '13 at 16:38
  • It's not really all that important - it was more not understanding that I was dealing with an array. Thanks, and I'll give you the answer in another 6 minutes. :) – b. e. hollenbeck Jan 24 '13 at 16:39
  • 1
    Hey, "excessively old" has implications! :-) – xpda Jan 24 '13 at 17:01
  • It doesn't have to be syntactically defined before it's used I think, only at the evaluation moment. It's possible that it's defined further down but that code at runtime is executed before this one (like a goto calling back or inside a subroutine). Does it make sense? – juancn Jan 31 '13 at 20:15
  • @b.e.hollenbeck UnDIMensioned arrays are implicitly DIMensioned to have an upper index of 10. So 11 elements unless the program used OPTION BASE 1. – BlackJack Jun 30 '22 at 06:27
4

As XPDA mentioned, any variable name suffixed with $ is a string. I wrote some GW-BASIC a few years ago, and thankfully I've still got a lot of the old documentation that was packaged with the compiler. I've uploaded a copy of the CHM I had archived, you'll probably find some useful information about it in there. http://www.mediafire.com/?3h9z133ok8wx1l9