1

When i want define values in Select Case i got error:

'Value' is not declared. It may be inaccessible due to its protection level.

When Dim Value As Object is outside Select Case - No error. My target is get Value different on special numbers. For example:

Select Case Integer
     Case 1
         Dim Value As New UserControl1
     Case 2
         Dim Value As New UserControl2
     Case Else
         Dim Value As New UserControl3
End Select
4

2 回答 2

1

试试这个,假设所有 3 种用户控件类型都派生自基础UserControl对象:

Dim Value as UserControl
Select Case Integer
     Case 1
         Value = New UserControl1
     Case 2
         Value = New UserControl2
     Case Else
         Value = New UserControl3
End Select
于 2013-06-27T19:36:24.663 回答
1

在作用域内声明变量并在作用域外访问它是不可行的,例如select case语句。但是,通过将声明和初始化分开,您的问题很容易解决。这使您可以在选择案例之外使用变量,因为该变量位于更高的范围内。该变量被声明为 System.Windows.Controls.UserControl,因为这是最具体的常见类型。

Dim Value As UserControl
Select Case Integer
     Case 1
         Value = New UserControl1
     Case 2
         Value = New UserControl2
     Case Else
         Value = New UserControl3
End Select
于 2013-06-27T19:37:12.197 回答