If and Else statements on Visual Basic - vb.net

I am having problems figuring out in which order these if and else statements need to be arranged in Visual Basic 2010 Express. As you can probably tell from the code, when it is working properly the program should display data found in a text file externally. If this data is not found then an error message in a label should appear.
Thanks for the help.
Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim filename As String = "..\..\usernamepassword.txt"
Dim objreader As New System.IO.StreamReader(filename)
Dim contents As String
Dim check As String
Dim checkfile As New System.IO.StreamReader("..\..\checkfile.txt")
check = checkfile.ReadToEnd
For i As Integer = 1 To check
contents = objreader.ReadLine
Dim data As New List(Of String)(contents.Split(","))
If forename.Text = data(2) Then
'first if statement is here \/
If surname.Text = data(3) Then
fullname.Text = (data(2) & " " & data(3))
dob.Text = data(4)
phone.Text = data(5)
address.Text = data(6)
password.Text = data(1)
'else statement \/
Else
Label2.Text = "Sorry, no result found for this student."
Label5.Text = "Please note this system is caps sensitive."
End If
End If
Next i
Dim s As String = ""
forename.Text = s
surname.Text = s
End Sub
End Class

You should handle it like this
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim filename As String = "..\..\usernamepassword.txt"
Dim found as Boolean = False
Dim objreader As New System.IO.StreamReader(filename)
Dim contents As String
Dim check As String
Dim checkfile As New System.IO.StreamReader("..\..\checkfile.txt")
check = checkfile.ReadToEnd
For i As Integer = 1 To check
contents = objreader.ReadLine
Dim data As New List(Of String)(contents.Split(","))
If forename.Text = data(2) Then
'first if statement is here \/
If surname.Text = data(3) Then
fullname.Text = (data(2) & " " & data(3))
dob.Text = data(4)
phone.Text = data(5)
address.Text = data(6)
password.Text = data(1)
found = True
Exit For
End If
End If
Next i
If found = False Then
Label2.Text = "Sorry, no result found for this student."
Label5.Text = "Please note this system is caps sensitive."
End If
Dim s As String = ""
forename.Text = s
surname.Text = s
End Sub

Check has been declared as string when it should be an integer.
Set option strict to on and infer to off

Related

Data type long can not be converted

I have a problem with error which show me problem with long data type in this part of code:
If Not filename Then
Call Form15.Show()
TextBox1.Clear()
here is full code:
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
Dim filename As String
Dim regCis = TextBox1.Text
filename = TextBox1.Text
Dim zakazCis As Double
Dim found As Boolean = False
found = True
If (Double.TryParse(TextBox2.Text, zakazCis)) Then
zakazCis = TextBox2.Text
Else
zakazCis = Nothing
End If
Dim basePath As String = "C:\_Montix a.s. - cloud\iMontix\Testy"
Dim filePath As String = IO.Path.Combine(basePath, filename & ".lbe")
'Napojeni tabulky
Dim table As DataTable = SdfDataSet.Tables("List1")
Me.Refresh()
'Vytvoreni dotazu
Dim expression As String
expression = ("[Čísla dílů] = '" & regCis & "'")
Dim foundRows() As DataRow
Me.PictureBox1.Invalidate()
Dim bla = "Label10"
'vykonani dotazu
foundRows = table.Select(expression)
If Not filename Then
Call Form15.Show()
TextBox1.Clear()
Else
If (foundRows(0)(2) = zakazCis) Then
'souhlasí regCis a zakcis
PictureBox1.Image = Image.FromFile("C:\_Montix a.s. - cloud\Visual Studio 2015\Projects\WindowsApplication17\WindowsApplication17\img\tick.png")
Label10.BackColor = Color.Green
Me.Controls(bla).Text = "SPRÁVNĚ"
fileprint.PrintThisfile(filePath)
Threading.Thread.Sleep(4000)
SendKeys.Send("{ENTER}")
TextBox2.Clear()
TextBox2.Select()
Button6.Hide()
PictureBox1.Hide()
Label10.Hide()
Else
'NEsouhlasí regCis a zakcis
PictureBox1.Image = Image.FromFile("C:\_Montix a.s. - cloud\Visual Studio 2015\Projects\WindowsApplication17\WindowsApplication17\img\cross.png")
Label10.BackColor = Color.Red
Form15.Show()
TextBox2.Clear()
TextBox2.Select()
End If
End If
End Sub
and here is code from form15
Public Class Form15
Private Sub Button11_Click(ByVal sender As Object, ByVal e As EventArgs)
Me.Hide()
End Sub
End Class
Do you known where is a problem?
You are using a string in a boolean expression. I guess, you might have added the string instead of the boolean by mistake. ('found' instead of 'filename')
If Not found Then
Call Form15.Show()
TextBox1.Clear()
Else

