PC Review


Reply
Thread Tools Rate Thread

Declaring Variables

 
 
Berny
Guest
Posts: n/a
 
      9th Nov 2003
Can anyone help me on this one or at lease tell me if it can be done.

I'm trying to declare a variable once that can be used by all of the
functions/procedures in the module/project.

dim strVar as string

strVar = "1.1b"

I can't seem to make it work.


 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      9th Nov 2003
Your Dim strVar As String needs to be in a module (not in the code behind a
form), and it must be at the beginning of the module (i.e.: not inside any
function or sub).

As well, to make it available everywhere, you need to use Global strVar As
String (or Public strVar As String).

The assignment statement, strVar = "1.1b", can go anywhere (but obviously
the assignment must be made before the variable is used anywhere!)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)



"Berny" <BlancoB at msn Dot com> wrote in message
news:%234lf%(E-Mail Removed)...
> Can anyone help me on this one or at lease tell me if it can be done.
>
> I'm trying to declare a variable once that can be used by all of the
> functions/procedures in the module/project.
>
> dim strVar as string
>
> strVar = "1.1b"
>
> I can't seem to make it work.
>
>



 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      9th Nov 2003
"Berny" <BlancoB at msn Dot com> wrote in message
news:%234lf%(E-Mail Removed)
> Can anyone help me on this one or at lease tell me if it can be done.
>
> I'm trying to declare a variable once that can be used by all of the
> functions/procedures in the module/project.
>
> dim strVar as string
>
> strVar = "1.1b"
>
> I can't seem to make it work.


You have to declare the variable at the module level in a standard
module (not a form, report, or class module), and it must be declared
with the Public keyword; e.g.,

Public strVar As String

You should be aware that under some circumstances the value of a global
variable can be lost. For example, an unhandled error will cause your
VB project to be reset, and that will erase all the values of public
variables. So if you want to use a global variable to hold data for an
extended period, you'd better include code to check that the variable
still has a value, and reload it if necessary.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
Juan M. Afan de Ribera
Guest
Posts: n/a
 
      9th Nov 2003
Maybe I misunderstand you, but, in addition of what Douglas and Dirk are
saying and in the case you want to assign a value that is not going to
change in the whole application, you better use this other way to do it

Public Const strVAr As String = "1.1b"

if this is not the case, just forget it

:-)

--
Saludos desde Barcelona
Juan M. Afan de Ribera
<MVP Ms Access>
http://www.juanmafan.tk
http://www.clikear.com/webs4/juanmafan


"Berny" <BlancoB at msn Dot com> escribió en el mensaje
news:#4lf#(E-Mail Removed)...
> Can anyone help me on this one or at lease tell me if it can be done.
>
> I'm trying to declare a variable once that can be used by all of the
> functions/procedures in the module/project.
>
> dim strVar as string
>
> strVar = "1.1b"
>
> I can't seem to make it work.
>
>



 
Reply With Quote
 
Berny
Guest
Posts: n/a
 
      10th Nov 2003
Thank you

Your information did the trick

"Berny" <BlancoB at msn Dot com> wrote in message
news:%234lf%(E-Mail Removed)...
> Can anyone help me on this one or at lease tell me if it can be done.
>
> I'm trying to declare a variable once that can be used by all of the
> functions/procedures in the module/project.
>
> dim strVar as string
>
> strVar = "1.1b"
>
> I can't seem to make it work.
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Declaring variables ericb Microsoft Access 9 23rd Feb 2010 06:26 PM
Declaring Variables Twice? Chad Microsoft Excel Programming 2 20th May 2009 12:48 AM
Re: DEclaring variables Pedro Microsoft Excel Programming 1 13th Nov 2003 06:02 PM
Declaring variables HHickey Microsoft Dot NET Framework 1 13th Nov 2003 05:39 PM
DEclaring variables Pedro Microsoft Excel Programming 2 13th Nov 2003 12:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:29 PM.