2016-11-06 52 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

你調光的if語句,所以一旦你點擊「結束時,如果」你的變量都走了,或「超出範圍」內的兩個變量。你一定要在variable scope上做一些研究...要在你的代碼中解決這個問題,首先聲明這個字符串在sub的內部但是在你的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

相關問題