• Updated 2023-07-12: Hello, Guest! Welcome back, and be sure to check out this follow-up post about our outage a week or so ago.

Apple IIc programming confusion

Apostrophe

Well-known member
Hi,

If you haven't already seen my post in Conquests, one of the power supplies I ordered for my Apple IIc has just arrived, and I played with the IIc for about two hours. It works great! And I've been getting better at programming it.

But there's one thing I can't get it to do. I've mastered Graphics mode; I successfully plotted a smiley face (and altered its colors), I successfully got it to run number/variable related programs I write for it, I have more or less mastered commands like HOME, RUN, LIST, PRINT, INPUT, NEW, END, IF...THEN, GOTO, etc. But I can't get it to accept text answers.

If I write a program telling it to ask me the year, it works fine. For instance, here's the program I wrote, along with the result:

new

10 home

20 input "What year is it?";a

30 if a="2009" then goto 50

40 if a<>"2009" then goto 10

50 print "Correct!"

60 end

run

What year is it? 2009

Correct!

But I can't get it to do the same with words. For instance, I want it to ask for the state I live in (Ohio) and then ask for the month (February). But the result isn't quite as favorable. I've tried various combinations of string variable techniques as well, to no avail. Below is my program, along with the result:

new

10 home

20 input "What state do you live in?";a

30 if a="Ohio" then goto 50

40 if a<>"Ohio" then goto 10

50 input "Correct! Type 'next' for the next question.";b

60 if b="next" then goto 70

70 home

80 input "What month is this?";c

90 if c="February" then goto 110

100 if c<>"February" then goto 70

110 print "Correct! Thus concludes this program."

120 end

run

What state do you live in?Ohio

?REENTER

What state do you live in?OHIO

?REENTER

What state do you live in?"Ohio"

?REENTER

What state do you live in?Ohio$

?REENTER

What state do you live in?"Ohio$"

As you can see, I've tried various combinations of Ohio, all with no results. And sometimes, it does this:

...

...

110 print "Correct! Thus concludes this program."

120 end

run

?SYNTAX ERROR IN 3

And so I'd type LIST 30, but the line looks just as I typed it, with no obvious mistakes.

So then I'd try to skip it. I'd type RUN 70, and it asks the question at 70, but never accepts my answer as the correct one, saying ?REENTER What month is this? over and over and over again, no matter what I type in.

Is there something I'm missing? Anything I'm not doing quite right?

-Apostrophe

 

david__schmidt

Well-known member
You need all string variables.

Code:
10 home
20 input "What state do you live in?";a$
30 if a$="Ohio" then goto 50
40 if a$<>"Ohio" then goto 10
50 input "Correct! Type 'next' for the next question.";b$
60 if b$="next" then goto 70
70 home
80 input "What month is this?";c$
90 if c$="February" then goto 110
100 if c$<>"February" then goto 70
110 print "Correct! Thus concludes this program."
120 end
You'll probably be happier with ALL CAPS, too. :)

 

Apostrophe

Well-known member
Thanks David--as I told wally, I've already tried string variables, but maybe I didn't do it right, or missed a few keys, etc.

When I turn the IIc on again tomorrow I'll try entering the revised code you provided, David. I'll let you know how it turns out. :)

-Apostrophe

 

wally

Well-known member
Just a guess...you may have to declare a$ first specifying a non zero maximum string length in bytes.

Try

Dim A$(64), B$(64), C$(255)

at the start of the program and see if that gives you some string variables of non zero length to play with.

 

wally

Well-known member
My prior post may go too far and create arrays of string variables, so also try the simpler

DIM A$(1), B$(1), C$(1) or even simpler DIM A$, B$, C$

I saw somewhere that Applesoft Basic went to dynamic garbage collection for variable length strings (and if so length was automatic up to some large number of bytes), but have yet to find a reference manual or program example clarifying declaration requirements and rules. In Atari Basic the DIM A$(64) was needed and just created a single string variable holding up to 64 bytes as an example.

Further edited post:

If on your IIc you are using Applesoft BASIC

http://apple2.info/wiki/index.php?title=Applesoft_BASIC#String_expressions_and_Assignments

has some reference info. I get the impression that string variables are dynamically declared and only string arrays need declarations, and that the example by david__schmidt should work without a DIM statement (but what do I know!). Upperlower case may create some issues too.

http://knowledgerush.com/kr/encyclopedia/Applesoft_BASIC_programming_language/

has some historical info on the shift from Integer Basic to Applesoft Basic.

 

luddite

Host of RetroChallenge
DIM A$(1), B$(1), C$(1) or even simpler DIM A$, B$, C$
Neither is necessary... the first will create arrays and the second AFAIK won't do anything. Simply changing the variable to string variables works just fine

Code:
 10  HOME
