Action! › and› BBS Express! PRO› Tutorial›› by› Thomas M. Johnson ››› Available from ›› Villa Video's Bargain Cellar › (414) 265-5149 › ExpressNet Node X11 ››Action! is copyright of ACS, OSS, ICD.›BBS Express! PRO is copyright Orion›Micro Systems.› ›This tutorial is copyright Thomas M.›Johnson.››This tutorial can be distributed under›the following conditions:› 1) It is free.› 2) All of the above› information is intact.››--------------------------------------››An ARRAY is a group of numbers that›are the same type. Whether that means›they are a BYTE, INT or CARD.››A string is something like this:›"Hello, how are you today?"››So why are these 2 concepts begin ›presented in the same lesson? Because›to a computer, they are the same›thing. A string is just an ARRAY of›BYTE values. But since a BYTE and›a CHAR are EXACTLY the same thing,›we will use CHAR just so we know›that we are using that ARRAY as a ›string instead of just holding›numbers. There is one small›difference between strings and›BYTE ARRAYs and we cover that in a›little bit.››An ARRAY is a indexed group of›numbers. Lets say you have 4 people›playing a game and you want to keep›track of all their scores. You›could use 4 different variables›like this:››PROC print_score()›› BYTE score1,› score2,› score3,› score4›› PrintF("Score 1: %U",score1)› PrintF("Score 2: %U",score2)› PrintF("Score 3: %U",score3)› PrintF("Score 4: %U",score4)›RETURN››Everytime you needed to do something›with a persons score, you have to›figure out who is playing and then›use their particular score variable.››A better way is to use an ARRAY.››PROC print_score()›› BYTE ARRAY score(5)› BYTE player› › FOR player=1 TO 4› DO› PrintF("Score %U: %U",player,score(player))› OD›RETURN››Now anytime you need a persons score,›you just place that player's number›in score( ) and it is given to you.››The declaration of an ARRAY is››type ARRAY name(dimension)››type can be any of the fundamental›types; BYTE (CHAR), INT or CARD.›The dimension is how big the ARRAY is›going to be. In Action!, ARRAYs go›from 0 to dimension-1. That is why›we declared score(5), now the player›numbers go from 0 to 4. We could have›used score(4) but then the numbers›would go from 0 to 3 and humans›usually don't think that way.››The type has nothing to do with how›big an ARRAY can be. The type is›what the ARRAY will hold. For›example, you can have this:››BYTE ARRAY total_pay(5000)››Now you can have 5000 employees but›each can only have a pay of 0 to 255.›(Sounds familiar huh?)››total_pay(1) = 210›total_pay(2) = 170›total_pay(3) = 250›total_pay(4) = 100› .› .› .›total_pay(4999) = 30››If you want to input a number into›an array you could use:››PROC main()›› CARD ARRAY lottery(10)› BYTE i›› FOR i=1 TO 9› DO› lottery(i)=InputB()› OD›RETURN›››You use ARRAY just like any normal›variable, but you must subscript›"(i) or something" each time you›use it.›››So, what is the difference between a›ARRAY of BYTEs and a string? The›zeroth (0th) BYTE of a string holds›its length. For this reason, you›can't do a direct assignment, the›compiler won't let you. Here's what ›I mean:›› CHAR ARRAY prompt(30)›› prompt="What is your guess? "››That is illegal. Instead, Action!›provides you with a ton of PROCs and›FUNCs to make working with strings›easy.››To assign a string variable some›text, you use:››SCopy(prompt,"What is your guess? ")››This just copies what ever is second›into what ever is first. So you can›also use:››SCopy(again,prompt)››This will make the variable "again"›equal to the same text as the variable›"prompt". This is assuming that›"again" was dimensioned to the same›size or bigger than "prompt".››Printing strings is easy, we just›use the normal Print() and PrintE()›we have always been using. Just now,›you use the string name inplace of›the text. ››PrintE(prompt)››Inputing strings is a little different›that inputing normal variables.›Here we use:››InputS(prompt)››Notice that it is a PROC and not a ›FUNC.››Action! also has PROCs that take›part of one string and copy them›into another (substrings) and taking›a string and copying into part of›another (appending or inserting).›Look in you Action! manual on how›to use these PROCs.››Another thing you can't do in Action!›is compare string like this:››IF prompt=again THEN ...››You must use a built in FUNC that›does this for you.››SCompare(prompt, again)››This FUNC returns an INT value. It›return a number <0 if prompt is less›than again. It return 0 if they›are equal. And it returns a number›>0 if prompt is greater than again.››This is great for alphabetization. In›fact, APROG.902 does a little›alphabetizing.››Before I let you go I have to tell›you a little somthing I left off of›ATUTOR.003.››In an IF statement, if the conditional›is not true you can have an ELSE›statment.››IF a>b THEN› PrintE("A is less than B")›ELSE› PrintE("A is greater than or")› PrintE("equal to B")›FI››Action! will execute the second part›only if the first is not true. You›can also have multiple IFs.››IF a>b THEN› PrintE("A is less than B")›ELSE› IF a=b THEN› PrintE("A is equal to B")› ELSE› PrintE("A is greater than or")› FI›FI›››In fact, this happens so often that›we have a special statement for it:›the ELSEIF. The next example is›the exact same thing as the above one.››IF a>b THEN› PrintE("A is less than B")›ELSEIF a=b THEN› PrintE("A is equal to B")›ELSE› PrintE("A is greater than or")›FI››The reason I am mentioning this now›is APROG.901 uses both the ELSE and›the ELSEIF.››