2012-08-31 4 views
1

Très bien, je suis en train de jouer avec Visual basic et j'ai l'impression d'avoir du mal à commencer xD. Quoi qu'il en soit ne sais pas pourquoi je reçois l'erreur suivante:Variable non détectée comme étant déclarée

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

J'essayé de cliquer sur la petite chose l'aide d'icônes et il m'a donné rien.

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) 

Répondre

0

Pour tous ceux qui étaient intéressés, le résultat final était le suivant.

Module Module1 

    Sub Main() 
     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 
     Dim UACLevel_level As String 
     If UACLevel_Value = 0 Then 
      UACLevel_level = "Never notify me." 
     ElseIf UACLevel_Value = 6 Then 
      UACLevel_level = "Notify me only when programs try to make changes to my computer(do not dim desktop)." 
     ElseIf UACLevel_Value = 7 Then 
      UACLevel_level = "Default - Notify me only when programs try to make changes to my computer." 
     ElseIf UACLevel_Value = 4 Then 
      UACLevel_level = "Always Notify Me" 
     Else 
      UACLevel_level = "Customized UAC Level" 
     End If 
     MsgBox("UACLevel is " & UACLevel_Value & ": " & UACLevel_Level) 

    End Sub 

End Module 
5

UACLevel_Level est déclarée à l'intérieur d'un bloc If. La variable déclarée à l'intérieur d'un bloc de code n'est visible qu'à partir de ce bloc.

Ceci est différent de VB6/VBA, où il serait visible en dehors du bloc (à quel point vous obtiendriez une erreur de déclaration multiple, parce que vous le déclarez cinq fois).

Déclarez UACLevel_Level en dehors du bloc If et attribuez-lui uniquement une valeur dans le bloc If.

Voir Scope in Visual Basic pour référence future.

+0

Merci, il a fallu un peu de jeu avec mais je l'ai fonctionné merci! – user1451070

+0

@ user1451070 Vous voulez dire cacher la fenêtre de la console qui est votre application? Vous pouvez créer un raccourci vers votre programme et définir dans le raccourci qu'il doit être masqué, mais si votre objectif est d'afficher une boîte de message, vous ne devriez pas avoir créé d'application de console en premier lieu. Créez un nouveau projet Windows Forms, créez un module, collez ce code, allez dans les propriétés du projet, onglet Application, décochez "Activer le framework applicatif", sélectionnez "Sub Main" pour l'objet "Startup", fermez et enregistrez les paramètres, supprimez le formulaire Form1, compilez. – GSerg

Questions connexes