As a demonstration for the Database PlugIn, here is a small application to store e-Mail addresses:
Before starting to code this example in Instant.EXE 3.0, start the database administration tool (iX_DataAdmin.exe). We will use this tool to create the database that we need to store eMail addresses and associated names. Enter eMail as a database name and hit the create button. The database file (email.mdb) will be created in the directory of the admin tool, but you can copy it were ever you want later on.
Now that the database file exists, we need a table within this database to store our information. Hit the create button in the "tables in database" section and enter a name (e.g. 'data'). Within this table, we need to create some fields that will contain our actual data. Usually, each record in a database is associated with an ID, but for this small example we won't need it, so you can delete that field. Instead, create to fields named 'Email' and 'Name'. Set the field type of both to '202=Text'.
The database is all set. Now you can fire up Instant.EXE 3.0 to use that database within your script.
As usual, first thing is to set up a GUI. Then we'll open the database and wait for user interaction:
Display Window 'E-Mail Address Book' (B=80, H=30, X=71, Y=31, Max. enabled, Inner size)
Display Control Label: activate only. (ID='lblName', X=5, Y=2, B=9, H=4)
Display Control Text box: (ID='inpName', X=20, Y=2, B=50, H=5, read only)
Display Control Label: activate only. (ID='lblEMail', X=5, Y=11, B=12, H=5)
Display Control Text box: (ID='inpEMail', X=20, Y=11, B=50, H=5, read only)
Display Control activate only. (ID='btnNext', X=55, Y=20, B=15, H=5)
Display Control activate only. (X=20, Y=20, B=15, H=5, ID='btnPrev')
Display Control activate only. (ID='btnAdd', X=37, Y=20, B=7, H=5)
Display Control activate only. (X=46, Y=20, B=7, H=5, ID='btnDel')
Database 'D:\asx\src\db_tut\email.MDB' (Table/SQL 'data', open)
Wait infinite...
When the user hits the add-button, two input-boxes will ask for the new contacts name and email address. Then a new dataset is created using the append-option of the database-command. Using the SQL insert-statement, the new contact's data is written to the database. When this is done, the database is closed and reopened to refresh the Instant.EXE 3.0 system variables.
:: iX_Display_Control(btnAdd)
Input "Please enter the name of the contact" in [NewName]
Input "Please enter the eMail-address of the contact" in [NewEmail]
Database '' (append dataset)
Database 'email.MDB' (Table/SQL 'INSERT INTO data (Email, Name) VALUES("[NewEmail]","[NewName]")', open)
Database 'email.MDB' (Table/SQL 'data', close)
Database 'email.MDB' (Table/SQL 'data', open)
Return
The subroutines for the buttons to navigate within the database are very similar, I will only explain the next-button for now. Using the if-command, it is checked whether we have already reached the end of the database. If not, the database-command with the 'Next database'-option is used to get that data. Only thing left to do is write the contents of that dataset to our GUI!
:: iX_Display_Control(btnNext)
If True: '[iX.Dataset.Number]<[iX.Dataset.Count]'
Database '' (next dataset)
Set in [iX.Display.Control(inpName).Text]: '[iX.Dataset.Field Name]'
Set in [iX.Display.Control(inpEMail).Text]: '[iX.Dataset.Field Email]'
End If
Return
Last but not least our application should supply a function to remove contacts from the database. Once again, this can be done with one call of the database-command. The subroutine first checks if there is any data left that can be deleted. If so, the current dataset is removed from the database by using the 'Delete dataset'-option of the database-command. Then the subroutine of the previous-button is called to update the information in the GUI.
:: iX_Display_Control(btnDel)
If True: '[iX.Dataset.Number]>0'
Database '' (delete dataset)
Call iX_Display_Control(btnPrev)
End If
Return
That's all. Easy, isn't it?