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

Possibly Related Threads…
Thread Author Replies Views Last Post
  Function Pointers? BlameTroi 5 230 02-20-2026, 05:55 PM
Last Post: BlameTroi
  QB64PE Excel-type spreadsheet supporting formulas and QB64PE macros? madscijr 33 1,455 01-30-2026, 12:28 AM
Last Post: madscijr
  Arbitrary CONST values Unseen Machine 31 2,880 10-29-2025, 05:44 AM
Last Post: bplus
  Variable length type declarations dano 5 688 08-06-2025, 09:53 PM
Last Post: dano
  Upcoming changes to CONST may affect your code SMcNeill 14 2,744 12-30-2023, 05:13 PM
Last Post: Kernelpanic

Forum Jump:


Users browsing this thread: 1 Guest(s)