Need help - radio button working with button.click

futhon

Member
Joined
Feb 9, 2010
Messages
9
Programming Experience
Beginner
hi
I have create a User Interface with Visual Basic.net

This is roughly how my UI works:

User will use a button1.click to open a filedialog to locate the file they needed. after which, the name of the file will appear on a textbox.
  • Button2 is an OK button to write the filename into a txt file.
  • Button2.click will work with the 3 radio buttons - meaning when Radio Button 1 is true and Button2.click is clicked, the filename will be saved as File1.txt.
  • if Radio Button 2 is true and Button2.click is clicked, the filename will be saved as File2.txt.
  • Likewise to Radio Button 3

After the txt file is saved, Button3.click supposed to use the save file to run a shell command. the shell command will depend on the existing 3 radio buttons too.

Here's the problem.
After saving the file based on the previous radio button selected, button3.click needs to run based on the same radio button too. However it was not able to run. When i exit the form and run the form again, By just clicking button3 and the selected radio button, it's work well.
So i was wondering if the radio button can be worked together in a different click command?
Also whether if i can use the radio button to together with the save file and execute shell command - had tried before but doesnt seem to work as the file took awhile to be saved and the execute command alrdy kicks in??

here's the code:
VB.NET:
 Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        '##########################
        '## When choosing Button1##
        '##########################
        If Not TextBox1.Text = " " Then

            If RadioButton1.Checked = True Then
                Dim pathdir As String = "C:\2nd project\workingdir\File1.bat"
     
      'Writing content into the text file
                If File.Exists(pathdir) = True Then
                    Dim objWriter As StreamWriter = New StreamWriter(pathdir)
                    objWriter.Write("file_1.exe ")
                    objWriter.Write(TextBox1.Text)
                    objWriter.Close()

                    'MsgBox("Text written to file")
                    TextBox1.Text = " "
                Else
                    MsgBox("File Does Not Exist")
                End If
            End If

        '##########################
        '## When choosing Button2##
        '##########################

            If RadioButton2.Checked = True Then
                Dim pathdir As String = "C:\2nd project\workingdir\File2.bat"

                If File.Exists(pathdir) = True Then

.     'similar to radio button 1's step
.
.
.


 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim ChosenPlatform As String

        If RadioButton1.Checked = True Then

            Shell("File1.bat")
            'TextBox1.Text = " "

        ElseIf RadioButton2.Checked = True Then

            Shell("File2.bat")
            TextBox1.Text = " "

        ElseIf RadioButton3.Checked = True Then
.
.
.
 
I just checked on the time delay which it can help.
When i try to use
System.Threading.Thread.Sleep(2000)
it doesnt work well for my script.

Probably need to set a delay to create the .bat file then execute the shell command..
anyone can help me here with the code?

Thanks
 
Back
Top