Bear with me guys, I'm new to VB. Long story short. I have a VB app that has a couple buttons that open a new form. I've tried to repurpose this form for multiple uses using Case selections.
2 buttons:
btnPing:
Private Sub btnPing_Click(sender As Object, e As EventArgs) Handles btnPing.Click
dataTransferBtnCase = "ping"
formDataTransfer.ShowDialog()
btnRobocopy.Enabled = True
End Sub
And btnRobocopy
Private Sub btnRobocopy_Click(sender As Object, e As EventArgs) Handles btnRobocopy.Click
dataTransferBtnCase = "robocopy"
formDataTransfer.Show()
End Sub
In each button, it assigns the value to the variable dataTransferBtnCase.
Now, on that form, I have the following code:
Public Class formDataTransfer
'Clear the variable right off the bat
Public dataTransferBtnCase As String = ""
Private Sub formDataTransfer_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim oldPath As String = viewInstall.txtOldHostname.Text
Dim newPath As String = viewInstall.txtNewHostname.Text
dataTransferBtnCase = viewInstall.dataTransferBtnCase
Select Case dataTransferBtnCase
Case "ping"
Me.Text = "Pinging " & oldPath
ExecuteCommand("cmd.exe", "/D /c ping " & oldPath)
Case "robocopy"
Me.Text = "Robocopy from " & viewInstall.txtOldHostname.Text & " to " & viewInstall.txtNewHostname.Text
ExecuteCommand("robocopy.exe", "C:emp
obo1 C:emp
obo2 /E /XF file *.dat *.dat.log *.dat.log1 /log:robolog.log")
Case Else
Me.Text = "lol idk!"
MessageBox.Show("An unknown error has occurred!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Select
dataTransferBtnCase = ""
viewInstall.dataTransferBtnCase = ""
End Sub
End Class
the btnPing_Click sub works every time like it should. However, the btnRobocopy_Click sub will only work after you click it once, close the new form window, and click the button again. I'm sure it's because I'm not clearing the variable correctly somewhere, I just don't know where. Any help?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…