Results 1 to 2 of 2

Thread: Saving files 'write line'

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2011
    Posts
    7

    Question Saving files 'write line'

    I want to be able to take some user inputs and then using the 'filesave' write a vb code file which I could load and get the program to execute. At the minute changing 4 text boxes on the main form to 4 values entered on the values form (where the save button is). I've tried this code;


    Code:
    Dim filesave As StreamWriter
            Dim num1, num2, num3, num4 As String
            num1 = TextBox1.Text
            num2 = TextBox2.Text
            num3 = TextBox3.Text
            num4 = TextBox4.Text
            filesave = My.Computer.FileSystem.OpenTextFileWriter("save.vb", False)
    filesave.WriteLine("Private Sub Load_Execute(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles loadfile.click")
            filesave.WriteLine("Dim num1, num2, num3, num4 As String")
            filesave.WriteLine("num1 =" num1)
            filesave.WriteLine("num2 =" num2)
            filesave.WriteLine("num3 =" num3)
            filesave.WriteLine("num4 =" num4)
            filesave.WriteLine("Main.Label1.Text = num1")
            filesave.WriteLine("Main.Label2.Text = num2")
            filesave.WriteLine("Main.Label3.Text = num3")
            filesave.WriteLine("Main.Label4.Text = num4")
            filesave.WriteLine("Me.Close()")
    filesave.WriteLine("End Sub")

    It keeps saying 'Comma, ')', or a valid expression continuation expected' after the lines with ("num1 =" num1). Is there another way of writing this as or is there something else I need to add. I'm trying to add a line that would declare num1 in this new code document as num1 was when the file was written. I've attached an example of what the written file should look like if num1 was one, num2 two et cetra. I'm not exactly sure if this would even work or if there is an easier way to approach it. Any help would be greatly appreciated.
    Attached Files Attached Files

  2. #2
    Lively Member S0LARIS's Avatar
    Join Date
    Apr 2011
    Posts
    121

    Re: Saving files 'write line'

    Hi,you are missing '&' operator.

    Replace this:
    vb Code:
    1. filesave.WriteLine("num1 =" num1)
    2.         filesave.WriteLine("num2 =" num2)
    3.         filesave.WriteLine("num3 =" num3)
    4.         filesave.WriteLine("num4 =" num4)

    With:
    vb Code:
    1. filesave.WriteLine("num1 =" & num1)
    2.         filesave.WriteLine("num2 =" & num2)
    3.         filesave.WriteLine("num3 =" & num3)
    4.         filesave.WriteLine("num4 =" & num4)
    If my post was helpful to you, then express your gratitude using Rate this Post.
    To understand recursion, you must first understand recursion.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width