Results 1 to 12 of 12

Thread: Making a Save/Open button

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2009
    Posts
    29

    Question Making a Save/Open button

    Hello
    I was wondering how to make a save button
    I'm making a very simple program in which the user enter an email address and the computer works out if it's real
    Daft, I know
    Just experimenting
    I was also wondering how to make an open button
    One last thing:
    Can I make my own file formats
    I was going to save this email address as an ema (Electronic Messaging Address) I hope someone knows the answer cause It's got me thinking
    Regards,
    Michael

  2. #2
    Hyperactive Member
    Join Date
    Dec 2008
    Posts
    314

    Re: Making a Save/Open button

    If you making a save button that will save list lets say from listbox u can use this

    Code:
            Dim SaveFile As New SaveFileDialog()
    
            SaveFile.Filter = "Text Files (*.txt)|*.txt"
            SaveFile.Title = "Save"
    
            If SaveFile.ShowDialog() = DialogResult.OK Then
                Dim Write As New System.IO.StreamWriter(SaveFile.FileName)
                For Each s As Object In lstURIlist.Items
                    Write.Write(s)
                    Write.WriteLine()
                Next s
                Write.Dispose()
                Write.Close()
                MsgBox("Url List Saved")
            End If

    If you want a button to save selected item in List Box u can use this instead


    Code:
            Dim SaveFile As New SaveFileDialog
            SaveFile.FileName = ""
            SaveFile.Filter = "Text Files (*.txt)|*.txt"
            SaveFile.Title = "Save"
            SaveFile.ShowDialog()
            Try
                Dim Write As New System.IO.StreamWriter(SaveFile.FileName)
                Write.Write(lstURIlist.Text)
                Write.Close()
            Catch ex As Exception
    
            End Try

    IT all dippends what Save option u want and what type of stuff u want it saving

    as for your open button I asume u want open text box so in that case u will need to use some thing like this

    Code:
    Dim OpenFile As New OpenFileDialog
    OpenFile.FileName = ""
    OpenFile.Filter = "Text Files (*.txt)|*.txt"
    OpenFile.Title = "Open"
    OpenFile.ShowDialog()
    Try
    Dim Read As New System.IO.StreamReader(OpenFile.FileName )
    RichTextBox1.Text = Read.ReadToEnd
    Read.Close()
    Catch ex As Exception
    
    End Try
    Hope This helps U im a noob my self so sorry if the code is wrong mabye some one more advanced can help u


    Goood luck and also u shold post smmall info on what u trying to do with your project so people know how to help u best

    Good luck

  3. #3
    Hyperactive Member Runesmith's Avatar
    Join Date
    Oct 2008
    Posts
    399

    Re: Making a Save/Open button

    What do you mean by "an open button"? What do you expect this button to do?

    Yes, you can create your own file formats. You can decide how the data is going to be stored, and what the file extension is. You need to create an application that uses this file format, otherwise it would be useless. Creating a new file format just for the sake of it is not a good idea. You should probably create a new file format if:
    a. none of the existing file formats fit what you need to do
    b. you are trying to ensure that your datafile cannot be opened by anyone elses app
    c. you need to register this file format to your app, so that Windows will start your app automatically when someone double-clicks on a file of this type
    Runesmith

    The key to getting the right answer is asking the right question

    I just realized: good health is merely the slowest possible rate at which one can die

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Aug 2009
    Posts
    29

    Re: Making a Save/Open button

    Runesmith,
    I fit into my program fits into categories b and c
    and my open button needs to be like a lot of other open buttons
    you click it and it opens a window where you can search through your documents and folders and double click a file (only my files will be visible (ema files)) and then it will open it in the text box
    There is no real purpose to this but I would really like to do it to get a feel for the program
    regards,
    michael

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2009
    Posts
    29

    Re: Making a Save/Open button

    I'm sorry I didn't explain fully Breez
    I wanted to make it save some text from a text box
    the user enters text and he can then save it
    in your example you explain how save items from a list and I got this working fine so I give you my gratitude but would it be possible to explain how you would save text from a text box
    regards,
    michael

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Aug 2009
    Posts
    29

    Re: Making a Save/Open button

    I'm using visual basic 2008 express edition

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Aug 2009
    Posts
    29

    Re: Making a Save/Open button

    I got the save button working
    Here's what you wrote Breez
    Dim SaveFile As New SaveFileDialog
    SaveFile.FileName = ""
    SaveFile.Filter = "Text Files (*.txt)|*.txt"
    SaveFile.Title = "Save"
    SaveFile.ShowDialog()
    Try
    Dim Write As New System.IO.StreamWriter(SaveFile.FileName)
    Write.Write(lstURIlist.Text)
    Write.Close()
    Catch ex As Exception

    End Try
    For it to work I just changed this line:
    Write.Write(lstURIlist.Text)
    to
    Write.Write(My_Text_Box_Name.Text)
    Bye
    Thanks for the help
    still pondering over the open button but I think I can do it
    I'll try something but if I can't I post a new thread in the forum

    bye

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Aug 2009
    Posts
    29

    Re: Making a Save/Open button

    This is as far as I can get
    I can save a file as ema format but I can't open it
    the open button won't work
    any help would be greatly appreciated
    bye

  9. #9
    Hyperactive Member
    Join Date
    Dec 2008
    Posts
    314

    Re: Making a Save/Open button

    Quote Originally Posted by Michael_ View Post
    This is as far as I can get
    I can save a file as ema format but I can't open it
    the open button won't work
    any help would be greatly appreciated
    bye
    try this for open

    Code:
    Dim Open As New OpenFileDialog() Dim myStreamReader As System.IO.StreamReader Open.Filter = "Text [*.txt*]|*.txt|All Files [*.*]|*.*" Open.CheckFileExists = True Open.Title = "OpenFile" Open.ShowDialog(Me) Try Open.OpenFile() myStreamReader = System.IO.File.OpenText(Open.FileName) RichTextBox1.Text = myStreamReader.ReadToEnd() Catch ex As Exception End Try
    rename names to your names so it will work and same as for your save button I posted above

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Aug 2009
    Posts
    29

    Re: Making a Save/Open button

    This is as far as I can get
    I can save a file as ema format but I can't open it
    the open button won't work
    any help would be greatly appreciated
    bye

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Aug 2009
    Posts
    29

    Re: Making a Save/Open button

    Thanks that worked a treat I can now everything (Well nearly everything) that planned to do

    thanks again

  12. #12
    Hyperactive Member
    Join Date
    Dec 2008
    Posts
    314

    Re: Making a Save/Open button

    Quote Originally Posted by Michael_ View Post
    Thanks that worked a treat I can now everything (Well nearly everything) that planned to do

    thanks again
    hey glad i could help if u can just change name of your thread to resolved that would be great so other people can get help if they need 2

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