BC30451'VARIABLE'未声明。由于其保护级别,它可能无法访问

时间:2016-11-06 01:41:34

标签: vb.net windows mintty

我的代码似乎有误。

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中。)

1 个答案:

答案 0 :(得分:3)

你在if语句中调整了两个变量,所以一旦你点击"结束了"你的变量消失了,或者超出范围"。你绝对应该对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