我遇到了一个问题,我收到“变量‘strMap’在被赋值之前使用。运行时可能导致空引用异常”字符串strMap的错误。
我知道这是说我在应用值之前使用字符串,但是,正如您从代码中看到的那样,我在最后一组 If 语句中应用了一个值(这些以前是 If/Else,但我假设这就是搞砸它的原因。
结果,它找不到在 shell 命令中指定的文件,因为 strMap 字符串充当空。
提前致谢。
达蒙
Private Sub btnCreateServerSimple_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateServerSimple.Click
'Working code for server creation using pre-existing batch files
'Declarations
Dim strGameType As String
Dim strMap As String
Dim strServer As String
'Dim strBatchFile As String
Dim strBatchLoc As String
'Checking for selected server and setting strServer string accordingly
If cmbServerSimple.Text = "Server 1" Then
strServer = "server1"
strBatchLoc = frmInstallUpdateSettings.txtCSGOServer1BatchFilesLocation.Text
Else : cmbServerSimple.Text = "Server 2"
strServer = "server2"
strBatchLoc = frmInstallUpdateSettings.txtCSGOServer2BatchFilesLocation.Text
End If
'Checking for gametype and setting strGameType string accordingly
If cmbGameTypeSimple.Text = "Classic Competative" Then
strGameType = "classic_competative"
Else : cmbGameTypeSimple.Text = "Classic Casual"
strGameType = "classic_casual"
End If
'Checking for selected map and setting strMap string accordingly
If cmbMapSimple.Text = "de_aztec" Then
strMap = "de_aztec"
End If
If cmbMapSimple.Text = "de_dust2_se" Then
strMap = "de_dust2_se"
End If
If cmbMapSimple.Text = "de_dust" Then
strMap = "de_dust"
End If
If cmbMapSimple.Text = "de_inferno" Then
strMap = "de_inferno"
End If
If cmbMapSimple.Text = "de_nuke_ve" Then
strMap = "de_nuke_ve"
End If
If cmbMapSimple.Text = "de_mirage" Then
strMap = "de_mirage"
End If
If cmbMapSimple.Text = "de_train" Then
strMap = "de_train"
End If
If cmbMapSimple.Text = "de_vertigo" Then
strMap = "de_vertigo"
End If
Shell("C:\Users\Damon\Desktop\batchtest\" & strServer & "_" & strGameType & "_" & strMap & ".bat", AppWinStyle.NormalFocus)
End Sub