Dim inside If..?

  • Thread starter Thread starter Carlos Albert
  • Start date Start date
C

Carlos Albert

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?
 
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
 
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 said:
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.
 
"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 ?
 
Back
Top