You can use Dim within an If statement. However, the variable is scoped to that block.
Instead, you can declare the variable outside the block and then use it inside and after:
Code:
Dim users As Integer
Using myentities As New entity
If x=1 then
users = (From r In myentities.users).Count 'Get number of all users
else
users = (From r In myentities.users where r.name=N'Brown').Count 'Get number of users named Brown
end if
msgbox(users)
Note that although MsgBox *seems* to appear to work in a development environment, it won't work for your web users.
Hope this helps,
Imar