Hello all,

I have the following script:

Test = "hello"
If Test = "hello" then
MyVar = "ok"
end if

MsgBox MyVar

I would expect that variable MyVar would hold "ok" but it does not.
Is the scope of this variable limited to the if - end if construct ?
How can I workaround this ?

Thanks
Bar

Re: Problem with variable scope by Ulf

Ulf
Mon Nov 01 07:15:39 CST 2004

barabba wrote:
> I have the following script:
>
> Test = "hello"
> If Test = "hello" then
> MyVar = "ok"
> end if
>
> MsgBox MyVar
>
> I would expect that variable MyVar would hold "ok" but it does not.

It does ... the script is correct.

> Is the scope of this variable limited to the if - end if construct ?

Nope

Ulf



RE: Problem with variable scope by Deepak

Deepak
Tue Nov 02 22:27:05 CST 2004

It depends on what you have declared that variable as .
It must work fine and it does .
Try this
dim test
dim a
test = "hello"
if test = "hello" then
a = "ok"
end if
msgbox a

"barabba" wrote:

> Hello all,
>
> I have the following script:
>
> Test = "hello"
> If Test = "hello" then
> MyVar = "ok"
> end if
>
> MsgBox MyVar
>
> I would expect that variable MyVar would hold "ok" but it does not.
> Is the scope of this variable limited to the if - end if construct ?
> How can I workaround this ?
>
> Thanks
> Bar
>

Re: Problem with variable scope by Al

Al
Fri Nov 05 12:57:20 CST 2004


"Deepak" <Deepak@discussions.microsoft.com> wrote in message
news:2BFD934F-94B7-433E-B985-EB4BEA613B8F@microsoft.com...
> It depends on what you have declared that variable as .
> It must work fine and it does .

In fact it does and should display the variable as "ok", even without the
dim statements.

> Try this
> dim test
> dim a
> test = "hello"
> if test = "hello" then
> a = "ok"
> end if
> msgbox a
>
> "barabba" wrote:
>
> > Hello all,
> >
> > I have the following script:
> >
> > Test = "hello"
> > If Test = "hello" then
> > MyVar = "ok"
> > end if
> >
> > MsgBox MyVar
> >
> > I would expect that variable MyVar would hold "ok" but it does not.

I would like to see the msgbox fail to display "ok". Have you perhaps
defined a sub or function with the same name?

> > Is the scope of this variable limited to the if - end if construct ?

No, however useful a feature like that would be.

> > How can I workaround this ?

Since I cannot duplicate the problem, all I can suggest is that you come
over to my house where you can run it successfully.

But seriously, if msgbox does not display the value as "ok", then what does
actually happen? An error message, and, if so, what *E*X*A*C*T*L*Y does it
say?

/Al