cobbBR
cobbBR

Reputation: 41

Decipher BASIC script

I've inherited a BASIC script, and I'm trying to rewrite it into Python. I don't know BASIC, or even which version of BASIC this is. Is it Visual Basic? Please help me translate this block of code.

'County Number, District Number, District Name 
j = 0
OPEN "" + year.base$ + "dist.csv" FOR INPUT AS #1
INPUT #1, a0$, a1$, a2$, a3$, a4$, a5$, a6$, a7$  
DO WHILE NOT EOF(1)  
j = j + 1  
  INPUT #1, a0$, a1$, a2$, a3$, a4$, a5$, a6$, a7$  
  conumbind(j) = VAL(a0$)  
  distnumbind(j) = VAL(a1$)  
  distnameind$(j) = a2$  
  rate2(j) = VAL(a3$)  
  rate34(j) = rate2(j) * 2  
LOOP  
CLOSE #1  
iTotal2 = j 

Upvotes: 2

Views: 189

Answers (2)

S. Ahn
S. Ahn

Reputation: 663

Initialize counter.

j = 0

Open file for reading.

OPEN "" + year.base$ + "dist.csv" FOR INPUT AS #1

Read in the first line into 8 variables. These aren't used. I assume they are the header.

INPUT #1, a0$, a1$, a2$, a3$, a4$, a5$, a6$, a7$  

Iterate through the rest of the file.

DO WHILE NOT EOF(1)  

Increment the counter.

  j = j + 1  

Read the next line of the file into 8 variables.

  INPUT #1, a0$, a1$, a2$, a3$, a4$, a5$, a6$, a7$  

Assign the some of the fields to array elements (the VAL function converts to a numeric value).

  conumbind(j) = VAL(a0$)  
  distnumbind(j) = VAL(a1$)
  distnameind$(j) = a2$  
  rate2(j) = VAL(a3$)  
  rate34(j) = rate2(j) * 2  

Finish the loop.

LOOP  

Close the input file.

CLOSE #1  

Save the record count.

iTotal2 = j 

Upvotes: 4

Baltico
Baltico

Reputation: 493

Hello this is QBASIC a DOS based language. QBasic on Wikipedia What this code does is to open a text file, in this case a comma separated values files. Each INPUT #1 sentence will fetch one line of the file and assign the values to the string variables (the ones that end in $ character are string variables). Then it will fill some unidimensional arrays with those values. iTotal2 will be the number of records in the file. The code does practically nothing, since once the arrays are filled, they are not used.

Upvotes: 3

Related Questions