I want to write text from text boxes to a text file.
The code writes the first line of the text file. When I clear the text boxes to write other values, what was previously written disappears and is replaced by the new values.
How do I get the new set of values to be written under the previous?
Dim path As String = TextBox1.Text & ".txt"
path = "C:\Users\USER\Desktop\" & path
Dim studentno As Integer = TextBox2.Text
Dim name As String = TextBox3.Text
Dim surname As String = TextBox4.Text
Dim subject As String = TextBox8.Text
Dim indv As Integer = TextBox5.Text
Dim grp As Integer = TextBox6.Text
Dim test As Integer = TextBox7.Text
If System.IO.File.Exists(path) = True Then
Dim sw As New System.IO.StreamWriter(path)
sw.WriteLine(studentno & "," & name & "," & surname & "," & subject & "," & indv & "," & grp & "," & test)
sw.Close()
MessageBox.Show("Text written to file.", "Note", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("File Does Not Exist.", "Note", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
This is the code i have to create the file, it works perfectly so this is fine.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim path As String = TextBox1.Text & ".txt"
path = "C:\Users\USER\Desktop\" & path
If String.IsNullOrEmpty(TextBox1.Text) = True Then
MessageBox.Show("Textbox Empty", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf Not File.Exists(path) Then
File.Create(path).Dispose()
MessageBox.Show("File created.", "Note", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("File already exists.", "Note", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Related
This is my first vb.net program, so please bear with me if my question is very mediocre.
Before mentioning my problem, the mechanism of my accounting program is that if the user would input data into the datagridview and export it, so that when he restarts the program, he can import the exported data.
I have imported this .csv file to my datagridview
The problem is that when I have imported it, only column texts would appear like this.
This is the export code that I have used to create the .csv file.
Private Sub ExportToExcelToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExportToExcelToolStripMenuItem.Click
Dim msg1 = "Export Successful"
Dim title = "Excel Export"
MsgBox(msg1, , title)
Try
Dim iexport1 As String = ""
Dim eexport1 As String = ""
For Each C As DataGridViewColumn In Income.Columns
iexport1 &= """" & C.HeaderText & ""","
Next
iexport1 = iexport1.Substring(0, iexport1.Length - 1)
iexport1 &= Environment.NewLine
For Each R As DataGridViewRow In Income.Rows
For Each C As DataGridViewCell In R.Cells
If Not C.Value Is Nothing Then
iexport1 &= """" & C.Value.ToString & ""","
Else
iexport1 &= """" & "" & ""","
End If
Next
iexport1 = iexport1.Substring(0, iexport1.Length - 1)
iexport1 &= Environment.NewLine
Next
For Each C As DataGridViewColumn In Expense.Columns
eexport1 &= """" & C.HeaderText & ""","
Next
eexport1 = eexport1.Substring(0, eexport1.Length - 1)
eexport1 &= Environment.NewLine
For Each R As DataGridViewRow In Expense.Rows
For Each C As DataGridViewCell In R.Cells
If Not C.Value Is Nothing Then
eexport1 &= """" & C.Value.ToString & ""","
Else
eexport1 &= """" & "" & ""","
End If
Next
eexport1 = eexport1.Substring(0, eexport1.Length - 1)
eexport1 &= Environment.NewLine
Next
Dim tw As IO.TextWriter = New IO.StreamWriter(path:="C:\Users\S2009516\Desktop\JanuaryIncome.CSV")
tw.Write(iexport1)
tw.Close()
Dim tw2 As IO.TextWriter = New IO.StreamWriter(path:="C:\Users\S2009516\Desktop\JanuaryExpense.CSV")
tw2.Write(eexport1)
tw2.Close()
Catch ex As Exception
End Try
End Sub
And this is the one I have used for importing csv file.
Private Sub ImportFromExcelToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ImportFromExcelToolStripMenuItem.Click
Dim expenseload1 As String = "C:\Users\S2009516\Desktop\JanuaryExpense.CSV"
Dim incomeload1 As String = "C:\Users\S2009516\Desktop\JanuaryIncome.CSV"
Try
Dim expensereader1 As New StreamReader(expenseload1, Encoding.Default)
Dim incomereader1 As New StreamReader(incomeload1, Encoding.Default)
Dim eline As String = ""
Dim iline As String = ""
Do
eline = expensereader1.ReadLine
iline = incomereader1.ReadLine
If eline Is Nothing Then Exit Do
If iline Is Nothing Then Exit Do
Dim words() As String = eline.Split(",")
Dim words2() As String = iline.Split(",")
Income.Rows.Add("")
Expense.Rows.Add("")
For ix As Integer = 0 To 3
Me.Income.Rows(Income.Rows.Count - 1).Cells(ix).Value = words2(ix)
Me.Expense.Rows(Income.Rows.Count - 1).Cells(ix).Value = words(ix)
Next
Loop
expensereader1.Close()
incomereader1.Close()
Catch ex As Exception
End Try
End Sub
I have no clue on why this is happening... I have followed all the steps in the tutorial video.. Please save my soul... I have been stuck with this for 2 days already.
Can you help you find to any solution? Because it's output error message as "Could not save; currently locked by another user."
Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
If txtPassword.Text.ToString() = "" Then
MsgBox("do not empty")
ElseIf txtUsername.Text.ToString() = "" Then
MsgBox("do not empty")
ElseIf txtSurName.Text.ToString() = "" Then
MsgBox("do not empty")
ElseIf txtGivenName.Text.ToString() = "" Then
MsgBox("do not empty")
ElseIf txtMobile.Text.ToString() = "" Then
MsgBox("do not empty")
ElseIf txtAddress.Text.ToString() = "" Then
MsgBox("do not empty")
ElseIf txtIC.Text.ToString() = "" Then
MsgBox("do not empty")
Else
Dim gender As String
If RadioButton1.Checked = True Then
gender = "Male"
Else
gender = "Female"
End If
Dim fsr As New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read)
Dim br As New BinaryReader(fsr)
Dim imgbuffer(fsr.Length) As Byte
br.Read(imgbuffer, 0, fsr.Length)
fsr.Close()
Using con As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source =..\VisitorPass.accdb")
con.Open()
Dim sql As String
sql = "Update HouseOwner set [Password]='" & txtPassword.Text & "',AccountName='" & txtUsername.Text & "',Houseowner_Surname='" & txtSurName.Text & "',Houseowner_GivenName='" & txtGivenName.Text & "',[IC]='" & txtIC.Text & "',[Mobile_No]='" & txtMobile.Text & "',Houseowner_address='" & txtAddress.Text & "',Gender='" & gender & "',[Photo]= #imgfile where [ID]=" & lblID.Text & ""
Using cmd As New OleDbCommand(sql, con)
cmd.Parameters.AddWithValue("#imgfile", imgbuffer)
cmd.ExecuteNonQuery()
MsgBox("Profile is updated")
con.Close()
End Using
End Using
Me.Close()
End If
End Sub
I'm trying to write a code in which users can add files to a listview. These files must then be moved to a user specified location. What I can't get to work is the filepath of files that are added to the listview. Here's the code for moving the file:
sPath = My.Settings.DefaultPath & ComboBox1.Text & "\" & ComboBox2.Text & "\"
If txtOnderwerp.Text = "" Then
If ComboBox3.Text = "Make your choice..." Then
MsgBox("Select subject!", MsgBoxStyle.Information)
Else
Try
For Each item As ListViewItem In ListView1.Items
My.Computer.FileSystem.CopyFile(item, sPath & ComboBox3.Text & "\" & item.Text, FileIO.UIOption.AllDialogs)
MsgBox("Copy succesfull.", MsgBoxStyle.Information)
ListView1.Items.Clear()
Me.Close()
Next
Catch ex As Exception
MessageBox.Show("Error copying file: " & ex.Message)
End Try
End If
End If
The code above states an error because 'item' is not a string for the FilsSystem.Copy command. Users can add files to a listview with this code:
Using ofd As New OpenFileDialog
ofd.Multiselect = True
If ofd.ShowDialog = DialogResult.OK Then
For Each fn As String In ofd.FileNames
Dim fi As New IO.FileInfo(fn)
Dim icons As Icon = SystemIcons.WinLogo
Dim li As New ListViewItem(fi.Name, 1)
If Not (ImageList1.Images.ContainsKey(fi.Extension)) Then
icons = System.Drawing.Icon.ExtractAssociatedIcon(fi.FullName)
ImageList1.Images.Add(fi.Extension, icons)
End If
icons = Icon.ExtractAssociatedIcon(fi.FullName)
ImageList1.Images.Add(icons)
ListView1.Items.Add(fi.Name, fi.Extension)
Next
End If
End Using
Answer thanks to advice from Andrew Mortimer.
Code for ListView:
Dim str(2) As String
Dim itm As ListViewItem
Using ofd As New OpenFileDialog
ofd.Multiselect = True
If ofd.ShowDialog = DialogResult.OK Then
For Each fn As String In ofd.FileNames
Dim fi As New IO.FileInfo(fn)
Dim icons As Icon = SystemIcons.WinLogo
'Dim li As New ListViewItem(fi.Name, 1)
If Not (ImageList1.Images.ContainsKey(fi.Extension)) Then
icons = System.Drawing.Icon.ExtractAssociatedIcon(fi.FullName)
ImageList1.Images.Add(fi.Extension, icons)
End If
str(0) = fi.Name
str(1) = fi.FullName
icons = Icon.ExtractAssociatedIcon(fi.FullName)
ImageList1.Images.Add(icons)
itm = New ListViewItem(str)
ListView1.Items.Add(itm)
Next
End If
End Using
Code for copying items in listview:
Dim str As String
Dim copyfilename As String
Dim NewDir As String
Try
NewDir = My.Settings.DefaultPath & ComboBox1.Text & "\" & ComboBox2.Text & "\" & txtOnderwerp.Text
My.Computer.FileSystem.CreateDirectory(NewDir)
For Each item As ListViewItem In ListView1.Items
copyfilename = item.Text
str = item.SubItems.Item(1).Text
My.Computer.FileSystem.CopyFile(str, NewDir & "\" & copyfilename)
MsgBox("Kopiƫren is gelukt.", MsgBoxStyle.Information)
ListView1.Items.Clear()
Me.Close()
Next
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message)
End Try
I was making a mod installer for a Minecraft community, when I ended with this problem:
Here's my code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Button1.Enabled = False
Button2.Enabled = False
ComboBox1.Enabled = False
Button1.Text = "DOWNLOADING... DO NOT QUIT!"
Dim selected As String
Dim issel As Boolean
issel = False
selected = ComboBox1.SelectedItem
If selected = "Minecade Mod 1.7.2" Then
selected = "5"
issel = True
End If
If selected = "Minecade Mod 1.7.2 with OptiFine Standard" Then
selected = "3"
issel = True
End If
If selected = "Minecade Mod 1.7.2 with Optifine Ultra" Then
selected = "4"
issel = True
End If
If selected = "Minecade Mod 1.7.2 with Optifine Standard and Minecade Capes" Then
selected = "1"
issel = True
End If
If selected = "Minecade Mod 1.7.2 with Optifine Ultra and Minecade Capes" Then
selected = "2"
issel = True
End If
If issel = False Then
MsgBox("Invalid Selection! Try again.")
Else
Dim answ As Integer
answ = MsgBox("You have chosen the mod with the ID of: " & selected & "." & vbCrLf & "Do you want to install this mod?", vbYesNo)
If answ = 6 Then
If My.Computer.FileSystem.FileExists("C:\Documents and Settings\All Users\Documents\JOWD\MineCadeMod\1.7.2modded" & selected & ".zip") Then
Dim answOverW As Integer = MsgBox("The file already exists on the download location. Do you wish to download the file again (NO) or do you want to continue with the old one (YES)? (Preferred: Yes)", vbYesNo)
'6y7n
End If
'Installation process begins
Try
Dim dlPath As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "JOWD\MineCadeMod\1.7.2modded" & selected & ".zip"
My.Computer.Network.DownloadFile("http://files.casualnetwork.net/installers/moddedminec/1.7.2modded" & selected & ".zip", dlPath, "", "", False, 500, True)
Dim Unpackandinstall As Boolean = MsgBox("Download succesful. Do you want to unpack and install the archieve?", vbYesNo)
If Unpackandinstall = True Then
'UNPACK -------
'''Error occures inside the TRY tags here!'''
Try
Dim filePath As String
filePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & ".minecraft\versions\1.7.2modded" & selected
Dim startPath As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "JOWD\MineCadeMod\1.7.2modded" & selected & ".zip"
Dim zipPath As String = filePath
Dim extractPath As String = filePath
My.Computer.FileSystem.CreateDirectory(filePath)
ZipFile.CreateFromDirectory(startPath, zipPath)
ZipFile.ExtractToDirectory(zipPath, extractPath)
MsgBox("Decompression, installation and finishing done! Ready to play!")
Catch ex As Exception
MsgBox("Error in decompression and installment proceidure." & vbCrLf & vbCrLf & ex.Message & vbCrLf & vbCrLf & "Report to JOWD, as this should NOT happen!")
Button1.Enabled = True
Button2.Enabled = True
ComboBox1.Enabled = True
Button1.Text = "Download and Install!"
End Try
'''Error area ends!'''
End If
Catch ex As Exception
Button1.Enabled = True
Button2.Enabled = True
ComboBox1.Enabled = True
Button1.Text = "Download and Install!"
MsgBox("Download failed. Error code below!" & vbCrLf & vbCrLf & ex.Message & vbCrLf & vbCrLf & "Check the main topic for a possible solution, if nothing applies leave a reply!")
Exit Sub
End Try
Else
'installation process aborted.
End If
End If
End Sub
I will be happy to answer any question related to my problem, I've tried to look help anywhere but nothing helps me!
Thanks.
Read! Edited.
Regarding the 2 answers from David Sdot and Visual Vincent, - Their answers did not fix my problem.
I tried to use the following line on the code:
filePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\.minecraft\versions\1.7.2modded" & selected
Same error occurred.
Still looking for more advices from you!
Leave a comment if you want the project file to test it out.
Read! Edited.
Here's the source for the app, do your testing there!
http://files.casualnetwork.net/installers/moddedminec/source/MinecadeModInstaller_Min.zip
Ok so here's my solution to your problem:
Here, I used a WebClient instead of My.Computer.Network.DownloadFile, since I think it's better. (You use whatever you want of course)
Dim Download As New WebClient
Download.DownloadFileAsync(New Uri("http://files.casualnetwork.net/installers/moddedminec/1.7.2modded" & selected & ".zip"), dlPath)
I also noticed some stuff that had to be changed in your code.
For some reason you tried to zip your file into itself:
ZipFile.CreateFromDirectory(startPath, zipPath)
Remove this. :)
And you also tried to extract .minecraft\versions\1.7.2modded to itself by doing this:
Dim startPath As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\JOWD\MineCadeMod\1.7.2modded" & selected & ".zip"
Dim zipPath As String = filePath
Dim extractPath As String = filePath
ZipFile.ExtractToDirectory(zipPath, extractPath)
Simply change zipPath from:
Dim zipPath As String = filePath
To:
Dim zipPath As String = startPath
Now the zipping should work fine :)
One more thing I noticed is that you couldn't skip the unzip part even if you pressed "No" in the MsBox. So I changed that code a little:
Dim Unpackandinstall As DialogResult
Unpackandinstall = MessageBox.Show("Download succesful. Do you want to unpack and install the archieve?", "", MessageBoxButtons.YesNo)
If Unpackandinstall = Windows.Forms.DialogResult.Yes Then
...
End If
Here's the whole Try block:
Try
Dim Download As New WebClient
Dim dlPath As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\JOWD\MineCadeMod\1.7.2modded" & selected & ".zip"
Download.DownloadFileAsync(New Uri("http://files.casualnetwork.net/installers/moddedminec/1.7.2modded" & selected & ".zip"), dlPath)
Dim Unpackandinstall As DialogResult
Unpackandinstall = MessageBox.Show("Download succesful. Do you want to unpack and install the archieve?", "", MessageBoxButtons.YesNo)
If Unpackandinstall = Windows.Forms.DialogResult.Yes Then
Try
Dim filePath As String
filePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\.minecraft\versions\1.7.2modded" & selected
Dim startPath As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\JOWD\MineCadeMod\1.7.2modded" & selected & ".zip"
Dim zipPath As String = startPath
Dim extractPath As String = filePath
My.Computer.FileSystem.CreateDirectory(filePath)
'ZipFile.CreateFromDirectory(startPath, zipPath)
ZipFile.ExtractToDirectory(zipPath, extractPath)
MsgBox("Decompression, installation and finishing done! Ready to play!")
Catch ex As Exception
MsgBox("Error in decompression and installment proceidure." & vbCrLf & vbCrLf & ex.Message & vbCrLf & vbCrLf & "Report to JOWD, as this should NOT happen!")
Button1.Enabled = True
Button2.Enabled = True
ComboBox1.Enabled = True
Button1.Text = "Download and Install!"
End Try
End If
Catch ex As Exception
Button1.Enabled = True
Button2.Enabled = True
ComboBox1.Enabled = True
Button1.Text = "Download and Install!"
MsgBox("Download failed. Error code below!" & vbCrLf & vbCrLf & ex.Message & vbCrLf & vbCrLf & "Check the main topic for a possible solution, if nothing applies leave a reply!")
Exit Sub
End Try
And just replace
Download.DownloadFileAsync(New Uri("http://files.casualnetwork.net/installers/moddedminec/1.7.2modded" & selected & ".zip"), dlPath)
With your My.Computer.Network code if you'd rather use that instead. :)
Hope this helps!
filePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & ".minecraft\versions\1.7.2modded" & selected
The path return by Environment.GetFolderPath has no \ at the end and you prepended a dot instead.
filePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\minecraft\versions\1.7.2modded" & selected
please i have this problem with vb and i have tried everything to fix it but still cant fix it. Here it is:
Const Filesplit = "#rapid#"
Dim temp As String = IO.Path.GetTempPath() & "\Stub.exe"
File.WriteAllBytes(temp, My.Resources.Stub)
If TextBox8.Text.Length > 2 Then
If File.Exists(temp) = True Then
Dim icon As New IconFile(TextBox9.Text)
Dim groupIconResource As GroupIconResource = icon.ConvertToGroupIconResource()
groupIconResource.SaveTo(temp)
End If
End If
FileOpen(1, temp, OpenMode.Binary, OpenAccess.Read, OpenShare.Default)
stub = Space(LOF(1))
FileGet(1, stub)
FileClose(1)
If File.Exists(TextBox8.Text) Then
My.Computer.FileSystem.DeleteFile(TextBox8.Text)
End If
FileOpen(1, Application.StartupPath & "\" & TextBox8.Text & ".exe", OpenMode.Binary, OpenAccess.Read, OpenShare.Default)
Dim all As String = ""
For i = 0 To settings.Length - 1
all = all & Filesplit & settings(i)
Next
FilePut(1, stub & all)
FileClose(1)
File.Delete(temp)
If Form2.CheckBox41.Checked = True Then
ChngaeAssembly()
End If
If ComboBox1.Text = "KB" Then
Using w As BinaryWriter = New BinaryWriter(New FileStream(Application.StartupPath & "\" & TextBox8.Text & ".exe", FileMode.Append))
Dim number As Integer = Val(TextBox6.Text)
For i = 0 To number
w.Write(New Byte(1024) {})
w.Flush()
Next
End Using
MsgBox("Successfully built !", MsgBoxStyle.Information, "rapid V 1.0")
Else
Using w As BinaryWriter = New BinaryWriter(New FileStream(Application.StartupPath & "\" & TextBox8.Text & ".exe", FileMode.Append))
Dim number As Integer = Val(TextBox6.Text * 1000)
For i = 0 To number
w.Write(New Byte(1024) {})
w.Flush()
Next
End Using
MsgBox("Successfully built !", MsgBoxStyle.Information, "rapid")
End If
MsgBox("Problem Occured. The Server was not Built.", MessageBoxIcon.Error, "rapid")
End Sub
Private Sub ChngaeAssembly()
Try
If File.Exists(Application.StartupPath & "\res.exe") Then
File.Delete(Application.StartupPath & "\res.exe")
End If
If File.Exists(Application.StartupPath & "\assemblychange.res") Then
File.Delete(Application.StartupPath & "\assemblychange.res")
End If
System.IO.File.WriteAllBytes(Application.StartupPath & "\res.exe", My.Resources.Res)
Dim source As String = My.Resources.String1
If File.Exists(Application.StartupPath & "\assemblychange.exe") Then
File.Delete(Application.StartupPath & "\assemblychange.exe")
End If
Dim Version = New Collections.Generic.Dictionary(Of String, String) : Version.Add("CompilerVersion", "v2.0")
Dim Compiler As VBCodeProvider = New VBCodeProvider(Version)
Dim CompResults As CompilerResults
Dim ComParameters As New CompilerParameters()
With ComParameters
.GenerateExecutable = True
.OutputAssembly = Application.StartupPath & "\assemblychange.exe"
.CompilerOptions = "/target:winexe"
.ReferencedAssemblies.Add("System.dll")
.ReferencedAssemblies.Add("System.Windows.Forms.dll")
.MainClass = "X"
End With
source = source.Replace("*Title*", Form2.TextBox3.Text)
source = source.Replace("*Description*", Form2.TextBox4.Text)
source = source.Replace("*Company*", Form2.TextBox5.Text)
source = source.Replace("*Product*", Form2.TextBox6.Text)
source = source.Replace("*Copyright*", Form2.TextBox7.Text)
source = source.Replace("*Trademark*", Form2.TextBox8.Text)
source = source.Replace("*version*", String.Format("{0}.{1}.{2}.{3}", Form2.NumericUpDown2.Value, Form2.NumericUpDown3.Value, Form2.NumericUpDown4.Value, Form2.NumericUpDown5.Value))
source = source.Replace("*fversion*", String.Format("{0}.{1}.{2}.{3}", Form2.NumericUpDown6.Value, Form2.NumericUpDown7.Value, Form2.NumericUpDown8.Value, Form2.NumericUpDown9.Value))
CompResults = Compiler.CompileAssemblyFromSource(ComParameters, source)
If CompResults.Errors.Count > 0 Then
For Each CompilerError In CompResults.Errors
MessageBox.Show("Error: " & CompilerError.ErrorText, "", MessageBoxButtons.OK, MessageBoxIcon.Error)
Next
If File.Exists(Application.StartupPath & "\res.exe") = True Then
File.Delete(Application.StartupPath & "\res.exe")
End If
If File.Exists(Application.StartupPath & "\res.log") = True Then
File.Delete(Application.StartupPath & "\res.log")
End If
If File.Exists(Application.StartupPath & "\res.ini") = True Then
File.Delete(Application.StartupPath & "\res.ini")
End If
If File.Exists(Application.StartupPath & "\assemblychange.exe") Then
File.Delete(Application.StartupPath & "\assemblychange.exe")
End If
If File.Exists(Application.StartupPath & "\assemblychange.res") Then
File.Delete(Application.StartupPath & "\assemblychange.res")
End If
MessageBox.Show("An error occurred. The assembly was not changed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
Dim otherfile As String = Application.StartupPath & "\assemblychange.exe"
Dim resfile As String = Application.StartupPath & "\assemblychange.res"
Dim mainfile As String = Application.StartupPath & "\" & TextBox8.Text & ".exe"
Shell(String.Format("{0}res.exe -extract {1},{2},VERSIONINFO,,", System.AppDomain.CurrentDomain.BaseDirectory(), otherfile, resfile))
Shell(String.Format("{0}res.exe -delete {1},{0}res.exe,VERSIONINFO,,", System.AppDomain.CurrentDomain.BaseDirectory(), mainfile))
Shell(String.Format("{0}res.exe -addoverwrite {1},{1},{2},VERSIONINFO,1,", System.AppDomain.CurrentDomain.BaseDirectory(), mainfile, resfile))
If File.Exists(Application.StartupPath & "\assemblychange.exe") Then
File.Delete(Application.StartupPath & "\assemblychange.exe")
End If
If File.Exists(Application.StartupPath & "\assemblychange.res") Then
File.Delete(Application.StartupPath & "\assemblychange.res")
End If
If File.Exists(Application.StartupPath & "\res.exe") = True Then
File.Delete(Application.StartupPath & "\res.exe")
End If
If File.Exists(Application.StartupPath & "\res.log") = True Then
File.Delete(Application.StartupPath & "\res.log")
End If
If File.Exists(Application.StartupPath & "\res.ini") = True Then
File.Delete(Application.StartupPath & "\res.ini")
End If
Catch
End Try
End Sub
When i debug, I get Sub Main was not found in 'X' when i try to change assembly please how do i fix it? Thanks in advance
One way to get that error is to have Sub Main as a startup object when it doesn't exist.
Under your project properties, Application, Startup Object may be set to "Sub Main" when you don't have a Sub Main. Instead, you can select a form (or sub) that exists in your project.
(This option is limited to forms if "Enable application framework" is checked.)