English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

if I want to store global constants and variables BEFORE the form loads and the user begins interacting with my program, how do I do that?

It doesn't seem initially obvious to me

2007-03-08 16:55:56 · 4 answers · asked by cpine505 3 in Computers & Internet Programming & Design

I'm using VB Express 2005

2007-03-08 17:14:19 · update #1

4 answers

In VB 2005 Express Add a Module and declare Public constants there.

Ex: Module1.vb

Module Module1
Public Const MyConstant = 5
End Module

2007-03-08 17:25:47 · answer #1 · answered by solitaryfalcon 2 · 1 0

if you're using vb 6, you add a MODULE to your project. In this MODULE, you create a Sub called Main. At the top of this file, you create your globals, and then the last thing you do is launch form 1. for ex, in run.bas:
global var1 as integer
global var2 as string
sub main
var1=5
var2="Hello"
load(form1)
form1.show
end sub
now, right click and go to properties and set the startup object to be sub main instead of form1.

in vb.net, you can use form.preinit or form.preload event to do this before the form loads.

2007-03-09 01:00:34 · answer #2 · answered by shawntolidano 3 · 0 0

to simply get rid of these types u define on the top what variables u have to assign just define on the top and it can easily accessed by all the classes remember not to use that name again and again for private variables it will interact with other values and Ur ans might will be changed

global variables if defined on the top at program properties it will act better

2007-03-09 01:03:49 · answer #3 · answered by simple_anagh 1 · 0 0

Isn't there a Form1_Load() init section that you can use? Right outside the sub just dim whatever as global.

2007-03-09 01:45:10 · answer #4 · answered by Andy T 7 · 0 0

fedest.com, questions and answers