20  INPUT "What state do you live in?";A$
30  IF A$ = "Ohio" THEN  GOTO 50
40  IF A$ <  > "Ohio" THEN  GOTO 10
50  INPUT "Correct! Type 'next' for the next question.";B$
60  IF B$ = "next" THEN  GOTO 70
70  HOME
80  INPUT "What month is this?";C$
90  IF C$ = "February" THEN  GOTO 110
100  IF C$ <  > "February" THEN  GOTO 70
110  PRINT "Correct! Thus concludes this program."
120  END
Edit: If I was paying attention I might have noticed that Dave Schmidt already corrected the program... so much work for nothing! ;-)

 

wally

Well-known member
Not having an Apple IIc handy but wanting the experience I went to http://www.calormen.com/Applesoft/index.htm and tried out the Applesoft Basic simulator that runs in Javascript. As others had said, no pre dimensioning/declaration of string variables necessary. Unless I am operating this simulator incorrectly, you can input statements including strings to be compared in mixed upper lower case, but the keyboard input received in input statements is upshifted to all caps. So your tests of any sting loaded from an input statement should read if a$ = "STRINGINALLCAPS" otherwise the comparison fails. You can still PRINT "UPPERlowercase" and that displays both cases. Acts like my keyboard is stuck on caps for input statements only.

10 home

20 input "What state do you live in?";a$

30 if a$="OHIO" then goto 50

40 goto 10

50 input "Correct! Type 'next' for the next question.";b$

60 if b$="NEXT" then goto 70

62 home

63 input "Type 'next' for the next question.";b$

65 goto 60

70 home

80 input "What month is this?";c$

90 if c$="FEBRUARY" then goto 110

100 goto 70

110 print "Correct! Thus concludes this program."

115 stop

120 end

 

Dog Cow

Well-known member
new

10 home

20 input "What state do you live in?";a

30 if a="Ohio" then goto 50

40 if a<>"Ohio" then goto 10

50 input "Correct! Type 'next' for the next question.";b

60 if b="next" then goto 70

70 home

80 input "What month is this?";c

90 if c="February" then goto 110

100 if c<>"February" then goto 70

110 print "Correct! Thus concludes this program."

120 end
Corrected program:

Code:
10 HOME
20 PRINT "WHAT STATE DO YOU LIVE IN" : INPUT STATE$
30 IF STATE$ = "OHIO" THEN 50 
40 GOTO 10
50 PRINT "CORRECT! TYPE NEXT TO CONTINUE" : INPUT B$
60 IF B$ = "NEXT" THEN PRINT "OK"
70 HOME : PRINT "WHAT MONTH IS IT TODAY" : INPUT MONTH$
80 IF MONTH$ = "FEB" THEN 90 
85 GOTO 60
90 PRINT "CORRECT! THIS IS THE END."
100 END
This has been tested on that simulator and works OK. Note: the syntax "THEN GOTO 100" can be shortened to "THEN 100"

 

luddite

Host of RetroChallenge
On the original ][ and ][+ keyboard input was all upper case on a stock configuration. The IIe and IIC, however, have a working shift key.

 

Apostrophe

Well-known member
Hi,

Okay, l added the string variables, and it works perfectly! I guess I just made a few errors beforehand...

Just one more question, though...those two buttons labeled 'keyboard' and '80/40'...what do they do? I didn't press them because I don't want to screw anything up.

I believe that keyboard simply switches the layout to Dvorak and back again to Qwerty--is this true? And, I'd hazard a guess that the 80/40 key switches the resolution in GR mode to 80X80 and back again to 40X40.

How far off am I?

-Apostrophe

 

luddite

Host of RetroChallenge
I believe that keyboard simply switches the layout to Dvorak and back again to Qwerty--is this true? And, I'd hazard a guess that the 80/40 key switches the resolution in GR mode to 80X80 and back again to 40X40.How far off am I?
Not too far... you're right about the keyboard switch, but the 80/40 switch is for text not graphics. Play with them all you want, they won't hurt anything.

 

Apostrophe

Well-known member
The more I use my Apple IIc, the better I get at programming it. But there's one thing that I still don't understand. I still haven't figured out what the 80/40 key does. I know how to use the Keyboard key and what it does, but not so with the 80/40 key. I press it, type a bit, and nothing else happens.

What exactly does that 80/40 key do?

-Apostrophe

 

luddite

Host of RetroChallenge
What exactly does that 80/40 key do?
According to wikipedia "an “80/40”-column switch for (specially-written) software to detect which text video mode to start up in"

Since the IIc is the only Apple II to have the 80/40 switch, I'd guess most programs wouldn't bother with it... especially since 80 and 40 column text modes can be accessed easily via software.

 

arfink

Well-known member
I do know AppleWorks does pay attention to that switch. You could conceivably use the switch for other things, as it just flags a certain address in memory. I doesn't actually do anything but that.

 
Top