未检测到变量被声明

Nic*_* W. 1 vb.net variable-declaration

好吧,我正在玩视觉基础,似乎有一段时间开始使用xD.无论如何不确定为什么我收到以下错误:

UACLevel_Level没有宣布.由于其保护级别,它可能无法访问.

我尝试点击小帮助图标的东西,它什么也没给我.

Dim ConsentPromptBehaviorAdmin = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", "ConsentPromptBehaviorAdmin", Nothing)
Dim EnableLUA = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", "EnableLUA", Nothing)
Dim PromptOnSecureDesktop = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", "PromptOnSecureDesktop", Nothing)
Dim UACLevel_Value = ConsentPromptBehaviorAdmin + EnableLUA + PromptOnSecureDesktop
If UACLevel_Value = 0 Then
    Dim UACLevel_Level = "Never notify me."
ElseIf UACLevel_Value = 6 Then
    Dim UACLevel_Level = "Notify me only when programs try to make changes to my computer(do not dim desktop)."
ElseIf UACLevel_Value = 7 Then
    Dim UACLevel_Level = "Default - Notify me only when programs try to make changes to my computer."
ElseIf UACLevel_Value = 4 Then
    Dim UACLevel_Level = "Always Notify Me"
Else
    Dim UACLevel_Level = "Customized UAC Level"
End If
MsgBox("UACLevel is " & UACLevel_Value & ": " & UACLevel_Level)
Run Code Online (Sandbox Code Playgroud)

GSe*_*erg 5

UACLevel_LevelIf块内声明.在代码块内声明的变量只能从该块中看到.

这与VB6/VBA不同,它在块外可见(此时你会得到一个多声明错误,因为你声明它五次).

UACLevel_LevelIf块外部声明,并且仅在块中为其分配值If.

请参阅Visual Basic中的Scope以供将来参考.