vb.net change combobox options depending on selected item in 2 previous comboboxes

I am creating a program which someone can input a search into a textbox and then narrow down the results using a series of comboboxes (or just use the comboboxes to search through everything).
The program looks like this: form 1
I have made the options in the 2nd combobox change using the following code:
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim type As String = ComboBox1.SelectedItem
Dim make As String = ComboBox2.SelectedItem
Dim model As String = ComboBox3.SelectedItem
Dim version As String = TextBox2.Text
Dim memory As String = TextBox3.Text
Dim problem As String = TextBox4.Text
Dim casenumber As Integer = Int(Rnd() * 9999) + 1000
If type = "Phone" Then
ComboBox2.Items.Clear()
Dim file As New System.IO.StreamReader("E: \phone.txt")
For i = 1 To 20
q(i) = file.ReadLine() & vbNewLine
ComboBox2.Items.Add(q(i))
Next
ElseIf type = "Tablet" Then
ComboBox2.Items.Clear()
Dim file As New System.IO.StreamReader("E:\tablet.txt")
For i = 1 To 20
q(i) = file.ReadLine() & vbNewLine
ComboBox2.Items.Add(q(i))
Next
ElseIf type = "Desktop computer" Then
ComboBox2.Items.Clear()
Dim file As New System.IO.StreamReader("E:\pc.txt")
For i = 1 To 20
q(i) = file.ReadLine() & vbNewLine
ComboBox2.Items.Add(q(i))
Next
ElseIf type = "Laptop" Then
ComboBox2.Items.Clear()
Dim file As New System.IO.StreamReader("E:\laptop.txt")
For i = 1 To 20
q(i) = file.ReadLine() & vbNewLine
ComboBox2.Items.Add(q(i))
Next
'Else
'Dim objwriter As System.IO.StreamWriter
'objwriter = My.Computer.FileSystem.OpenTextFileWriter("E:\unknown.txt", True)
'File.AppendText("type:" And ComboBox1.Text And "make" & ComboBox2.Text And "model: " & ComboBox3.Text And "version: " And TextBox2.Text & "memory" And TextBox3.Text)
End If
End Sub
However,the code won't work to change what is in the 3rd box. I have repeated the following code for each option:
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.SelectedIndexChanged
Dim type As String = ComboBox1.SelectedItem
Dim make As String = ComboBox2.SelectedItem
Dim model As String = ComboBox3.SelectedItem
Dim version As String = TextBox2.Text
Dim memory As String = TextBox3.Text
Dim problem As String = TextBox4.Text
If type = "Phone" Then
If make = "apple" Then
ComboBox2.Items.Clear()
Dim file As New System.IO.StreamReader("E:\apple.txt")
For i = 1 To 20
q(i) = file.ReadLine() & vbNewLine
ComboBox3.Items.Add(q(i))
Next
ElseIf make = "samsung" Then
ComboBox2.Items.Clear()
Dim file As New System.IO.StreamReader("E:\samsung.txt")
For i = 1 To 20
q(i) = file.ReadLine() & vbNewLine
ComboBox3.Items.Add(q(i))
Next
ElseIf make = "htc" Then
ComboBox2.Items.Clear()
Dim file As New System.IO.StreamReader("E:\htc.txt")
For i = 1 To 20
q(i) = file.ReadLine() & vbNewLine
ComboBox3.Items.Add(q(i))
Next
ElseIf make = "Nokia" Then
ComboBox2.Items.Clear()
Dim file As New System.IO.StreamReader("E:\Nokia.txt")
For i = 1 To 20
q(i) = file.ReadLine() & vbNewLine
ComboBox3.Items.Add(q(i))
Next
ElseIf make = "Blackberry" Then
ComboBox2.Items.Clear()
Dim file As New System.IO.StreamReader("E:\blackberry.txt")
For i = 1 To 20
q(i) = file.ReadLine() & vbNewLine
ComboBox3.Items.Add(q(i))
Next
I have checked the obvious problems like putting the wrong text file names and capital letters etc, but can't get this to work whatever I do.
Does anyone know why the third combobox remains blank even when both conditions are met (both combobox1 and 2 have the right thing selected)? Any suggestion would be much appreciated.
Firstly I suspect that this code :-
Dim type As String = ComboBox1.SelectedItem.ToString
Dim make As String = ComboBox2.SelectedItem.ToString
Dim model As String = ComboBox3.SelectedItem.ToString
Dim version As String = TextBox2.Text
Dim memory As String = TextBox3.Text
Dim problem As String = TextBox4.Text
shouldn't be in each if your events. They should really be placed somewhere that executes after all the information has been chosen yes?
OK for a start paste this into a text file called "device type.txt"
Phone,E:\phone.txt
Tablet,E:\tablet.txt
Desktop Computer,E:\pc.txt
Laptop,E:\laptop.txt
Then edit your phones.txt file and the rest of the above files to match that format e.g this phone.txt file
Apple,E:\apple.txt
Samsung,E:\samsung.txt
Htc,E:\htc.txt
Nokia,E\nokia.txt
Blackberry,E:\blackberry.txt
and so on for each item that links to another file. For the last files in the tree - which I presume are the files containing a list of the models for each brand of phone, just leave them as a simple list. No commas or anything after each model.
Use this code to do the populating of each ComboBox
Private Sub PopulateComboBox(ByRef cboBox As ComboBox, ByVal itemSource As String)
RemoveHandler ComboBox1.SelectedIndexChanged, AddressOf ComboBox1_SelectedIndexChanged
RemoveHandler ComboBox2.SelectedIndexChanged, AddressOf ComboBox2_SelectedIndexChanged
RemoveHandler ComboBox3.SelectedIndexChanged, AddressOf ComboBox3_SelectedIndexChanged
Dim devices As New List(Of item)
Dim csvFlag As Boolean = False
cboBox.Items.Clear()
Using MyReader As New Microsoft.VisualBasic.
FileIO.TextFieldParser(itemSource)
If MyReader.ReadLine.Contains(",") Then csvFlag = True
End Using
Using MyReader As New Microsoft.VisualBasic.
FileIO.TextFieldParser(itemSource)
If csvFlag Then
MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters(",")
End If
Dim currentRow As String() = {"", ""}
While Not MyReader.EndOfData
Try
If csvFlag Then
currentRow = MyReader.ReadFields()
Dim tempItem As New item
tempItem.item = currentRow(0)
tempItem.fileName = currentRow(1)
devices.Add(tempItem)
Else
currentRow(0) = MyReader.ReadLine
Dim tempItem As New item
tempItem.item = currentRow(0)
tempItem.fileName = ""
devices.Add(tempItem)
End If
Catch ex As Microsoft.VisualBasic.
FileIO.MalformedLineException
MsgBox("Line " & ex.Message & "is not valid and will be skipped.")
End Try
End While
End Using
If csvFlag Then
cboBox.DataSource = devices
cboBox.DisplayMember = "item"
cboBox.ValueMember = "fileName"
Else
cboBox.DataSource = devices
cboBox.DisplayMember = "item"
cboBox.ValueMember = "item"
End If
AddHandler ComboBox1.SelectedIndexChanged, AddressOf ComboBox1_SelectedIndexChanged
AddHandler ComboBox2.SelectedIndexChanged, AddressOf ComboBox2_SelectedIndexChanged
AddHandler ComboBox3.SelectedIndexChanged, AddressOf ComboBox3_SelectedIndexChanged
End Sub
What it does is firstly check to see if the file being read is a comma-delimited file.
If it is delimited, it will read the file referred to in itemSource and expect a pair of values. The first value is what you see in the box(the DisplayMember), and the second value is what clicking on the box actually returns(the ValueMember)
If the file isn't comma-delimited, it will just read each line and add it to the combobox so that it acts normally (this will be important for the last files in the tree)
Next you need these methods for the ComboBoxes
Private Sub PopulateComboBox1()
PopulateComboBox(ComboBox1, "E:\device type.txt")
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
PopulateComboBox(ComboBox2, ComboBox1.SelectedValue.ToString)
End Sub
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
PopulateComboBox(ComboBox3, ComboBox2.SelectedValue.ToString)
End Sub
Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.SelectedIndexChanged
PopulateComboBox(ComboBox3, ComboBox2.SelectedValue.ToString)
End Sub
Call the method to populate Combobox1 possibly in the form's load event.

