Global Variables

Post

Posted
Rating:
#1 (In Topic #534)
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
Hi All,

I was wondering if someone could direct me to the correct outcome of this issue I am having

I want to have a module that holds all my global settings for example

Code

Public Key_SignOn As Integer = 65             'A

the idea is so I can use the same declare though out my application like this

Code

Select Case Key.Code
    Case Key_SignOn ' lower case A
      frmSignedOff.Enabled = False
      FMain.Workspace1.Add(FrmSignOn, False)
  End Select

and not like this

Code

elect Case Key.Code
    Case 65 ' Lower case A
      frmSignedOff.Enabled = False
      FMain.Workspace1.Add(FrmSignOn, False)
  End Select

but when I try to run the program I get the following error "Unknown identifier: Key_SignOn in frmSignedoff.class:13"

what do I need to do to get this to work.

I do come from a Visual Basic 6 background and I am willing to learn new skills here
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Enthusiast
PJBlack is in the usergroup ‘Enthusiast’

Code (gambas)

  1. ' Modul AllMyGlobalVars
  2. Public Key_SignOn As Integer = 65
  3.  

Code (gambas)

  1. ' Class/Form/Modul blablahblubb
  2.     Case AllMyGlobalVars.Key_SignOn ' lower case A
  3.  

BUT

maybe you like to have a look at the gb.settings class …

http://gambaswiki.org/…p/gb.settings?ht=settings
or
https://gambas-buch.de/doku.php?id=k19:k19.1:start (german, not translated yet)
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
 Do yourself a favour and don't name your modules too long - it gets very stale, very quickly, having to type MyFunkySpecialModule.{my variable}

I went full 1980's and named my two main modules:
AV { application variables } - just global variables
AG { application global } - Global functions and routines

…as long as you don't go overboard with shortened names, it will save you a LOT of time as you code.

Cheers - Quin.
I code therefore I am
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Enthusiast
PJBlack is in the usergroup ‘Enthusiast’
speaking names quin ... and gb has completion hints after three letters
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Regular
stevedee is in the usergroup ‘Regular’

Quincunxian said

Do yourself a favour and don't name your modules too long…

Quin, I agree with PJ and rely on auto-complete to do most of my typing. But I try to avoid similar long names:-

mySpecialFunkyChicken
mySpecialFunkyChildren

…but even in such cases, I just use the up/down arrow when auto-complete gives me a list of options.
I'd probably call the modules: gVars & gFunctions

I don't want to go back to the 1980s for x = y - z + 2j

…I'd only go back for ABBA
Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
There is one exception.
If you assign a local variable to a global variable in a form or a class then the auto-complete does not work.

Code (gambas)

  1. ' Gambas class file
  2. Private MyLocalVariable as string = MyGlobalModule.SomeVariable  ' Auto-complete does not work
  3.  
  4. Public Sub Form_Open()
  5.    Dim MyLocalVariable as string = MyGlobalModule.SomeVariable  ' Auto-complete works
  6.  

As a whole, I agree to a point.
Normally I only use three distinct modules and avoid using more as they do come with a memory overhead.
So having short names for these especially with the naming convention used ( AE, AG, AV ) does save time ( AE is dedicated to error management routines )
I make extensive use of tool-box classes that I've developed over the years and the contained routines do need to be named distinctively for obvious reasons.

My advice to new coders is: be consistent.  
If you work in a professional developer team, they will normally have a style guide on what naming convention to use.
Even if you are just an enthusiast, then being consistent makes life easier in the long run.
I've opened code I wrote 10 years ago and with a horrified look on my face, I had that moment of "What the hell was i thinking…"

Cheers - Quin.
I code therefore I am
Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
I've opened code I wrote 10 years ago and with a horrified look on my face, I had that moment of "What the hell was i thinking…"

I have had that happen with what I wrote last week  :lol:
Online now: No Back to the top

Post

Posted
Rating:
#8
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
Thank-you to everyone who replay Sorry for the dalay I only just got my emails back up and running
Online now: No Back to the top
1 guest and 0 members have just viewed this.