What is the pound/hash symbol for in BASIC? - basic

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.

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

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.

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.

Related

explain what is missing from 10print

10 PRINT CHR$(205.5+RND+(1));:GOTO 10
I seem to be the only person ever to not be able to do this. i have written all kinds of BASIC but I can't do anything with this. What am i missing?
I get "SYNTAX ERROR IN 10"
i can't get it to work And really, why would it? 205 is a memory address and so the value of 5 in and we have random number thing going but where does the pattern come from. Don't we need? "/" "\ ".
205.5 produces these/??? that doesn't make any sense. I must have an extreme misunderstanding of computers and BASIC that curiously doesn't prevent me from creating functioning programs.
I also program in C and I am still completely clueless. never seen anything like this work seems like there is a hidden line 1,2,3,4,5,6,7,8,9, that wasn't listed so I don't know what the rest of the code is???
I've tried on the 64mini and several emulators and they all give the same error.
Did I have a stroke and need to goto the hospital? maybe I can no longer discern what I see on the screen Lol.
10 PRINT CHR$(205.5+RND+(1));:GOTO 10
As pointed out by teapot418, you have a typo in your code. The exact code is:
10 PRINT CHR$(205.5+RND(1)); : GOTO 10
CHR$ creates the ASCII character for the given number. (What you wrote about reading from address is PEEK.)
CHR$(205) gives you the "\" and CHR$(206) the "/". The floating part of the number gets ignored. Because of the randomness, you get random sequences of CHR$(205) and CHR$(206) which creates the maze. The ; at the end of PRINT avoids a newline.

Syntax Err GET on an Apple II, AppleDOS 3.3 using Applesoft

