下面的代码似乎有一个错误。
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.CenterToScreen()
If My.Computer.FileSystem.FileExists("binphpphp.exe") Then
Dim PHPRC As String = ""
Dim PHP_BINARY As String = "binphpphp.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("srcpocketminePocketMine.php") Then
Dim POCKETMINE_FILE As String = "srcpocketminePocketMine.php"
Else
MsgBox("Couldn't find a valid PocketMine-MP installation", MsgBoxStyle.Exclamation, "PocketMine-MP")
End If
End If
Process.Start("C:UsersDamianDesktopGamesPocketmineInstallerPocketMine-MPbinmintty.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中只是为了测试的原因)
你在if语句中暗化了两个变量,所以一旦你点击"end if"你的变量就消失了,或者"out of 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("binphpphp.exe") Then
PHP_BINARY = "binphpphp.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("srcpocketminePocketMine.php") Then
POCKETMINE_FILE = "srcpocketminePocketMine.php"
Else
MsgBox("Couldn't find a valid PocketMine-MP installation", MsgBoxStyle.Exclamation, "PocketMine-MP")
End If
End If
Process.Start("C:UsersDamianDesktopGamesPocketmineInstallerPocketMine-MPbinmintty.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