Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TYPE and CONST within SUB/FUNCTION
#3
Quote:A while back I accidentally discovered that CONST can be used in SUBs and FUNCTIONs to create local constants. You can even use the same CONST variable name from the main code to create another unique local constant.

I was wondering if this worked with TYPEs. It appears it does not. While you can create a user defined TYPE within a SUB or FUNCTION it will always be seen globally. Is this correct behavior or should the user defined TYPE be local to the SUB and/or FUNCTION?
If a constant is declared within a procedure or function, it has the status "local" and is only known there. Otherwise a constant is declared globally; in the main program.

Type . . . End Type definitions can not be declared in functions or procedures; the best place for them is at the beginning of a program - right after the constant declaration.
Actually clear, because what's the point of a type declaration in a procedure or function?

However, type definitions can be used as argument types of procedures and functions.

From MS-DOS QBasic - The Technical Reference; The Wait Group 1991/92
Reply


Messages In This Thread
RE: TYPE and CONST within SUB/FUNCTION - by Kernelpanic - 07-09-2023, 11:05 PM
RE: TYPE and CONST within SUB/FUNCTION - by bplus - 07-10-2023, 12:30 AM
RE: TYPE and CONST within SUB/FUNCTION - by bplus - 07-10-2023, 12:55 AM
RE: TYPE and CONST within SUB/FUNCTION - by bplus - 07-11-2023, 01:22 AM



Users browsing this thread: 2 Guest(s)