【问题标题】:BC30451 'VARIABLE' is not declared. It may be inaccessible due to its protection levelBC30451 'VARIABLE' 未声明。由于其保护级别,它可能无法访问
【发布时间】:2016-11-06 01:41:33
【问题描述】:

我似乎对下面的代码有错误。

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

【问题讨论】:

    标签: vb.net windows mintty


    【解决方案1】:

    您正在使 if 语句中的两个变量变暗,因此一旦您点击“end 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多