Problem with my "Save" button

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi, I have a problem with my save button:
<pre class="prettyprint lang-vb Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br/> If Directory.Exists("C:GamesBuilddatadata.world" & TextBox1.Text) Then<br/> If MessageBox.Show("This world already exists. Would you like to save over it?", "Save as Continued World?", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then<br/> File.Delete("C:GamesBuilddatadata.world" & TextBox1.Text & "world.buildlvl")<br/> Dim newWorldFile As New IO.StreamWriter("C:GamesBuilddatadata.world" & TextBox1.Text & "world.buildlvl")<br/> newWorldFile.WriteLine(Form1.PictureBox1.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox2.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox3.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox4.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox5.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox6.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox7.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox8.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox9.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox10.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox11.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox12.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox13.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox14.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox15.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox16.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox17.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox18.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox19.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox20.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox21.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox22.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox23.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox24.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox25.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox26.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox27.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox28.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox29.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox30.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox31.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox32.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox33.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox34.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox35.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox36.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox37.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox38.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox39.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox40.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox41.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox42.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox43.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox44.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox45.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox46.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox47.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox48.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox49.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox50.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox51.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox52.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox53.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox54.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox55.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox56.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox57.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox58.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox59.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox60.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox61.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox62.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox63.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox64.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox65.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox66.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox67.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox68.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox69.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox70.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox71.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox72.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox73.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox74.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox75.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox76.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox77.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox78.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox79.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox80.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox81.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox82.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox83.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox84.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox85.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox86.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox87.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox88.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox89.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox90.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox91.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox92.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox93.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox94.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox95.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox96.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox97.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox98.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox99.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox100.ImageLocation)<br/> newWorldFile.Close()<br/> If MessageBox.Show("The world has successfully saved!", "Saved!", MessageBoxButtons.OK) = Windows.Forms.DialogResult.OK Then<br/> Me.Close()<br/> End If<br/> Else<br/><br/> End If<br/> Else<br/> Directory.CreateDirectory("C:GamesBuilddatadata.world" & TextBox1.Text)<br/> File.Create("C:GamesBuilddatadata.world" & TextBox1.Text & "world.buildlvl")<br/> Dim newWorldFile As New IO.StreamWriter("C:GamesBuilddatadata.world" & TextBox1.Text & "world.buildlvl")<br/> newWorldFile.WriteLine(Form1.PictureBox1.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox2.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox3.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox4.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox5.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox6.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox7.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox8.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox9.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox10.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox11.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox12.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox13.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox14.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox15.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox16.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox17.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox18.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox19.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox20.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox21.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox22.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox23.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox24.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox25.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox26.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox27.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox28.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox29.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox30.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox31.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox32.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox33.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox34.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox35.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox36.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox37.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox38.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox39.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox40.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox41.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox42.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox43.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox44.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox45.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox46.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox47.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox48.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox49.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox50.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox51.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox52.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox53.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox54.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox55.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox56.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox57.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox58.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox59.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox60.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox61.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox62.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox63.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox64.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox65.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox66.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox67.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox68.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox69.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox70.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox71.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox72.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox73.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox74.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox75.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox76.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox77.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox78.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox79.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox80.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox81.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox82.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox83.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox84.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox85.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox86.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox87.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox88.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox89.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox90.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox91.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox92.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox93.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox94.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox95.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox96.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox97.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox98.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox99.ImageLocation)<br/> newWorldFile.WriteLine(Form1.PictureBox100.ImageLocation)<br/> newWorldFile.Close()<br/> End If<br/> Me.Close()<br/> Form1.Close()<br/> Form2.Close()<br/> Form3.Close()<br/> Form4.Close()<br/> End Sub[/code]
Problem: Its basically saying, if the world already exists, delete and save it again. I havent tested that yet. But when it is creating a new one, on the line:
<pre class="prettyprint lang-vb Dim newWorldFile As New IO.StreamWriter("C:GamesBuilddatadata.world" & TextBox1.Text & "world.buildlvl")[/code]
It says it is being used by another process. I dont know why it says that, because it isnt. Why is this so?<br/>


View the full article
 
Back
Top