2016-11-06 5 views
1

아래 코드에서 오류가있는 것 같습니다.BC30451 t 'VARIABLE'이 선언되지 않았습니다. 보호 수준으로 인해 액세스 할 수 없습니다.

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
    Me.CenterToScreen() 


    If My.Computer.FileSystem.FileExists("bin\php\php.exe") Then 
     Dim PHPRC As String = "" 
     Dim PHP_BINARY As String = "bin\php\php.exe" 
    Else 
     Dim PHP_BINARY As String = "php" 
    End If 

    If My.Computer.FileSystem.FileExists("PocketMine-MP.phar") Then 
     Dim POCKETMINE_FILE As String = "PocketMine-MP.phar" 
    Else 
     If My.Computer.FileSystem.FileExists("src\pocketmine\PocketMine.php") Then 
      Dim POCKETMINE_FILE As String = "src\pocketmine\PocketMine.php" 
     Else 
      MsgBox("Couldn't find a valid PocketMine-MP installation", MsgBoxStyle.Exclamation, "PocketMine-MP") 
     End If 

    End If 

    Process.Start("C:\Users\Damian\Desktop\Games\Pocketmine\Installer\PocketMine-MP\bin\mintty.exe", "-o Columns=88 -o Rows=32 -o AllowBlinking=0 -o FontQuality=3 -o Font='DejaVu Sans Mono' -o FontHeight=10 -o CursorType=0 -o CursorBlinks=1 -h error -t 'PocketMine-MP' -i bin/pocketmine.ico -w max" & PHP_BINARY & "" & POCKETMINE_FILE & "" & "--enable-ansi") 

End Sub 

는이 오류

BC30451 'PHP_BINARY'가 선언되지 않았습니다을 받고 계속. 보호 수준으로 인해 액세스 할 수 없습니다.

BC30451 'POCKETMINE_FILE'이 (가) 선언되지 않았습니다. 보호 수준으로 인해 액세스 할 수 없습니다.

내가 뭘 잘못하고 있니?

(참고로,를 Form1_Load에있는 그것의 단지 테스트 이유로.)

답변

2

당신은 당신이 공격 그래서 일단 문은 "범위에서"당신의 변수가 사라 졌어요 "하면 끝", 또는 경우 내에서 두 개의 변수를 디밍하고 . 당신은 확실히 variable scope에 대한 연구를해야합니다 ... 당신의 코드에서 이것을 고치려면 먼저 if 문 외부의 서브 문 안에 문자열을 선언하십시오. 그런 다음 if 문을 사용하여 변수의 내용을 변경하십시오. 그런 식으로 프로세스 호출이 오면 변수는 범위를 벗어나지 않습니다 :

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
    Me.CenterToScreen() 

    Dim PHP_BINARY As String = Nothing 
    Dim POCKETMINE_FILE As String = Nothing 

    If My.Computer.FileSystem.FileExists("bin\php\php.exe") Then 
     PHP_BINARY = "bin\php\php.exe" 
    Else 
     PHP_BINARY = "php" 
    End If 

    If My.Computer.FileSystem.FileExists("PocketMine-MP.phar") Then 
     POCKETMINE_FILE = "PocketMine-MP.phar" 
    Else 
     If My.Computer.FileSystem.FileExists("src\pocketmine\PocketMine.php") Then 
      POCKETMINE_FILE = "src\pocketmine\PocketMine.php" 
     Else 
      MsgBox("Couldn't find a valid PocketMine-MP installation", MsgBoxStyle.Exclamation, "PocketMine-MP") 
     End If 

    End If 

    Process.Start("C:\Users\Damian\Desktop\Games\Pocketmine\Installer\PocketMine-MP\bin\mintty.exe", "-o Columns=88 -o Rows=32 -o AllowBlinking=0 -o FontQuality=3 -o Font='DejaVu Sans Mono' -o FontHeight=10 -o CursorType=0 -o CursorBlinks=1 -h error -t 'PocketMine-MP' -i bin/pocketmine.ico -w max" & PHP_BINARY & "" & POCKETMINE_FILE & "" & "--enable-ansi") 

End Sub 
+1

이것은 완벽하게 작동합니다. 감사 :) – TheDeibo