gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 11:25:00 30 4
gpt4 key购买 nike

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

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 中只是出于测试原因。)

最佳答案

您在 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

关于vb.net - BC30451 'VARIABLE' 未声明。由于其保护级别,它可能无法访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40445201/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com