-
Select Case Scope
Are duplicate name declarations in a select case legal?
Code:
Select Case Msg
Case "Yes"
Dim sAnswer As String = "Yes"
Case "No"
Dim sAnswer As String = "No"
End Select
Reason I ask is because I notice if I do this, the IDE wont automatically format the name of the declaration , like so...
Code:
Select Case Msg
Case "Yes"
Dim sAnswer As String = "Yes"
MsgBox(sanswer)
Case "No"
Dim sAnswer As String = "No"
MsgBox(sanswer)
End Select
The IDE wont auto-Capitalise sanswer if I have more than 1 instance in the routine.. Just wondering..
-
Simple answer : If the project doesn't compile, then its not legal.
Does it compile?
-
Re: Select Case Scope
Quote:
Originally posted by Hinder
Are duplicate name declarations in a select case legal?
Code:
Select Case Msg
Case "Yes"
Dim sAnswer As String = "Yes"
Case "No"
Dim sAnswer As String = "No"
End Select
Reason I ask is because I notice if I do this, the IDE wont automatically format the name of the declaration , like so...
Code:
Select Case Msg
Case "Yes"
Dim sAnswer As String = "Yes"
MsgBox(sanswer)
Case "No"
Dim sAnswer As String = "No"
MsgBox(sanswer)
End Select
The IDE wont auto-Capitalise sanswer if I have more than 1 instance in the routine.. Just wondering..
Have you tried your code? Cos it works OK. as it is.
If you declare sAnswer outside of the Select Case Block you will find the intellisense works as you expect.
-
The IDE's got weird quirks, doesn't mean your code won't work. I.e., if i have an if...end block, then put that in another if...end block, the IDE doesn't always format them out to the correct tabs. Usually they'll be ok the next time I load the project, but anyway, doesn't seem to break the code (that's my job!).