Hello, Being new to PB I am wondering what I can use to create a data browser screen that is filled with data from an SQLite table.
In access you can create a browse screen by containing a datasheet onto a form. FRom that you can then move up and down and allow the user to make selections on a record with the mouse or a key press. There was a simpler version called browse in dBASE and Clipper that basically read the table onto the screen. Some refer to this type of screen as a GRID.
From the available HELP and other PB manuals, PB Survival Guide etc I cannot find anything like them at all, nor any Grid functions.
If someone could point me in the right direction I'd greatly appreciate it.
Many thanks, C87
PB equivalent to Datasheet in Access or a browse in dBASE
PB equivalent to Datasheet in Access or a browse in dBASE
If it's falling over......just remember the computer is never wrong!
Re: PB equivalent to Datasheet in Access or a browse in dBAS
Hello and welcome to the forum!C87 wrote:Hello, Being new to PB I am wondering what I can use to create a data browser screen that is filled with data from an SQLite table.
In access you can create a browse screen by containing a datasheet onto a form. FRom that you can then move up and down and allow the user to make selections on a record with the mouse or a key press. There was a simpler version called browse in dBASE and Clipper that basically read the table onto the screen. Some refer to this type of screen as a GRID.
From the available HELP and other PB manuals, PB Survival Guide etc I cannot find anything like them at all, nor any Grid functions.
If someone could point me in the right direction I'd greatly appreciate it.
Many thanks, C87
dBASE and Clipper like the old good days
Actually in PureBasic as so simple as TBrowse() was in Clipper 5, but it is more poweful.
Check the following code. It is not very elegant but I hope that gives you an idea:
Code: Select all
UseSQLiteDatabase()
EnableExplicit
Procedure CheckDatabaseUpdate(Database, Query$)
Protected Result
Result = DatabaseUpdate(Database, Query$)
If Result = 0
Debug DatabaseError()
EndIf
ProcedureReturn Result
EndProcedure
Procedure CreateDB(Database$)
If CreateFile(0, Database$)
CloseFile(0)
If OpenDatabase(0, Database$, "", "")
CheckDatabaseUpdate(0, "CREATE TABLE food (name CHAR(50), weight INT)")
CheckDatabaseUpdate(0, "INSERT INTO food (name, weight) VALUES ('apple', '10')")
CheckDatabaseUpdate(0, "INSERT INTO food (name, weight) VALUES ('pear', '5')")
CheckDatabaseUpdate(0, "INSERT INTO food (name, weight) VALUES ('banana', '20')")
CloseDatabase(0)
Else
Debug "Can't open database !"
EndIf
Else
Debug "Can't create the database file !"
EndIf
EndProcedure
Procedure Browse(Database$, Table$, lstGadget)
Protected i
Protected TotalFields
Protected CurrRecord
Protected sRow.s
;~ Open Database
If OpenDatabase(0, Database$, "", "")
;~ Query the table and read all records
If DatabaseQuery(0, "SELECT * FROM " + Table$)
;~ Count the database fields
TotalFields = DatabaseColumns(0)
;~ Walk through the columns
For i = 0 To TotalFields - 1
;~ Begin to add columns from 1, because the column 0 ir reserved for record counter
AddGadgetColumn(lstGadget, i+1, Trim(DatabaseColumnName(0, i)), 100)
Next
;~ Initialize the counter and retrieve the records
CurrRecord = 1
While NextDatabaseRow(0)
;~ The Chr(10) is column separator
sRow = Trim(Str(CurrRecord)) + Chr(10)
;~ Retrieve all the fields of record
For i = 0 To TotalFields - 1
sRow + Trim(GetDatabaseString(0, i)) + Chr(10)
Next
;~ Add line to "Browse"
AddGadgetItem(lstGadget, -1, sRow)
;~ Increase the record counter
CurrRecord + 1
Wend
FinishDatabaseQuery(0)
CloseDatabase(0)
EndIf
EndIf
EndProcedure
Procedure BrowseDemo(Database$)
If OpenWindow(0, 0, 0, 700, 300, "Browse Demo", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(0, 10, 10, 680, 280, "Counter", 75, #PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
;~ "Browse" the table
Browse(Database$, "food", 0)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
EndProcedure
;~ Create the temporary database
Define Database$ = GetTemporaryDirectory()+"Database.sqlite"
CreateDB(Database$)
;~ Call the main function
BrowseDemo(Database$)
It creates and browse a SQLite database.
Regards.
Thanos
» myPersonal Banker :: Because you do not need to have a master degree in economics in order to organize your finances!
Re: PB equivalent to Datasheet in Access or a browse in dBAS
Many thanks for that Thanos, it runs fine and should get me going along the right lines. It's always the same with a new language. You need to know so many new functions and methods that it can seem to be quite impossible. Then after a few months they often become so obvious or trivial when looking back. PureB looks a good solution and so good to get away from OOP.
Regards, C87
Regards, C87
If it's falling over......just remember the computer is never wrong!
Re: PB equivalent to Datasheet in Access or a browse in dBAS
Indeed!C87 wrote:Many thanks for that Thanos, it runs fine and should get me going along the right lines. It's always the same with a new language. You need to know so many new functions and methods that it can seem to be quite impossible. Then after a few months they often become so obvious or trivial when looking back. PureB looks a good solution and so good to get away from OOP.
Regards, C87
But, please mention that Purebasic is a very good choice for development (e.g. easy syntax, very good editor, "self documented" procedure names, exe without dependencies, small footprint, native access for databases and speeeeeeeed). Also the very friendly and active forum.
It has so many commons with Clipper [WINKING FACE] Unfortunately I discovered it after losing my time with some other langs.
Check this free book for start
http://www.purebasic.fr/english/viewtop ... 9#p282952
Stay with Purebasic and you wll never regret it.
Regards
Thanos
Στάλθηκε από το Redmi Note 3 μου χρησιμοποιώντας Tapatalk
» myPersonal Banker :: Because you do not need to have a master degree in economics in order to organize your finances!