Jump to content

Same form for "new" and "edit"


maba
 Share

Recommended Posts

Hi all,

the simplest (and rightest) way to have only one form to insert or modify data?

Example:I would manage sqlite data with one form for the two operation with simple IFs to load data, enable or disable fileds, etc.

Put all code in a function that accepts an argument like the record ID?

Thanks

Link to comment
Share on other sites

Yes, that is definately simple. Assuming that you would use an editbox for changing your data:

Global $GUI, $Edit, $File, $New, $Open, $Save, $msg, $File, $FileContents
$GUI = GUICreate("Example",500,500)
$Edit = GUICtrlCreateEdit("", 0, 0, 500, 470)
$File = GUICtrlCreateMenu("File")
$New = GUICtrlCreateMenuItem("&New", $File)
$Open = GUICtrlCreateMenuItem("&Open", $File)
$Save = GUICtrlCreateMenuItem("&Save", $File)
GUISetState(@SW_SHOW, $GUI)
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case -3;GuiMsg -3 = $GUI_EVENT_EXIT
            Exit
        Case $New
            GUICtrlSetData($Edit, "");Sets the data in the editbox to nothing
        Case $Open
            $File = FileOpenDialog("Open", @DesktopDir, "All Files (*.*)");Allows you to select the desired file
            $FileContents = FileRead($File);Sets the value of $FileContents to the text read from the file
            GUICtrlSetData($Edit, $FileContents);Sets the data in the editbox to the data in $FileContents
        Case $Save
            $FileContents = GUICtrlRead($Edit);Sets the value of $FileContents to the text read from the edit box
            FileWrite($File, $FileContents);Writes the value of $FileContents to the file
    EndSwitch
WEnd

There you go, I hope that's what you were looking for. The commands you want to look are are FileOpenDialog, FileRead, GuiCtrlSetData, GuiCtrlRead and FileWrite.

Unfrotunately, I don't know much about SQLite so I cannot help much there without more information, but the code provided should start you off.

Edited by Mikeman27294
Link to comment
Share on other sites

Thanks for your quickly answer!

We can use this example:

New Contact and Edit Contact button opens two different form with the same input fields.

I have a similar form with about 30 fields.

Should I use GUICtrlSetData in the while loop for each field or I can use IF statement in a function that create the form and after call (e.g.)

_CreateNewOrEditForm
from "New Contact" and "Edit Contact" buttons? Edited by maba
Link to comment
Share on other sites

  • 4 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...