I am using the AppleWin emulator, setup as an Apple IIe, Apple DOS 3.3 with Applesoft. My goal is to make a simple game.
This simple GET program works fine at the ] prompt (I am not sure, but I think it's called the monitor).
10 GET V$
20 PRINT V$
It prints the pressed key as expected
Then I start Applesoft using LOAD APPLESOFT. I tried writing the same simple program than at the ] prompt. But this time when I type the first line 10 GET V$ I get as output *** SYNTAX ERR.
I think it's not a supported feature, but in the ApplesoftII Basic Programming Reference Manual they list get a reserved keyword.
I could update to a higher version of Applesoft, then which version of Applebasic would support it?
I can also use another method of getting a key press without the user needing to press enter afterwards.
Applesoft on the Apple ][e (the first apple version to support lower-case at all) is case sensitive, and all the keywords are UPPERCASE only -- so get will not match the keyword (or anything) and will give you a syntax error.
Of course, if you're emulating an original Apple ][, there's no lower case at all, and lower case letters show up as flashing uppercase -- and still won't match a keyword.
After continuing to research my issue, I have found the location of memory for the keyboard buffer.
The keyboard buffer is -16384 and the way to reset that value of that address is to access -16368.
If the value in -16384 is larger than 128 then a key has been pressed.
So, I can use PEEK -16384 to read the value. To get an ASCII code you need to subtract 128 to that value.
Example code:
KEY= PEEK(-16384)
IF KEY>=128 THEN PRINT KEY-128
To tell the system you dealt with the key press and reset the value, you need to access the value in -16368. By using PEEK or POKE.
Example code:
POKE -16368,0
Or can also be PEEKed
PRINT PEEK -16368
if the error you are getting is *** SYNTAX ERR and not "?SYNTAX ERROR" then you are using integer basic and not applesoft basic. Try to switch to applesoft basic first by using FP

How to get rid of the error 'EOFError: EOF when using input() after having used sys.stdin.readlines() in a different function?

I am trying to replicate an Excel VBA macro to Python for the sake of learning a new programming language and I am stuck at a point which Google alone is not helping (I guess I do not even know what to look for). Could you please give it a try?
What I expect the program to do:
When running the user should be prompted with a few options and if the input is 0 then it should ask for a multi line input containing a full HTML source code from this website Steam Tools
After the input the user is expected to hit CTRL+D / CTLR+Z to confirm there is nothing else to add (I think the problem is here, maybe it is not able to "clear" the EOF error while using input() again?)
Then as an ouput the program should return the first 10 rows delimited by comma and create another input() to avoid the window to autoclose.
What the issue is:
When I run it from the desktop (double cliking the .py file) it autocloses withouth creating the last input().
When I run it from PyCharm it runs OK and the last input remains waiting for user action. However, it does dump an error like this:
File "D:/Stuff/_root/py/Steam/steam_cards_manager.py", line 51, in z_parse_tbody
input('\nCopy the program output and type Back:') EOFError: EOF when reading a line
Any feedback is appreciated as I don't know if I am doing things in an easy / effcient way.
I've upload my .py file and also a sample HTML to make it easier to replicate the issue, hope it helps.
https://github.com/brmenezewe/db
It turned out that I had to replace the CTRL+D shortcut by a "trigger" word that when sent via a single input() it breaks the While loop and joins the inputs previously received:
def z_input_lines():
lines = []
while True:
line = input()
if not line or line.lower() != "go":
lines.append(line)
else:
break
return "".join(lines)

VBA how to run a string as a line of code

Is there a way to convert a string into an executable line of code?
something like:
Dim Line1 as String
Line1 = "MsgBox (""Hello"")"
Execute Line1
resulting in the pop up box saying Hello.
What I'm doing is pulling lines out of a text file. I can pull lines that are the names of form controls and use them to perform actions on those form controls but I'd like to go one step further and execute lines.
I've seen claims that this would work:
Application.Run Line1
or make the variable an array and store it in element 1 e.g. and use
Application.Run Line1(1)
but it doesn't work for me.
Ok, while writing this I've also been experimenting. I found that
Eval (Line1)
will work when Line1 is a message box, but not when it is something like:
line1 = "DoCmd.OpenForm ""form1"""
Any tips would be appreciated.
Thanks
You can use,
Eval("DoCmd.OpenForm(""form1"")")
You have to make sure any functions you include use parentheses.
Further reference,
http://msdn.microsoft.com/en-us/library/office/aa172212(v=office.11).aspx
It's not exactly what I was asking, I ended up going a slightly different direction, but here's what I ended up doing and it would probably be easily altered to more closely match my question. I actually took lines of text from an external text file and inserted them into a line of code. What I was doing in this example was just hiding columns, the external text file was a list of column names. (figuring out how to output that was fun too)
Open "C:\UserList.txt" For Input As #TextFile
While Not EOF(TextFile)
Line Input #TextFile, TextLine
Screen.ActiveDatasheet.Controls(TextLine).ColumnHidden = True
Wend
Visual Basic is a compiler language, and as such does not support the ability to execute human-readable code while it is running. All code written in VBA must first be compiled BEFORE the program runs the first time.
However, SQL is an interpreter language, and can be handed code which it will execute line by line. You can also fetch contents for variables from other sources while the program runs, you just can't build a string while the program is running and then execute it in VBA directly.

Fortran77 automatically determine how many lines of text are at the top of a data file

An (old) instrument of mine is generating ASCII data files with text descriptions at the top of the file, before the data. But the number of lines of descriptive text varies from run to run. How can I get Fortran77 to determine this automatically?
Here is an example data file, below the line.
Line of explanatory text.
Notice the possible blank lines.
More text.
The number of lines is NOT the same every time.
1.0, 2.0
2.0, 4.0
3.0, 6.0
4.0, 8.0
[I found the answer myself. Posting here to help others. It is quite annoying having to wait 8 hours to answer my own question, but I understand why the rule exists. Stupid posers!]
A crude but effective solution, if your text never starts with a number (which is my case):
Assume the input file is named Data.dat.
integer NumTextLines
real X
open(8,"Data.dat")
NumTextLines=-1
50 NumTextLines=NumTextLines+1
read(8,*,err=50) X
close(8)
open(8,"Data.dat")
Every time the program tries to read a word from a text line into the real variable X, the read statement errors and program control goes back to line 50. If the read statement is successful, then you don't want to increment NumTextLines any more. Close the file and re-open it to start over from the beginning. But now you know NumTextLines. So you can read the text one line at a time, and either save it or skip it.
{Above method works on most of my files, but not all. Another way is to read each line into a character*500 variable (say, A), then test the ASCII value of the first element of the character array. But that gets complicated.}

Resources