I have a function with If... Else... End If...

And inside the If I wanted to define some datasets and stuff... but the
visual says not.

Is there any way to do it?

Re: Dim inside If..? by SStory

SStory
Fri Sep 23 16:18:31 CDT 2005

If this is Visual Basic .NET 1.1, you should be able to do this.

if whatever then
dim x as integer
end if

what code are you using?
what version of .NET?

What message are you getting?

thanks,

shane
"Carlos Albert" <nadie@ningunlugar> wrote in message
news:eBf%23ZHIwFHA.3720@TK2MSFTNGP14.phx.gbl...
>I have a function with If... Else... End If...
>
> And inside the If I wanted to define some datasets and stuff... but the
> visual says not.
>
> Is there any way to do it?
>
>



Re: Dim inside If..? by Scott

Scott
Fri Sep 23 16:33:47 CDT 2005

You can certainly declare a variable with Dim inside of an "If", but if you
do, the variable will only be available inside that particular part of the
If statement (Block Level Scope).


"Carlos Albert" <nadie@ningunlugar> wrote in message
news:eBf%23ZHIwFHA.3720@TK2MSFTNGP14.phx.gbl...
>I have a function with If... Else... End If...
>
> And inside the If I wanted to define some datasets and stuff... but the
> visual says not.
>
> Is there any way to do it?
>
>



Re: Dim inside If..? by Peter

Peter
Sat Sep 24 07:53:14 CDT 2005


"Carlos Albert" <nadie@ningunlugar> wrote in message
news:eBf%23ZHIwFHA.3720@TK2MSFTNGP14.phx.gbl...
>I have a function with If... Else... End If...
>
> And inside the If I wanted to define some datasets and stuff... but the
> visual says not.
>
> Is there any way to do it?
>
>
Per haps if you were to show us some of the code where your Dim attempt
fails, of provide further details...
As stated by others, using Dim inside an if or else block should work OK.

If isLocalMethod = "True" Then 'See commentary above.

Dim a As Integer

Dim b As Integer

a = 3

b = 3

Dim c As Integer = a + b

All compiles and executes correctly.


--
Peter [MVP Visual Developer]
Jack of all trades, master of none.



Re: Dim inside If..? by Patrice

Patrice
Mon Sep 26 04:55:18 CDT 2005

"says not" is not helpfull. Please always tells exacly what happens. It
should work. What is the exact error message you get ?

You perhaps try to redefine a variable that already exists ?

--

"Carlos Albert" <nadie@ningunlugar> a écrit dans le message de
news:eBf%23ZHIwFHA.3720@TK2MSFTNGP14.phx.gbl...
> I have a function with If... Else... End If...
>
> And inside the If I wanted to define some datasets and stuff... but the
> visual says not.
>
> Is there any way to do it?
>
>