VB2010 read a csv in datagrid, update in grid and save to same csv

Created a procedure in VB2010 to read a csv-file in datagridviewer, update cells in grid and save to same csvfile
Opening the csvfile in the datagridviewer works fine,
Updating in the datagridviewer works fine also
But when I save the datagrid to a csv-file with the same name, I get an error message "The process Can not access the file because it is used by an other process".
But if I save it to an other filename it is ok.
Then I tried to copy the new file with the new filename back to the original filename.
I received still the same error message that I cant copy because the file is still in use.
Does anybody now how to solve this.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fName As String = ""
OpenFileDialog1.InitialDirectory = "H:\Data\2014\Software\VB2010\"
OpenFileDialog1.Filter = "CSV files (*.csv)|*.CSV"
OpenFileDialog1.FilterIndex = 2
OpenFileDialog1.RestoreDirectory = True
If (OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
fName = OpenFileDialog1.FileName
End If
Me.TextBox1.Text = fName
Dim TextLine As String = ""
Dim SplitLine() As String
DataGridView1.ColumnCount = 5
DataGridView1.Columns(0).Name = "Name"
DataGridView1.Columns(1).Name = "Gender"
DataGridView1.Columns(2).Name = "Age"
DataGridView1.Columns(3).Name = "Ranking"
DataGridView1.Columns(4).Name = "Date"
If System.IO.File.Exists(fName) = True Then
Dim objReader As New System.IO.StreamReader(fName)
Do While objReader.Peek() <> -1
TextLine = objReader.ReadLine()
SplitLine = Split(TextLine, ",")
Me.DataGridView1.Rows.Add(SplitLine)
Loop
Else
MsgBox("File Does Not Exist")
End If
End Sub
Private Sub SaveGridDataInFile(ByRef fName As String)
'method called by button2
Dim I As Integer = 0
Dim j As Integer = 0
Dim cellvalue$
Dim rowLine As String = ""
Try
Dim objWriter As New System.IO.StreamWriter(fName, True)
For j = 0 To (DataGridView1.Rows.Count - 2)
For I = 0 To (DataGridView1.Columns.Count - 1)
If Not TypeOf DataGridView1.CurrentRow.Cells.Item(I).Value Is DBNull Then
cellvalue = DataGridView1.Item(I, j).Value
Else
cellvalue = ""
End If
rowLine = rowLine + cellvalue + ","
Next
objWriter.WriteLine(rowLine)
rowLine = ""
Next
objWriter.Close()
objWriter = Nothing
MsgBox("Text written to file")
Catch e As Exception
MessageBox.Show("Error occured while writing to the file." + e.ToString())
Finally
FileClose(1)
End Try
Call copy_file()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'çall method SaveGridDataInFile
SaveGridDataInFile(Me.TextBox1.Text)
' FileCopy("H:\Data\2014\Software\VB2010\datagr_ex2.csv", "H:\Data\2014\Software\VB2010\datagr_ex.csv")
End Sub
Sub copy_file()
Dim FileToDelete As String
FileToDelete = "H:\Data\2014\Software\VB2010\datagr_ex.csv"
If System.IO.File.Exists(FileToDelete) = True Then
System.IO.File.Delete(FileToDelete)
MsgBox("File Deleted")
End If
FileCopy("H:\Data\2014\Software\VB2010\datagr_ex2.csv", "H:\Data\2014\Software\VB2010\datagr_ex.csv")
End Sub
My guess is you need to close the StreamReader you use to load the file before you can reopen the file to save it. The StreamReader class implements IDisposable so you can use VB.Net's Using Statement to automatically close the file when you're finished reading, i.e.
If System.IO.File.Exists(fName) = True Then
Using objReader As New System.IO.StreamReader(fName)
Do While objReader.Peek() <> -1
TextLine = objReader.ReadLine()
SplitLine = Split(TextLine, ",")
Me.DataGridView1.Rows.Add(SplitLine)
Loop
End Using
Else
MsgBox("File Does Not Exist")
End If

how to filter a datagridview when a database is not being used

I am able get the contents of a csv file to read into DataGridView1, but I am having trouble filtering the data from textbox2. I tried different things I have found online, but nothing has worked so far. this is what i have:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim fName As String = ""
OpenFileDialog1.InitialDirectory = "C:\"
OpenFileDialog1.Filter = "CSV Files (*.csv)|*.csv"
OpenFileDialog1.FilterIndex = 2
OpenFileDialog1.RestoreDirectory = True
If (OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
fName = OpenFileDialog1.FileName
End If
Me.TextBox1.Text = fName
GetData(fName, DataGridView1, True)
End Sub
Private Sub GetData(ByVal Path As String, ByRef DG As DataGridView, Optional ByVal NoHeader As Boolean = False)
Dim Fields() As String
Dim Start As Integer = 1
If NoHeader Then Start = 0
If Not File.Exists(Path) Then
Return
End If
Dim Lines() As String = File.ReadAllLines(Path)
Lines(0) = Lines(0).Replace(Chr(34), "")
Fields = Lines(0).Split(",")
If NoHeader Then
For I = 1 To Fields.Count - 1
Fields(I) = Str(I)
Next
End If
For Each Header As String In Fields
DG.Columns.Add(Header, Header)
Next
For I = Start To Lines.Count - 1
Lines(I) = Lines(I).Replace(Chr(34), "")
Fields = Lines(I).Split(",")
DG.Rows.Add(Fields)
Next
End Sub
I just want to be able to filter say column 5 (no column headers in csv file) by typing something in textbox2. Any help would be greatly appreciated. Thank you
Don't add the values to a DGV, but instead use a DataTable then just make a query on that. Example considers you have a combobox for some filter choices - they are other ways to get this to depending on your needs. This method requires you to have headers though.
Private dt As New DataTable
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim fName As String = ""
OpenFileDialog1.InitialDirectory = "C:\"
OpenFileDialog1.Filter = "CSV Files (*.csv)|*.csv"
OpenFileDialog1.FilterIndex = 2
OpenFileDialog1.RestoreDirectory = True
If (OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
fName = OpenFileDialog1.FileName
End If
Me.TextBox1.Text = fName
LoadData(fName)
FilterData(combobox1.Text, "some column name")
End Sub
Private Sub LoadData(ByVal Path As String)
Dim Fields() As String
Dim Start As Integer = 1
If NoHeader Then Start = 0
If Not File.Exists(Path) Then
Return
End If
Dim Lines() As String = File.ReadAllLines(Path)
Lines(0) = Lines(0).Replace(Chr(34), "")
Fields = Lines(0).Split(",")
For I = 1 To Fields.Count - 1
Fields(I) = Str(I)
Next
For Each Header As String In Fields
dt.Columns.Add(Header, Header)
Next
For I = Start To Lines.Count - 1
Lines(I) = Lines(I).Replace(Chr(34), "")
Fields = Lines(I).Split(",")
dt.Rows.Add(Fields)
Next
End Sub
Private Sub FilterData(filter As String, columnName as string)
Dim query = From dr As DataRow In dt.Rows Where dr(columnName).ToString = filter
DGV.DataSource = query
End Sub

Issue with overlapping batch file runs

I am having an issue in my script with things running sequentially. I have an initial script to decompile an swf. A second that searches for one string in one of the decompiled files and a third for recompiling into a new swf.
How can I make each process wait until it completes before the next is started?
I am also having trouble with making the second script actually work. It would be nice if I could display something about what it replaced after it finished.
Here is my script so far:
Imports System.Net
Public Class Form3
Private Sub Button7_Click(sender As System.Object, e As System.EventArgs) Handles Button7.Click
If TextBox4.Text = "" Then
MessageBox.Show("Please select a directory")
Else
Dim fd As OpenFileDialog = New Ope
nFileDialog()
Dim strFileName As String
fd.Title = "Open File Dialog"
fd.InitialDirectory = TextBox1.Text
fd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
fd.FilterIndex = 2
fd.RestoreDirectory = True
If fd.ShowDialog() = DialogResult.OK Then
strFileName = fd.FileName
If InStr(strFileName, ".swf") <> 0 Then
TextBox2.Text = strFileName
Else
MessageBox.Show("You have to pick a .swf silly...")
End If
End If
End If
End Sub
Private Sub Button8_Click(sender As System.Object, e As System.EventArgs) Handles Button8.Click
Me.Close()
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim Folder = TextBox4.Text & "\HEXED"
If TextBox2.Text = "" Then
MessageBox.Show("You have to pick a .swf silly...")
Else
If My.Computer.FileSystem.DirectoryExists(Folder) Then
My.Computer.FileSystem.DeleteDirectory(Folder, FileIO.DeleteDirectoryOption.DeleteAllContents)
End If
My.Computer.FileSystem.CopyDirectory("C:\Users\Matt\Documents\My_Games\ROTMG\ShadyGamer\WindowsApplication1\WindowsApplication1\RABCDasm", Folder)
My.Computer.FileSystem.CopyFile(TextBox2.Text, Folder & "\client.swf", True)
Dim FILE_NAME As String = Folder & "\decompile.bat"
Dim i As Integer
Dim aryText(4) As String
aryText(0) = "cd " & Folder
aryText(1) = "swfdecompress client.swf"
aryText(2) = "abcexport client.swf"
aryText(3) = "rabcdasm client-1.abc"
Dim objWriter As New System.IO.StreamWriter(FILE_NAME, False)
For i = 0 To 3
objWriter.WriteLine(aryText(i))
Next
objWriter.Close()
Dim psi As New ProcessStartInfo(Folder & "\decompile.bat")
psi.RedirectStandardError = True
psi.RedirectStandardOutput = True
psi.CreateNoWindow = False
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.UseShellExecute = False
Dim decompile As New Process
Process.Start(psi)
MessageBox.Show("Click Step 2")
Button1.Visible = False
Button3.Visible = True
End If
End Sub
Private Sub TextBox4_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox4.TextChanged
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim MyFolderBrowser As New System.Windows.Forms.FolderBrowserDialog
MyFolderBrowser.Description = "Select the Folder"
MyFolderBrowser.ShowNewFolderButton = False
Dim dlgResult As DialogResult = MyFolderBrowser.ShowDialog()
If dlgResult = Windows.Forms.DialogResult.OK Then
TextBox4.Text = MyFolderBrowser.SelectedPath
End If
End Sub
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
Dim Folder = TextBox4.Text & "\HEXED"
Const quote As String = """"
Dim MyFile As String = Folder & "\client-1\com\company\assembleegameclient\parameters\Parameters.class.asasm"
Replace(MyFile, quote & TextBox1.Text & quote, quote & TextBox3.Text & quote)
MessageBox.Show("Click Step 3")
Button3.Visible = False
Button4.Visible = True
End Sub
Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
Dim Folder = TextBox4.Text & "\HEXED"
Dim FILE_NAME2 As String = Folder & "\recompile.bat"
Dim j As Integer
Dim aryText2(4) As String
aryText2(0) = "cd " & Folder
aryText2(1) = "rabcasm client-1\client-1.main.asasm"
aryText2(2) = "abcreplace client.swf 1 client-1\client-1.main.abc"
Dim objWriter2 As New System.IO.StreamWriter(FILE_NAME2, False)
For j = 0 To 2
objWriter2.WriteLine(aryText2(j))
Next
objWriter2.Close()
Dim ps As New ProcessStartInfo(Folder & "\recompile.bat")
ps.RedirectStandardError = True
ps.RedirectStandardOutput = True
ps.CreateNoWindow = False
ps.WindowStyle = ProcessWindowStyle.Hidden
ps.UseShellExecute = False
Dim recompile As Process = Process.Start(ps)
My.Computer.FileSystem.CopyFile(Folder & "\client.swf", TextBox4.Text & "\hexed.swf", True)
End Sub
End Class
You can use process.WaitForExit() - msdn here - http://msdn.microsoft.com/en-us/library/system.diagnostics.process.waitforexit.aspx
Update
You'll need to change the way you start the process to use this:
Dim ps As New System.Diagnostics.Process()
Dim psi As New System.Diagnostics.ProcessStartInfo(folder & "\decompile.bat")
psi.RedirectStandardError = True
psi.RedirectStandardOutput = True
psi.CreateNoWindow = False
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.UseShellExecute = False
ps.StartInfo = psi
ps.Start()
ps.WaitForExit()