If CheckBox1.Checked = True Then
Dim a As String = "-clone"
Else
End If
If CheckBox2.Checked = True Then
Dim b As String = "-noerror"
Else
End If
If CheckBox3.Checked = True Then
Dim c As String = "-nocorr"
Else
End If
If CheckBox4.Checked = True Then
Dim d As String = "-notrunc"
Else
End If
All of the variables
a,b,c,d
are declared in the local scope of
If
. Once the If is done, they are no more available and thus the error.
try this:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim someString As String
If CheckBox1.Checked = True Then
someString = "-clone"
Else
End If
If CheckBox2.Checked = True Then
someString = "-noerror"
Else
End If
If CheckBox3.Checked = True Then
someString = "-nocorr"
Else
End If
If CheckBox4.Checked = True Then
someString = "-notrunc"
Else
End If
Dim file As System.IO.StreamWriter
file = My.Computer.FileSystem.OpenTextFileWriter(Application.StartupPath & "test.bat", True)
file.WriteLine("readom dev=0,0,0 f=Backup.raw" + someString)
file.Close()
End Sub
For more details and understanding:
Scope - Visual Basic | Microsoft Docs[
^]