Issue with overlapping batch file runs - vb.net

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()

Related

Async FileDownloader that compare files with hash codes from a list

I want to make a launcher for my game. The launcher should make a check for the files when I click on the "Play" button.
I want to check the hash codes (for example the patch files) that are already installed and the patch files on my server. The files that I want to check should be in a .txt file list.
When the code is not a match with the files on the server, I want to overwrite the local files.
After downloading the file the next one should start until all files are downloaded. I want to show progress with a ProgressBar.
I tested that with only one file that is hard coded. With more files I didn't find a solution.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
Dim URL As String = "http://213.196.154.200/downloads/WOTLK/WOTLK/Data/patch-3.MPQ"
Application.DoEvents()
hhtpclient.DownloadFileAsync(New Uri(URL), Pfad + "/data/patch-3.mpq", Stopwatch.StartNew)
Application.DoEvents()
Label2.Visible = True
Label3.Visible = True
ProgressBar1.Visible = True
Button2.Visible = True
Button1.Enabled = False
Label5.Visible = False
Catch ex As Exception
MsgBox("Download fehlgeschlagen!" & vbNewLine & ex.ToString, MsgBoxStyle.Critical, "Error")
End
End Try
End Sub
Private Sub hhtpclient_DownloadFileCompleted(sender As Object, e As AsyncCompletedEventArgs) Handles hhtpclient.DownloadFileCompleted
If Abbort = "0" Then
Dim customMsgbox1 = New Form2("Download erfolgreich!")
customMsgbox1.btnCustomNo.Visible = False
customMsgbox1.btnCustomYes.Location = New Point(179, 229)
customMsgbox1.ShowDialog()
Label2.Visible = False
Label3.Visible = False
ProgressBar1.Visible = False
Abbort = "0"
PictureBox8.Visible = False
Else
Dim customMsgbox2 = New Form2("Download abgebrochen!")
customMsgbox2.btnCustomNo.Visible = False
customMsgbox2.btnCustomYes.Location = New Point(179, 229)
customMsgbox2.ShowDialog()
Label2.Visible = False
Label3.Visible = False
ProgressBar1.Visible = False
Abbort = "0"
End If
Button2.Visible = False
Button1.Enabled = True
Label5.Visible = True
End Sub
Private Sub hhtpclient_DownloadProgressChanged(sender As Object, e As DownloadProgressChangedEventArgs) Handles hhtpclient.DownloadProgressChanged
Dim SW As Stopwatch
SW = Stopwatch.StartNew
Me.ProgressBar1.Value = e.ProgressPercentage
Dim totalbytes As Double = e.TotalBytesToReceive
Dim bytes As Double = e.BytesReceived
If totalbytes >= "1000000000" Then
Label2.Text = Math.Round(bytes / 1024000000.0, 2) & " / " & Math.Round(totalbytes / 1024000000.0, 2) & " GB"
ElseIf totalbytes >= "1000000" Then
Label2.Text = Math.Round(bytes / 1024000.0, 2) & " / " & Math.Round(totalbytes / 1024000.0, 2) & " MB"
End If
If bytes >= "1000000" Then
Label3.Text = (e.BytesReceived / 1024000.0 / (DirectCast(e.UserState, Stopwatch).ElapsedMilliseconds / 1000.0#)).ToString("0.0") & " MB/s"
ElseIf bytes >= "1000" Then
Label3.Text = (e.BytesReceived / 1024.0 / (DirectCast(e.UserState, Stopwatch).ElapsedMilliseconds / 1000.0#)).ToString("0.0") & " KB/s"
End If
End Sub
I tried this code. The Files will download but I don't how to add a ProgressBar and the application freeze when the files downloading:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'===Downloadvorgang===
Dim Einl() As String = Split(My.Computer.FileSystem.ReadAllText("D:/Test.txt"), vbNewLine)
For i As Long = 0 To UBound(Einl)
Dim l() As String = Split(Einl(i), ";")
Dim url As String = l(0)
Dim dateiname As String = l(1)
My.Computer.Network.DownloadFile(url, "D:/" & dateiname, "", "", False, 100000, True)
Next
MsgBox("Die Dateien wurden erfolgreich heruntergeladen!", MsgBoxStyle.OkOnly, "Download beendet")
'===Downloadvorgang Ende====
End Sub

Unable to cancel application

I have an application that copies files into different directories. As the application is running if I click the BtnExit_Click button nothing happens. I'm only able to exit out of the app after it has run through all the files to copy.
This is my code
Private Sub BtnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
BackgroundWorker1.CancelAsync()
Me.Close()
End Sub
Background Worker:
Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
Me.txtImgCount.Text = iCount
Me.txtImgCount.Update()
Me.fileCount.Text = fCount
Me.fileCount.Update()
Me.txtTotal.Update()
Me.Label8.Text = statusText
Me.Label8.Update()
Application.DoEvents()
Try
Me.RichTextBox1.Text &= (fileFilename)
Application.DoEvents()
Catch ei As DivideByZeroException
Debug.WriteLine("Exception caught: {0}", ei)
Finally
End Try
Try
Me.RichTextBox1.Text &= (imgFilename)
Application.DoEvents()
Catch ea As DivideByZeroException
Debug.WriteLine("Exception caught: {0}", ea)
Finally
End Try
End Sub
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
RunCopyFiles()
End Sub
Private Sub RunCopyFiles()
BackgroundWorker1.WorkerReportsProgress = True
Dim sFileToFind As String
Dim location As String
'Dim File As String
statusText = "Initiating"
status = "Initiating..."
'Directory Files are located in
location = txtFolderPath.Text
'Directory ICN files are located in
imgLocation = txtSearchICN.Text
'Directory files are to copied into
MoveLocation = CopyToPath
createImgFldr = MoveLocation & "\Figures"
createReportFldr = MoveLocation & "\Reports"
createXMLFldr = MoveLocation & "\XML files"
'Create Figures Folder
If Not IO.Directory.Exists(createImgFldr) Then
IO.Directory.CreateDirectory(createImgFldr)
' MsgBox("folder created" & createFolder)
End If
'Create Reports folder
If Not IO.Directory.Exists(createReportFldr) Then
IO.Directory.CreateDirectory(createReportFldr)
'MsgBox("folder created" & createReportFldr)
End If
'Create XML folder
If Not IO.Directory.Exists(createXMLFldr) Then
IO.Directory.CreateDirectory(createXMLFldr)
' MsgBox("folder created" & createFolder)
End If
'Text file with list of file names
Dim filesToCopy = txtFileName.Text
orphanedFiles = MoveLocation & "\Reports\OrphanedFilesItems.txt"
' Create or overwrite the file.
System.IO.File.Create(orphanedFiles).Dispose()
ListofGraphics = MoveLocation & "\Reports\ListOfGraphics.txt"
' Create or overwrite the file.
System.IO.File.Create(ListofGraphics).Dispose()
Dim removDupBuildLog = MoveLocation & "\Reports\RemvoeDup.txt"
Dim ListLog = MoveLocation & "\Reports\ListOfGraphics.txt"
ListofFiles = MoveLocation & "\Reports\ListOfFiles.txt"
' Create or overwrite the file.
System.IO.File.Create(ListofFiles).Dispose()
MissingFiles = MoveLocation & "\Reports\MissingGraphicList.txt"
' Create or overwrite the file.
System.IO.File.Create(MissingFiles).Dispose()
Dim FILE_NAME As String
FILE_NAME = txtFileName.Text
Dim fileNames = System.IO.File.ReadAllLines(FILE_NAME)
status = "Copying SGML\XML Files"
statusText = "Copying SGML\XML Files..."
fCount = 0
For i = 0 To fileNames.Count() - 1
Dim fileName = fileNames(i)
sFileToFind = location & "\" & fileName & "*.*"
Dim paths = IO.Directory.GetFiles(location, fileName, IO.SearchOption.AllDirectories)
If Not paths.Any() Then
System.IO.File.AppendAllText(orphanedFiles, fileName & vbNewLine)
Else
For Each pathAndFileName As String In paths
If System.IO.File.Exists(pathAndFileName) = True Then
Dim sRegLast = pathAndFileName.Substring(pathAndFileName.LastIndexOf("\") + 1)
Dim toFileLoc = System.IO.Path.Combine(createXMLFldr, sRegLast)
Dim moveToFolder = System.IO.Path.Combine(MoveLocation, "XML files", sRegLast)
'if toFileLoc = XML file exists move it into the XML files folder
If System.IO.File.Exists(toFileLoc) = False Then
System.IO.File.Copy(pathAndFileName, moveToFolder)
System.IO.File.AppendAllText(ListofFiles, sRegLast & vbNewLine)
Application.DoEvents()
fileFilename = (fileName) + vbCrLf
fCount = fCount + 1
'fileCount.Text = fCount
End If
End If
Next
End If
BackgroundWorker1.ReportProgress(100 * (i + 1) / fileNames.Count)
Next
CreateGraphicsFunction()
GetImages()
Application.UseWaitCursor = False
Application.DoEvents()
End Sub
If you look at the code example in the documentation for the BackgroundWorker Class you will see that it checks the worker.CancellationPending property every time through the loop.
So you'll need a couple of changes:
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)
RunCopyFiles(worker, e)
End Sub
Private Sub RunCopyFiles(worker As BackgroundWorker, e As DoWorkEventArgs)
... other code here
For Each pathAndFileName As String In paths
... other code here
If worker.CancellationPending Then
e.Cancel = True
Exit Sub
End If
Next
Maybe put another check just after the ReportProgress(...) too.
Also, you will need to set backgroundWorker1.WorkerSupportsCancellation = True.
The Application.UseWaitCursor = False should not be in the worker - put it in the code that calls backgroundWorker1.RunWorkerAsync().
As LarsTech wrote in a comment, you should remove all calls to Application.DoEvents(): problems with it are listed in Use of Application.DoEvents().
Finally, make sure that you are using Option Strict On.

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

ProgressBar not updating using a For Each loop

I'm copying all the .avi and .png files from one folder into another:
Private Sub CopierSend_Button_Click(sender As Object, e As EventArgs) Handles CopierSend_Button.Click
If MessageBox.Show("Click OK to send media or just Cancel.", "Media Copier", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = DialogResult.OK Then
For Each foundFile As String In My.Computer.FileSystem.GetFiles(FrapsFolder_, Microsoft.VisualBasic.FileIO.SearchOption.SearchTopLevelOnly, "*.avi", "*.png")
Dim foundFileInfo As New System.IO.FileInfo(foundFile)
My.Computer.FileSystem.CopyFile(foundFile, DestFolder_ & foundFileInfo.Name, Microsoft.VisualBasic.FileIO.UIOption.OnlyErrorDialogs, Microsoft.VisualBasic.FileIO.UICancelOption.DoNothing)
Next
Else
'Nothing Yet
End If
End Sub
I want to add a ProgressBar which will count every time a file is copied, so I added this code before the For Each loop:
Dim file1() As String = IO.Directory.GetFiles(FrapsFolder_, "*.avi")
Dim file2() As String = IO.Directory.GetFiles(FrapsFolder_, "*.png")
Dim files = file1.Length + file2.Length
Copier_ProgressBar.Step = 1
Copier_ProgressBar.Maximum = files
And added this code inside the For Each loop:
Copier_ProgressBar.Value += 1
Here is all of my code:
Private Sub CopierSend_Button_Click(sender As Object, e As EventArgs) Handles CopierSend_Button.Click
If MessageBox.Show("Click OK to send media or just Cancel.", "Media Copier", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = DialogResult.OK Then
Dim file1() As String = IO.Directory.GetFiles(FrapsFolder_, "*.avi")
Dim file2() As String = IO.Directory.GetFiles(FrapsFolder_, "*.png")
Dim files = file1.Length + file2.Length
Copier_ProgressBar.Step = 1
Copier_ProgressBar.Maximum = files
For Each foundFile As String In My.Computer.FileSystem.GetFiles(FrapsFolder_, Microsoft.VisualBasic.FileIO.SearchOption.SearchTopLevelOnly, "*.avi", "*.png")
Dim foundFileInfo As New System.IO.FileInfo(foundFile)
My.Computer.FileSystem.CopyFile(foundFile, DestFolder_ & foundFileInfo.Name, Microsoft.VisualBasic.FileIO.UIOption.OnlyErrorDialogs, Microsoft.VisualBasic.FileIO.UICancelOption.DoNothing)
Copier_ProgressBar.Value += 1
Next
Else
'Nothing Yet
End If
End Sub
The ProgressBar updates, but only after all the files have been copied instead of updating in real time. Any idea?
As it stands it looks like the ProgressBar doesn't do anything until after all the files have copied. That isn't strictly true. Instead your UI is not updating.
Instead you should look into using a BackgroundWoker to report progress. Something like this should do the trick:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'This can also be set using the Designer
BackgroundWorker1.WorkerReportsProgress = True
End Sub
Private Sub CopierSend_Button_Click(sender As Object, e As EventArgs) Handles CopierSend_Button.Click
If MessageBox.Show("Click OK to send media or just Cancel.", "Media Copier", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = DialogResult.OK Then
Dim file1() As String = IO.Directory.GetFiles(FrapsFolder_, "*.avi")
Dim file2() As String = IO.Directory.GetFiles(FrapsFolder_, "*.png")
Dim files As Integer = file1.Length + file2.Length
Copier_ProgressBar.Step = 1
Copier_ProgressBar.Maximum = files
BackgroundWorker1.RunWorkerAsync()
End If
End Sub
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
For Each foundFile As String In My.Computer.FileSystem.GetFiles(FrapsFolder_, Microsoft.VisualBasic.FileIO.SearchOption.SearchTopLevelOnly, "*.avi", "*.png")
Dim foundFileInfo As New System.IO.FileInfo(foundFile)
My.Computer.FileSystem.CopyFile(foundFile, DestFolder_ & foundFileInfo.Name, Microsoft.VisualBasic.FileIO.UIOption.OnlyErrorDialogs, Microsoft.VisualBasic.FileIO.UICancelOption.DoNothing)
BackgroundWorker1.ReportProgress(Copier_ProgressBar.Value + 1)
Next
End Sub
Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
Copier_ProgressBar.Value = e.ProgressPercentage
End Sub
As an additional note, for best practice, I would consider using Path.Combine instead of concatenating strings together:
My.Computer.FileSystem.CopyFile(foundFile, Path.Combine(DestFolder_, foundFileInfo.Name), Microsoft.VisualBasic.FileIO.UIOption.OnlyErrorDialogs, Microsoft.VisualBasic.FileIO.UICancelOption.DoNothing)

Binary Reader and allowed characters

I have a problem.
Now program working like this:
Reading binary file bytes. &H1E and &H1F Allowed characters only :A123456789
If in file is B or C or D or E or F....... textbox1 = bad file
That's working. Now I want to add verification in &H10.
Allowed characters only 26
If other characters textbox1 = bad file
Imports System.IO
Imports System.IO.SeekOrigin
Public Class Form1
Dim charactersAllowed As String = "A123456789"
Dim swap As String = "26"
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim OFD As New OpenFileDialog
Dim fullFile() As Byte
With OFD
.Filter = "Binary files (*.bin)|*.bin"
End With
If OFD.ShowDialog = Windows.Forms.DialogResult.OK Then
fullFile = File.ReadAllBytes(OFD.FileName)
TextBox1.AppendText(fullFile(&H1E).ToString("X2") & " ")
TextBox1.AppendText(fullFile(&H1F).ToString("X2"))
TextBox4.AppendText(fullFile(&H10).ToString("X2"))
End If
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Dim theText As String = TextBox1.Text
Dim Letter As String
Dim SelectionIndex As Integer = TextBox1.SelectionStart
Dim Change As Integer
For x As Integer = 0 To TextBox1.Text.Length - 1
Letter = TextBox1.Text.Substring(x, 1)
If charactersAllowed.Contains(Letter) = False Then
theText = theText.Replace(Letter, String.Empty)
Change = 1
End If
Next
TextBox1.Text = theText
TextBox1.Select(SelectionIndex - Change, 0)
End Sub
Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs) Handles TextBox4.TextAlignChanged
Dim check As String = TextBox4.Text
Dim check2 As String
Dim check3 As Integer = TextBox4.SelectionStart
Dim check4 As Integer
For x As Integer = 0 To TextBox4.Text.Length - 1
check2 = TextBox4.Text.Substring(x, 1)
If swap.Contains(check2) = False Then
check = check.Replace(check2, String.Empty)
check4 = 1
End If
Next
TextBox1.Text = check
TextBox1.Select(check3 - check4, 0)
End Sub
Hard to decode, but an obvious approach is to prevent editing when the byte has the wrong value:
If OFD.ShowDialog = Windows.Forms.DialogResult.OK Then
fullFile = File.ReadAllBytes(OFD.FileName)
If fullFile(&H10) <> 26 Then
TextBox1.Text = "Bad file"
TextBox1.Enabled = False
TextBox4.Enabled = False
Else
TextBox1.Enabled = True
TextBox4.Enabled = True
'' etc...
End If
End If