Simple question, Please Help!!! :))) 
Author Message
 Simple question, Please Help!!! :)))

Doing this rather silly school project for which we were requested to
use subroutines (with little guidance).

I'm using the command:

"GoSub ControlBrk"

I now need to program the ControlBrk part of my program and I was
thinking that would go something like this....

Sub ControlBrk    <--- what's the Syntax for this????
        code
        code
        code
Return
(which will return control to the statement following my GoSub
command)

Well I keep getting compiler errors and the darn thing won't run. I
think it's because my Syntax is wrong for the programming of the
actual subroutine. Any ideas????

Thanks,
Danny

PS - Though this program is being done in VB, right now we're only
doing hard coding without the visual aspect. VB without the V ;)



Sun, 28 Apr 2002 03:00:00 GMT  
 Simple question, Please Help!!! :)))

Quote:
>Doing this rather silly school project for which we were requested to
>use subroutines (with little guidance).

>I'm using the command:

>"GoSub ControlBrk"

>I now need to program the ControlBrk part of my program and I was
>thinking that would go something like this....

>Sub ControlBrk    <--- what's the Syntax for this????
>    code
>    code
>    code
>Return
>(which will return control to the statement following my GoSub
>command)

>Well I keep getting compiler errors and the darn thing won't run.

You didn't mention which flavor of BASIC you use, but if you have a compiler
I'll guess it's QuickBasic or something later.

In QB, there are two kinds of subroutines: the old GOSUB..RETURN type and the
newer SUB..END SUG type.

The old syntax is:

GOSUB label
{execution will continue from here after return}
...
...
END ' of main program

label:
 {subroutine body}
RETURN

Note that you _don't use the keyword SUB.  All variables in a GOSUB subroutine
are global; the subroutine can see and alter any variable in the main program
or in another GOSUB - style subroutine.  This is the original subroutine,
updated only to the extent of allowing a descriptive label instead of a line
number.

The newer type of subroutine is defined with

SUB name [parameter list]
  subroutine body
END SUB

You call this kind of subroutine just by mentioning its name and (if it takes
paramaters) parameter list.  Variables declared inside a SUB are invisible to
the rest of the program, unless declared SHARED.

For example, if you want to use a SUB to
sound the beeper a variable number of times, you could use:

SUB Beeper (Count%)
  FOR I% = 1 TO Count%
          BEEP
  NEXT
END SUB

and the call

Beeper N%

anywhere in the program will produce N beeps.

QB keeps each SUB in its own editing window, so when you start editing the sub
the main program disappears.  The F2 key brings up a the list of subs (and the
main program) so you can select the next one to edit.  If you save the program
after adding a SUB, QB will automatically insert a DECLARE SUB line at the top
of the source file.  This alerts the compiler to the presence of the sub; it
looks like this:

DECLARE SUB Beeper (Count%)

Details are in the online help.

--------------------------------------------------------------------------
--------------
If it's spam, it's a scam.  Don't do business with Net abusers.



Mon, 29 Apr 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Very simple question - PLEASE HELP !!! :-)

2. Simple question, please help?!

3. MDI simple questions - please help

4. Simple question, please help!

5. Simple question - please help me arghhh!!!!!!!!

6. Simple question, please help!

7. Simple question...please help

8. A simple question - please help

9. Simple Question, Please help!!! :)))

10. SIMPLE SIMPLE ListView Question. Please help

11. PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP,

12. SIMPLE QUESTION, please SIMPLE ANSWER

 

 
Powered by phpBB® Forum Software