Connecting Tech Pros Worldwide Forums | Help | Site Map

very new to vb.net

cwebs4u's Avatar
Newbie
 
Join Date: Feb 2007
Location: Ft Lauderdale
Posts: 1
#1: Feb 1 '07
picked up a book and probably not a good one but nonetheless, picked one up and trying to read the chapters and do the exercises in the back of each chapter (good gurl, right?)

well... im stuck on a question and was hoping someone could finish what i started and/or fix it and then explain to me why they finished it the way they did (any takers) ???

====================================

i gotta form and it has two buttons, one button named uiSalaryButton and the other named uiBonusButton

both buttons Click event procedures need to use the variable "employeeName" variable

i need to write an appropriate statement that declares the employeeName variable and specify where i would need to enter that statement AND whether or not it's procedure-level or module-level variable

ima start off and you can either correct, fix or tell me to bug off (or not)

Module-level:
Private employeeName as String = uiSalaryButton + uiBonusButton


thanx,
sharon

Lives Here
 
Join Date: Oct 2006
Posts: 1,626
#2: Feb 1 '07

re: very new to vb.net


Hi Sharon.
There are 2 ways to share a variable between procedures. One is to pass it from one procedure to another as a parameter and the other is to make the variable global in scope so that all procedures can 'see' it.

In your case the second route seems to be the best as you have discovered. All of the procedures in your module will 'see' this variable. You don't have to use special initializing syntax to make sure that the button onclick events can use this variable. As long as the event procedures are in the same module all will be well.

When you use the 'private' keyword you are limiting the scope to just that module. No other modules can see this variable. This is good. Unless you have a pressing reason to do so, it is normally poor programming to declare variiables that can be seen in all modules.

So the declaration:
Expand|Select|Wrap|Line Numbers
  1. Private employeeName As String
is all you need to put in your code module

If you post more code, we can give more assistance.
Good luck
Reply