Re: Coming From QBasic
- Posted by Jason Gade <jaygade at yahoo.com> Jan 17, 2006
- 520 views
Lynn Kilroy wrote: > > I see nothing wrong with passing an argument to a subroutine/procedure {to > me, these are really the same thing}, and allowing that subroutine to alter > > it. In QBasic, if I said: > > >DECLARE SUB Inke (a AS STRING) > > > >SUB Inkey (a AS STRING) > >a = INKEY$ > >END SUB > > what I'm saying is Inkey requires the argument 'a,' which passes data to and > > can also extract data from the subroutine. If I included a local variable > > in that subroutine: > > >DECLARE SUB Inke (a AS STRING) > > > >SUB Inkey (a AS STRING) > > > >DIM Variable AS DOUBLE > > > >Variable = RND > > > >a = INKEY$ > > > >END SUB > > then Variable is only remembered by Inkey. but is never seen by the rest of > > the program. In this case, it is a useless excercise becuase nothing is > done with it. As you say, local versus global. > > Also, in both cases above, the line > > >SUB Inkey (a AS STRING) > > means you *MUST* pass it an argument. That argument can be either a > variable pointer or a constant hard coded as an argument. In the case of > Inkey, you could pass it arguments the following way, and they would all > work. > > >DIM KeyPress AS STRING > > > >Inkey KeyPress > > -Or- > > >Inkey X$ > > -Or- > > >Inkey " " > > The first two are variables. I never use the signed variables. Poor form, > > and rather tasteless to me, anymore, so the middle one is out. But I use > variations of the top and bottom lines quite frequently, although in the > case of Inkey, calling Inkey with " " as the argument {a hard coded > constant} rather defeats the purpose. > > In Euphoria, the sub would look different. I'm going to use your code and > take a whack at it. > > >Procedure Inkey(Integer Key) > > Key = get_key() > >End Procedure > > > >Integer Key > > > >Inkey(Key) > > Would this work? If not this precisely, then how would it be coded, > precisely? The difference isn't so much that I use a global variable for it > > {Blech!} but that I pass a variable to it, and the variable is altered by > the Subroutine/Procedure and then passed back to the main program {if the > main program had a variable pointer in the first place}. > > Love & Friendship & Blessed Be! > Lynn Erika Kilroy No, this wouldn't work because Euphoria doesn't use pointers and doesn't allow you to modify a variable passed in as an argument. Euphoria is case-sensitive, too, so "Integer" would not work in place of "integer". Unless you defined "Integer" seperately. -- "Actually, I'm sitting on my butt staring at a computer screen." - Tom Tomorrow j.