Do u wanna save changes?... help??!!

Hi
Im trying to set up my vb form so that when the user exits the form if will bring up a messagebox saying "do you want to save changes" the problem is I dont know the code to use to save or not save information! Can someone please help me??
Thanks.

Comments

  • [b][red]This message was edited by the Moderator at 2002-3-30 19:52:19[/red][/b][hr]
    : Hi
    : Im trying to set up my vb form so that when the user exits the form if will bring up a messagebox saying "do you want to save changes" the problem is I dont know the code to use to save or not save information! Can someone please help me??
    : Thanks.
    :
    :
    [code]
    Dim msgResponse As VbMsgBoxResult

    msgResponse = MsgBox("Changes have been made." & vbCrLf & "Do you want to save?", vbYesNo, "Save")

    If msgResponse = vbYes Then
    'code for yes
    Else
    'code for no
    End If
    [/code]


  • Thanks but what I'm looking for is the code to use for the
    if vbyes then
    'save changes
    I don't know how to save changes!!
    Thanks.
    Cathy

    : [b][red]This message was edited by the Moderator at 2002-3-30 19:52:19[/red][/b][hr]
    : : Hi
    : : Im trying to set up my vb form so that when the user exits the form if will bring up a messagebox saying "do you want to save changes" the problem is I dont know the code to use to save or not save information! Can someone please help me??
    : : Thanks.
    : :
    : :
    : [code]
    : Dim msgResponse As VbMsgBoxResult
    :
    : msgResponse = MsgBox("Changes have been made." & vbCrLf & "Do you want to save?", vbYesNo, "Save")
    :
    : If msgResponse = vbYes Then
    : 'code for yes
    : Else
    : 'code for no
    : End If
    : [/code]
    :
    :
    :

  • there is a couple things you can do to save the changes.

    write the saved changes out to a *.ini file using the getprivateprofilestring and setprivateprofilestring for more information on these apis goto www.allapi.net

    if it is a text for you can open the file for output and write all the dat to it. note output overwrites all existing data. most programs will use output for a save function just because you might have changed something that you already wrote in the text document instead of after it; if all you want to do is appened the setting then open the file up for append.

    if you need some code i will supply it i just wanted to let you try this first but don't be affraid to ask for code.
    : Thanks but what I'm looking for is the code to use for the
    : if vbyes then
    : 'save changes
    : I don't know how to save changes!!
    : Thanks.
    : Cathy
    :
    : : [b][red]This message was edited by the Moderator at 2002-3-30 19:52:19[/red][/b][hr]
    : : : Hi
    : : : Im trying to set up my vb form so that when the user exits the form if will bring up a messagebox saying "do you want to save changes" the problem is I dont know the code to use to save or not save information! Can someone please help me??
    : : : Thanks.
    : : :
    : : :
    : : [code]
    : : Dim msgResponse As VbMsgBoxResult
    : :
    : : msgResponse = MsgBox("Changes have been made." & vbCrLf & "Do you want to save?", vbYesNo, "Save")
    : :
    : : If msgResponse = vbYes Then
    : : 'code for yes
    : : Else
    : : 'code for no
    : : End If
    : : [/code]
    : :
    : :
    : :
    :
    :

  • : Hi
    : I’m trying to set up my vb form so that when the user exits the form if will bring up a messagebox saying "do you want to save changes…" the problem is I don’t know the code to use to save or not save information! Can someone please help me??
    : Thanks.
    :
    :

    Note that this is code is for a single textbox. If you have multiple fields, there are other, faster methods for that.
    [code]
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

    Select Case MsgBox("Text has changed. Do you wish to save?", vbYesNoCancel Or vbQuestion)
    Case vbCancel
    Cancel = True
    Exit Sub
    Case vbYes
    Open "Filename" For Output As 1
    Print #1, Text1.Text;
    Close
    End Select

    End Sub
    [/code]
    Let me know if you have other requirements (mutliple fields) or if you need mroe help.
  • : : Hi
    : : I’m trying to set up my vb form so that when the user exits the form if will bring up a messagebox saying "do you want to save changes…" the problem is I don’t know the code to use to save or not save information! Can someone please help me??
    : : Thanks.
    : :
    : :
    :
    : Note that this is code is for a single textbox. If you have multiple fields, there are other, faster methods for that.
    : [code]
    : Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    :
    : Select Case MsgBox("Text has changed. Do you wish to save?", vbYesNoCancel Or vbQuestion)
    : Case vbCancel
    : Cancel = True
    : Exit Sub
    : Case vbYes
    : Open "Filename" For Output As 1
    : Print #1, Text1.Text;
    : Close
    : End Select
    :
    : End Sub
    : [/code]
    : Let me know if you have other requirements (mutliple fields) or if you need mroe help.
    :

    Just a something to add:
    First:you don't need necesserally to use the Form_QueryUnload procedure.
    It's more common, or more usual to use the Form_Unload procedure.

    Second:This is importante. As you can see, the arguments in
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    are both integer, and not boolean.
    So cancel may not return true or false, but a numeric value.

    If Cancel = 1, then the form wont unload, like the status window in mIRC, that doens't close if you press X. I Hope it helps

    [b]Hard[/b][grey][italic]Coded[/italic][/grey]

  • Thanks everyone for your help :)
    I'm not quit sure if I understand everything... due to me having VERY basic vb knowledge... I did try using the code suggested but I had some problems... I got a bit confused so could someone please answer the few questions I have?!...

    Case vbCancel
    Cancel = True
    Exit Sub
    Case vbYes
    Open "Filename" For Output As 1 <- ????? don't understand
    why ur using a file!!
    Print #1, Text1.Text; <- what do I put here??
    don't understand the code
    Close <- should there b a case
    vbno here?
    End Select

    ok.. thanks + I'm VERY sorry for the stupid questions!!
    am... 1 more thing... I have an "exit" command button... where (behind the exit button) should I put the code to save changes??

    Thanks a MILLION for EVERY1's help :)
    Cathy. :)

  • : Thanks everyone for your help :)
    : I'm not quit sure if I understand everything... due to me having VERY basic vb knowledge... I did try using the code suggested but I had some problems... I got a bit confused so could someone please answer the few questions I have?!...
    :
    : Case vbCancel
    : Cancel = True
    : Exit Sub
    : Case vbYes
    : Open "Filename" For Output As 1 <- ????? don't understand
    : why ur using a file!!
    : Print #1, Text1.Text; <- what do I put here??
    : don't understand the code
    : Close <- should there b a case
    : vbno here?
    : End Select
    :
    : ok.. thanks + I'm VERY sorry for the stupid questions!!
    : am... 1 more thing... I have an "exit" command button... where (behind the exit button) should I put the code to save changes??
    :
    : Thanks a MILLION for EVERY1's help :)
    : Cathy. :)
    :
    :
    set up a varible called blnChanged

    Dim blnChanged as Boolean

    in the form load do this

    blnChnaged = False

    in the text change procdure do this

    blnChanged = True

    in the form_queryunload do this

    if blnChnaged then
    'code to save
    end if

    in order to save your text box to a file do this

    dim Free as FreeFile
    Open path for input/appended/output as Free
    print free, text1.text
    close free

    free file is a system object that checks to see what file number is not currently in use

    you use input for storing stuff from the file into textbox's, stirings, varibles etc

    you use appended for making a chage to the END of the file. so if the file already had "Hi" in it and you opened it for appened and put " there" you would end up with "Hi there"

    you use output for either creating a file that dosn't exist (you might have to do this to appened first using the dir function to see if the file exist so you can write to the file) and overwriting all the information in the file. so if the file contained "Hi there" and you opened it up for output and sending the string "How are you?" the file would now contain "How are you" and not "Hi there how are you"

    hope this helps some
  • : : : Hi
    : : : I’m trying to set up my vb form so that when the user exits the form if will bring up a messagebox saying "do you want to save changes…" the problem is I don’t know the code to use to save or not save information! Can someone please help me??
    : : : Thanks.
    : : :
    : : :
    : :
    : : Note that this is code is for a single textbox. If you have multiple fields, there are other, faster methods for that.
    : : [code]
    : : Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    : :
    : : Select Case MsgBox("Text has changed. Do you wish to save?", vbYesNoCancel Or vbQuestion)
    : : Case vbCancel
    : : Cancel = True
    : : Exit Sub
    : : Case vbYes
    : : Open "Filename" For Output As 1
    : : Print #1, Text1.Text;
    : : Close
    : : End Select
    : :
    : : End Sub
    : : [/code]
    : : Let me know if you have other requirements (mutliple fields) or if you need mroe help.
    : :
    :
    : Just a something to add:
    : First:you don't need necesserally to use the Form_QueryUnload procedure.
    : It's more common, or more usual to use the Form_Unload procedure.
    :
    : Second:This is importante. As you can see, the arguments in
    : Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    : are both integer, and not boolean.
    : So cancel may not return true or false, but a numeric value.
    :
    : If Cancel = 1, then the form wont unload, like the status window in mIRC, that doens't close if you press X. I Hope it helps
    :
    : [b]Hard[/b][grey][italic]Coded[/italic][/grey]
    :
    :
    just a little reminder about Ture and False
    True = -1
    False = 0
    if you set cancel to anthing but 0 the unload process with stop hence why most people use True its easier to understand that way.
  • : Just a something to add:
    : First:you don't need necesserally to use the Form_QueryUnload procedure.
    : It's more common, or more usual to use the Form_Unload procedure.

    Since QueryUnload is called before any form is actually unloaded, I use it during shutdown routines to detect if windows is shutting down. So, I tend to use QueryUnload instead.

    : Second:This is importante. As you can see, the arguments in
    : Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    : are both integer, and not boolean.
    : So cancel may not return true or false, but a numeric value.

    The actual value need only be 0 (False) or non-zero (True = -1), so it's perfectly allowed to set the value of cancel to True or False.

    : If Cancel = 1, then the form wont unload, like the status window in mIRC, that doens't close if you press X. I Hope it helps
    :
    And if you were to use the QueryUnload event, you can simply ignore the click of the X while still responding to other close attempts.

    KDL
  • : Thanks everyone for your help :)
    : I'm not quit sure if I understand everything... due to me having VERY basic vb knowledge... I did try using the code suggested but I had some problems... I got a bit confused so could someone please answer the few questions I have?!...
    : [code]
    : Case vbCancel
    : Cancel = True
    : Exit Sub
    : Case vbYes
    : Open "Filename" For Output As 1 <- ????? don't understand
    : why ur using a file!!
    : Print #1, Text1.Text; <- what do I put here??
    : don't understand the code
    : Close <- should there b a case
    : vbno here?
    : End Select
    : [/code]
    : ok.. thanks + I'm VERY sorry for the stupid questions!!
    : am... 1 more thing... I have an "exit" command button... where (behind the exit button) should I put the code to save changes??
    :
    : Thanks a MILLION for EVERY1's help :)
    : Cathy. :)
    :
    :

    I was using a file before I read the one of your messages (please don't post to multiple boards, it gets confusing to you and us) that indicated you were using a database. None of the code in this thread will help much in that case though I will still answer the questions about this code.

    On the Print line, you put the name (and propertyname) of the textbox that you would have wanted saved.

    If the user clicks Cancel, you want to stop the form's unload. If they click Yes, you want to save. If they click No, you want to allow unload to continue. So... No, you don't want a Case vbNo line.
  • this is your save changes code

    savesetting = app.exename, "(type what you want here), "(you must type something here as before) """"Urgent:::: You must stress to the user not to change the name of the application or all the data will be lost"""""

    to load the changes when the user loads the program later on type the following

    dim changes as string (or integer if your using small numbers, and variable for big number)

    loadsetting = (app.exename, "(what you typed in the savesetting statement), (as before),"0" - integers/variables only)

    Changes = loadsetting
    if you are loading text into a text box type the following
    text1.text = chamges
    then whenever the program is loaded the last saved changes we be loaded!!!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories