Unknown GW-BASIC function/syntax: Q(var) = var
Asked Answered
B

2

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?

Bedraggled answered 24/1, 2013 at 16:31 Comment(2)
+1 for reminding me of GW-BASIC, it has been YEARSCherice
I have to say, this particular project has been a blast to port.Bedraggled
O
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.

Overt answered 24/1, 2013 at 16:33 Comment(6)
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.Bedraggled
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.Overt
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. :)Bedraggled
Hey, "excessively old" has implications! :-)Overt
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?Hudis
@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.Downswing
T
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

Taliesin answered 26/1, 2013 at 1:58 Comment(1)
Why you had to write gwbasic a few years back ,who would want a program written in gwbasic ? ,I'm just curious :)Gym

© 2022 - 2024 — McMap. All rights reserved.