3

So, I'm struggling with a school project, I have a BASIC code, that is programmed on a PALM, I need to translate that to LabView, so first I'm translating the code to pseudocode, but I've never used BASIC before, so I'm having trouble with some lines.

So far, I know that: VariableName# = 15, means the type of the variable is double, and that it can be used on the right side of a number to convert it to double, like VariableName# = 15#

I also have on my code: OPEN "LPT1" FOR OUTPUT AS #1, opens serial port found on COM1, and names it "LPT1"

But a few lines later I found this, and I don't know what is it supposed to do:

225 FOR J = 1 TO 6000: PRINT #1, 40; : NEXT J
226 FOR ZZ = 1 TO S9: PRINT #1, 41; : NEXT ZZ

I know how FOR statements work, but what is it supposed to print?

PS: It's a solar positioning system.

edit: S9 is defined at the beggining of the program, it's 450.

Galarzaa90
  • 182
  • 3
  • 14

3 Answers3

2

I think what happens is it outputs 40 on that port 6000 times (see link for file output in BASIC) and then 41. Not sure what S9 is.

LPT1 is usually a parallel port, COM1 is a serial port, so there might something fishy going on.

From the same link:

PRINT #

The PRINT # command writes data to a file - the data is written to the file whose number follows "#". The command works like the PRINT command, except that the information is sent to the file instead of printed to the screen. The statement

Vlad
  • 18,195
  • 4
  • 41
  • 71
1

Lines 225 and 226 are printing to #1 which is mapped to line printer 1 (e.g. the parallel port and usually a centronics connectors)

OPEN "LPT1" FOR OUTPUT AS #1

Next, decimal 40 and 41 are ( and ) respectively. So it's formatting and printing those symbols to your printer.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • So it's basically printing `(` 6000 times, and then `)`450 times? Can't find a reason for that, it's a strange code – Galarzaa90 Nov 20 '13 at 02:54
  • I think so. It probably works to make a nicely formatted output on a very specific model of printer and paper size. – Elliott Frisch Nov 20 '13 at 02:56
  • I just found it on the solar tracker's manual, 40 makes the solar tracker's elevation go down, while 41 makes it go up, so it's sending the solar tracker to it's zero position. Thanks! – Galarzaa90 Nov 20 '13 at 12:51
  • It is printing the numbers 40 and 41, not "(" and ")". That would have been `PRINT #1, CHR$(40)` and `PRINT #1, CHR$(41)`. Most probably there is a space before each number. At least that's what Microsoft's early BASIC implementations do. If it's a positive number there is a space, if it's a negative number there is a minus at that place. – BlackJack Jun 25 '22 at 10:47
  • @BlackJack I'm confident (based on the check mark) that I was correct 9 years in that it's just sending control commands to the solar positioning system. Presence of LPT1 precludes **early** MS BASIC. But if you're into [that](https://github.com/mist64/msbasic). – Elliott Frisch Jun 25 '22 at 16:03
  • @ElliottFrisch It is sending control commands, but not as single characters but as three characters per `PRINT#`. The early MS BASICs did this — BASIC on the C64 was my first programming language — so did GW-BASIC which seems to be the dialect used here, given the shown `OPEN` statement and the fact that `#` denotes the type „double“. – BlackJack Jun 26 '22 at 07:21
1

All print #1 means is that it is going to output any information you do from that point on to #1, which in your case is "LPT1", Anything after this print will go to it until there is the phrase "Close #1"

As for S9, I believe that would be a variable that is set somewhere in the program. Try using CTRL-F in the code to find S9 somewhere else in the program. If you are using GW-Basic as the interpretter, type in 'save "NAME.txt",a' to get a text file. The only other thing I could assume it would translate to is for ZZ= 1 to (infinity) step 9, which is unrealistic but would make it count by 9 until it couldn't count any more.