Question

I am trying to fill A$(X,X) with "."s in Commodore BASIC.

This is what I have so far....but I'm not really sure what to do concerning ASCII values and such. Any commentary?

INPUT A$
FOR I = 0 TO X = DIM A$(X,X)
A$(".",x)

I'm still EXTREMELY confused on PET BASIC's API... Any suggestions would be GREATLY appreciated.

Was it helpful?

Solution

My answers are based around a youth in front of a Commodore 64 and may not be completely correct for the PET series. But seeing as you haven't had any other answers yet I'll give it a bash.

In the first line of your code you are requesting a string from the user and storing it in A$. The dollar sign denotes the variable is a string. In the second line, you are redefining A$ as a two dimensional array. The dimensions are both X which hasn't been defined. I don't recall DIM having a return value but I could be wrong.

The function to get an ASCII value from a char is ASC() and to convert back you use CHR$() such:

10 NUMA = ASC("A"): REM NUMA now contains 65
20 CHARA$ = CHR$(NUMA): REM CHARA$ now contains "A"

Something you should know is that these functions use "PET ASCII" which is slightly different to ASCII. It never caused me any problems but its something to remember.

FOR loops always have a NEXT to end the block such:

10 FOR A = 1 TO 10
20 PRINT A: REM Displays series of numbers.
30 NEXT

I'm not entirely clear what you're trying to achieve but hopefully I have at least given you enough pieces to work it out. From what I understand, you need something like:

10 INPUT "Please enter a number:", X
20 DIM A$(X, X)
30 FOR I = 0 TO X
40 FOR J = 0 TO X
50 A$(I, J) = "."
60 NEXT
70 NEXT
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top