Results 1 to 5 of 5

Thread: using a button to save info input in textboxes

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2009
    Posts
    75

    using a button to save info input in textboxes

    this application I'm writing is for Employee Data. I have 7 texboxes and 1 combo box.

    With the file menu I have used that function to save info inputed in one texbox. However for this application I need to use btnSave button to save the record.

    here is what I used for the file>save menu:

    Code:
    Dim result As DialogResult
            'find input file
            With OpenFileDialog1
                .Title = "Find Input File"
                .Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
                .CheckFileExists = True
                result = .ShowDialog()
            End With
            'canceled out?
            If result = DialogResult.Cancel Then
                Exit Sub
            End If
            'remember name of input file
            strInputFileName = OpenFileDialog1.FileName
    
            'open files for input
            Dim inputfile As System.IO.StreamReader
            inputfile = System.IO.File.OpenText(strInputFileName)
    
            'clear and fill textbox with content of input file
            TextBox1.Clear()
            Do Until inputfile.Peek() = -1
                Dim strTextLine As String
                strTextLine = inputfile.ReadLine()
                TextBox1.Text = strTextLine & ControlChars.NewLine
    
            Loop
            'close the channel
            inputfile.Close()

    How can I implement this with a button?

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: using a button to save info input in textboxes

    If I'm not mistaken that code is VB.NET!

    Furthermore the code posted isn't doing any save into a file, it rather reads from a file and puts the contents into TextBox1!

    And on your question, "How to use code from a Menu on aCommandButton, the answer is: The use is the same, you could copy/paste the code from one Sub to the other.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  3. #3
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: using a button to save info input in textboxes

    Move to VB.Net Forum.

    pino

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: using a button to save info input in textboxes

    I think this is what you are looking for.
    Code:
    System.IO.File.WriteAllText("c:\hack.txt", TextBox1.Text)

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2009
    Posts
    75

    Re: using a button to save info input in textboxes

    Quote Originally Posted by opus View Post
    If I'm not mistaken that code is VB.NET!

    Furthermore the code posted isn't doing any save into a file, it rather reads from a file and puts the contents into TextBox1!

    And on your question, "How to use code from a Menu on aCommandButton, the answer is: The use is the same, you could copy/paste the code from one Sub to the other.
    oh Ok I was not sure if visual basic in visual studio is .net at all. thanks. lul what about the option of deciding where to save it?
    Last edited by DiLDoR; Apr 20th, 2009 at 11:53 PM.

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