Populating the textgadget issue

Just starting out? Need help? Post your questions and find answers here.
DT2000
User
User
Posts: 15
Joined: Tue Dec 02, 2014 5:09 am

Populating the textgadget issue

Post by DT2000 »

I am still rather new to PB and took the past year away from any code and I have decided to get back into it to learn more.

This maybe a rather simple and silly problem but the resolve escapes me and it has been nagging at me for a couple days now..... I am attempting to populate my textgadget with data from my DB however I am running into an issue when populating.

When I run the program the textgadget (8 of them), will populate fine for the first row of data in the table however it will not populate anything other than the first row. There has to be something I am overlooking or have forgotten about because I just can't seem to get it to populate the rest of the rows in the table.

Here is my existing populate procedure:

Code: Select all

    Procedure populateDHSF()
      dbcolumn = 0
      If DatabaseQuery(#dbaseID, "SELECT * FROM DrawHistorySF")  ; get all data from database DHSF
        NextDatabaseRow(#dbaseID)                                ; get next row in database
          spacer = Space(2)                                      ; add 2 spaces to the out put when populating
        For populate = #MonthDHSF To #B1DHSF                     ; populate columns MonthSF through B1DHSF
          SetGadgetText(populate, spacer + GetDatabaseString(#dbaseID, dbColumn))
          dbColumn +1
        Next
      EndIf
      FinishDatabaseQuery(#dbaseID)
    EndProcedure
I have looked at this for hours on end and tried many different things to try to get it to populate all the other rows into the respective columns but nothing has worked yet.

Any insight as to why it is not working would be much appreciated.
"Occasionally stumped.... But never defeated!"
User avatar
mk-soft
Always Here
Always Here
Posts: 6215
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Populating the textgadget issue

Post by mk-soft »

A TextGadget is not MultiLine.
Use EditorGadget or ListView and AddGadgetItem... :wink:
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4948
Joined: Sun Apr 12, 2009 6:27 am

Re: Populating the textgadget issue

Post by RASHAD »

As mk-soft mentioned
You can use ListViewGadget()
But if insist for some reasons to use TextGadget()
You can adapt next snippet
PB 5.6 x86 Win 10 x64

Code: Select all

text1$ = "Row #1"
text2$ = "Row #2"
text3$ = "Row #3"

LoadFont(0, "Times New Roman", 12)

If OpenWindow(0, 0, 0, 400, 400, "Tiny Note", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TextGadget(0,10,10,380,24,"",#PB_Text_Border)
SetGadgetFont(0,FontID(0))
SetGadgetColor(0, #PB_Gadget_BackColor, $CFFEFC)
SetGadgetColor(0, #PB_Gadget_FrontColor, $0000FF)
text$ = text1$ + #CRLF$ + text2$ + #CRLF$ + text3$
SetGadgetText(0,text$)
ResizeGadget(0,#PB_Ignore,#PB_Ignore, #PB_Ignore,GadgetHeight(0,#PB_Gadget_RequiredSize))

Repeat
    Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow

EndIf
Egypt my love
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Populating the textgadget issue

Post by Fangbeast »

Shouldn't that be

Code: Select all

While NextDatabaseRow(#dbaseID)                                ; get next row in database
wend
instead of just

Code: Select all

NextDatabaseRow(#dbaseID)                                ; get next row in database
Unless I missed something in his code?

Code: Select all

Procedure populateDHSF()
  
  dbcolumn = 0
  
  If DatabaseQuery(#dbaseID, "SELECT * FROM DrawHistorySF")  ; get all data from database DHSF
    
    While NextDatabaseRow(#dbaseID)                                ; get next row in database
    
      spacer = Space(2)                                      ; add 2 spaces to the out put when populating
      
      For populate = #MonthDHSF To #B1DHSF                     ; populate columns MonthSF through B1DHSF
        
        SetGadgetText(populate, spacer + GetDatabaseString(#dbaseID, dbColumn))
        
        dbColumn +1
        
      Next
    
    Wend
  
  EndIf
  
  FinishDatabaseQuery(#dbaseID)
  
EndProcedure
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
infratec
Always Here
Always Here
Posts: 7591
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Populating the textgadget issue

Post by infratec »

Hi,

as always... if you not provide a working code everything is like a look in a crystall ball.

Do you only want one row of the table? (than your code is nearly right)
For each field of the table you have one Textgadget?

My version, with correct position of FinishDatabaseQuery():

Code: Select all

Procedure populateDHSF()
  
  Protected dbcolumn.i, populate.i
  
  
  If DatabaseQuery(#dbaseID, "SELECT * FROM DrawHistorySF")  ; get all data from database DHSF
    If NextDatabaseRow(#dbaseID)                             ; get next row in database
      For populate = #MonthDHSF To #B1DHSF                   ; populate columns MonthSF through B1DHSF
        SetGadgetText(populate, "  " + GetDatabaseString(#dbaseID, dbColumn))
        dbColumn + 1
      Next
    Else
      Debug "No row available"
    EndIf
    FinishDatabaseQuery(#dbaseID)
  Else
    Debug DatabaseError()
  EndIf
EndProcedure
infratec
Always Here
Always Here
Posts: 7591
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Populating the textgadget issue

Post by infratec »

A working example:

Code: Select all

EnableExplicit

#dbaseID = 0

Enumeration
  #MonthDHSF
  #B1DHSF
EndEnumeration

Procedure populateDHSF()
  
  Protected dbcolumn.i, populate.i
  
  
  If DatabaseQuery(#dbaseID, "SELECT * FROM DrawHistorySF")  ; get all data from database DHSF
    If NextDatabaseRow(#dbaseID)                             ; get next row in database
      For populate = #MonthDHSF To #B1DHSF                   ; populate columns MonthSF through B1DHSF
        SetGadgetText(populate, "  " + GetDatabaseString(#dbaseID, dbColumn))
        dbColumn + 1
      Next
    EndIf
    FinishDatabaseQuery(#dbaseID)
  Else
    Debug DatabaseError()
  EndIf
EndProcedure



UseSQLiteDatabase()

OpenWindow(0, 0, 0, 400, 40, "Test", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)

If OpenDatabase(#dbaseID, ":memory:", "", "")
  
  If DatabaseUpdate(#dbaseID, "CREATE TABLE DrawHistorySF (a text, b text)")
    
    If DatabaseUpdate(#dbaseID, "INSERT INTO DrawHistorySF VALUES ('bla', 'blu')")
      
      TextGadget(#MonthDHSF, 10, 10, 180, 20, "", #PB_Text_Border)
      TextGadget(#B1DHSF, 200, 10, 190, 20, "", #PB_Text_Border)
      
      populateDHSF()
      
      Repeat
      Until WaitWindowEvent() = #PB_Event_CloseWindow
      
      CloseDatabase(#dbaseID)
      
    Else
      Debug DatabaseError()
    EndIf
  Else
    Debug DatabaseError()
  EndIf
Else
  Debug DatabaseError()
EndIf
Bernd
DT2000
User
User
Posts: 15
Joined: Tue Dec 02, 2014 5:09 am

Re: Populating the textgadget issue

Post by DT2000 »

I greatly appreciate all the replies, and I will go through each thoroughly to better understand what I have missed and/or misunderstood about my procedure and text gadgets. I should have mentioned that the window setup does have a textgadget named and in place for each column to be populated... from MonthDHSF through B1DHSF. A total 8 textgadgets, 1 for each column that would be populated by multiple rows from the DB (or so I thought).

Perhaps what I am mistaken about is that populating a textgadget… it can populate each row of the DB in each of the corresponding columns chronologically, row after row displaying in one textgadget. As an example, all the MonthDHSF data for all rows would populate one under the other, row by row when called to populate.

Here is my code example:

Code: Select all

  ;------------------------------------------
  ;-TEST TO POPULATE ALL ROWS IN TEXTGADGET
  ;------------------------------------------
  
  ;------------------------------------------
  ;-Initialize DB and Image Decoder
  ;------------------------------------------
  UseSQLiteDatabase()
  UsePNGImageDecoder()
  
  Enumeration
    
  ;===================================================================================
  ;-WINDOWS
  ;===================================================================================
  #MainWindow       ; Splash Window
  #DHSF             ; DHSF Window
  
  ;------------------------------------------
  ;-BackGrounds
  ;------------------------------------------
  #MainWindowBGIMG  ; Main Window Image
  #DHSFBGIMG        ; DHSF Window BackGround Image
  
  ;------------------------------------------
  ;-Main Window Buttons
  ;------------------------------------------
  #FWB1             ; Main Window Button 1 (Open DHSF Window)
  #FWB2             ; Main Window Button 3 (X)
  
  ;------------------------------------------
  ;-DHSF Window Buttons
  ;------------------------------------------
  #DHSFB1           ; DHSF Window Button 1 (Back Main Window)
  #DHSFB2           ; DHSF Window Button 2 (Exit)
  
  ;------------------------------------------
  ;-DHSF Constants
  ;------------------------------------------
  #MonthDHSF          ; Month of Draw
  #N1DHSF             ; Field 1
  #N2DHSF             ; Field 2
  #N3DHSF             ; Field 3
  #N4DHSF             ; Field 4
  #N5DHSF             ; Field 5
  #N6DHSF             ; Field 6
  #B1DHSF             ; Field 7
  
  ;------------------------------------------
  ;-Define DB ID
  ;------------------------------------------
  #dbaseID          ; DataBase ID
  
EndEnumeration

  ;------------------------------------------
  ;- Global Declaration
  ;------------------------------------------
  Global.s pathW$, bgimgfileM$, bgimgfileSF$, spacer = Space(2)
  
  ;------------------------------------------
  ;-Load the Window Background Images
  ;------------------------------------------
  bgimgfileM$ = pathW$ + "MainWindow.png"
  LoadImage(#MainWindowBGIMG, bgimgfileM$)
  bgimgfileSF$ = pathW$ + "SFWindow.png"
  LoadImage(#DHSFBGIMG, bgimgfileSF$)
  
  ;------------------------------------------
  ;-Populate DHSF Window
  ;------------------------------------------
 Procedure populateDHSF() 
  If DatabaseQuery(#dbaseID, "SELECT * FROM DHSF")           ; get all data from database DHSF
    NextDatabaseRow(#dbaseID)                                ; get next row in database
      spacer = Space(2)                                      ; add 2 spaces to tjhe out put when populating
      For populate = #MonthDHSF To #B1DHSF                   ; populate columns MonthSF through B1DHSF
        SetGadgetText(populate, spacer + GetDatabaseString(#dbaseID, dbColumn))
        dbColumn + 1
      Next
      EndIf 
      FinishDatabaseQuery(#dbaseID)
  EndProcedure
    
  ;------------------------------------------
  ;-DataBase
  ;------------------------------------------
  If OpenDatabase(#dbaseID, "DHSF.sqlite", "", "")
    
  ;------------------------------------------
  ;-Main Window
  ;------------------------------------------
    wFlags = #PB_Window_BorderLess|#PB_Window_ScreenCentered
    OpenWindow(#MainWindow, 0, 0, 800, 800, "", wFlags)
    ResizeImage(#MainWindowBGIMG, 800, 800)
    ImageGadget(#MainWindowBGIMG, 0, 0, 800, 800, ImageID(#MainWindowBGIMG))
    DisableGadget(#MainWindowBGIMG, 1)
    ButtonGadget(#FWB1, 225, 530, 60, 20, "Window 2")
    ButtonGadget(#FWB2, 500, 530, 60, 20, "Exit")
    
  ;------------------------------------------
  ;-DHSF Window
  ;------------------------------------------
    wFlags = #PB_Window_BorderLess|#PB_Window_ScreenCentered|#PB_Window_Invisible
    OpenWindow(#DHSF, 0, 0, 800, 800, "", wFlags)
    ResizeImage(#DHSFBGIMG, 800, 800)
    ImageGadget(#DHSFBGIMG, 0, 0, 800, 800, ImageID(#DHSFBGIMG))
    DisableGadget(#DHSFBGIMG, 1)
    ButtonGadget(#DHSFB1, 225, 530, 60, 20, "Back")
    ButtonGadget(#DHSFB2, 500, 530, 60, 20, "Exit")
    TextGadget(#MonthDHSF, 225, 150, 90, 350, "", #PB_Text_Border)
    TextGadget(#N1DHSF, 335, 150, 29, 350, "", #PB_Text_Border)
    TextGadget(#N2DHSF, 365, 150, 29, 350, "", #PB_Text_Border)
    TextGadget(#N3DHSF, 395, 150, 29, 350, "", #PB_Text_Border)
    TextGadget(#N4DHSF, 425, 150, 29, 350, "", #PB_Text_Border)
    TextGadget(#N5DHSF, 455, 150, 29, 350, "", #PB_Text_Border)
    TextGadget(#N6DHSF, 485, 150, 29, 350, "", #PB_Text_Border)
    TextGadget(#B1DHSF, 535, 150, 29, 350, "", #PB_Text_Border)
    HideWindow(#DHSF, 1)
    
  ;------------------------------------------
  ;-Window Event
  ;------------------------------------------
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_Gadget
          Select EventGadget()
                      
  ;------------------------------------------
  ;-Main Window Button Routin
  ;------------------------------------------
             Case #FWB1       ; Open DHSF Window
                HideWindow(#MainWindow, 1)
                HideWindow(#DHSF, 0)
                populateDHSF()
                SetActiveWindow(#DHSF)
                
                Case #FWB2    ; Exit 
                Quit = 1
                
  ;------------------------------------------
  ;-DHSF Window Button Routine
  ;------------------------------------------
              Case #DHSFB1
                HideWindow(#DHSF, 1)
                HideWindow(#MainWindow, 0)
                SetActiveWindow(#MainWindow)
               
              Case #DHSFB2
                Quit = 1
                
            EndSelect
        EndSelect

  Until Quit = 1
  CloseDatabase(#dbaseID)
EndIf  
In plain terms, if there are multiple rows of data consisting of 8 columns... when the populate procedure is called that it would then populate each row within the textgadget assigned respectively. I was not sure if each row in the DB required its own textgadget or whether it could populate all the data within a single textgadget. I thought, for some reason, that when populating a textgadget that it will populate all the data within the table no matter how many rows there are (going by the example in the IDE help menu under “DataBaseQuery” to call the list of "employees" from the given example).

I also, previously, wrote the code using an editorgadget where the data was entered into each column, all rows entered into one editorgadget respectively (using 8 editorgadgets), and it populated properly but for some reason my mind has kept telling me that I should have been able to populate the textgadget to do pretty much the same. Perhaps I have been thinking wrongly?

I also find that when I use the proper syntax for “While NextDatabaseRow” and the “Wend” to close the statement it will not populate at all… can someone explain why this occurs?
I will look over all the replies in depth to better understand my error in thinking.

I thank you all for the help and the given examples to help e understand and learn the proper flow if the code
"Occasionally stumped.... But never defeated!"
infratec
Always Here
Always Here
Posts: 7591
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Populating the textgadget issue

Post by infratec »

Code: Select all

;------------------------------------------
;-TEST TO POPULATE ALL ROWS IN TEXTGADGET
;------------------------------------------


Enumeration
  
  ;===================================================================================
  ;-WINDOWS
  ;===================================================================================
  #MainWindow       ; Splash Window
  #DHSF             ; DHSF Window
  
  ;------------------------------------------
  ;-BackGrounds
  ;------------------------------------------
  #MainWindowBGIMG  ; Main Window Image
  #DHSFBGIMG        ; DHSF Window BackGround Image
  
  ;------------------------------------------
  ;-Main Window Buttons
  ;------------------------------------------
  #FWB1             ; Main Window Button 1 (Open DHSF Window)
  #FWB2             ; Main Window Button 3 (X)
  
  ;------------------------------------------
  ;-DHSF Window Buttons
  ;------------------------------------------
  #DHSFB1           ; DHSF Window Button 1 (Back Main Window)
  #DHSFB2           ; DHSF Window Button 2 (Exit)
  
  ;------------------------------------------
  ;-DHSF Constants
  ;------------------------------------------
  #MonthDHSF          ; Month of Draw
  #N1DHSF             ; Field 1
  #N2DHSF             ; Field 2
  #N3DHSF             ; Field 3
  #N4DHSF             ; Field 4
  #N5DHSF             ; Field 5
  #N6DHSF             ; Field 6
  #B1DHSF             ; Field 7
  
  ;------------------------------------------
  ;-Define DB ID
  ;------------------------------------------
  #dbaseID          ; DataBase ID
  
EndEnumeration

;------------------------------------------
;- Global Declaration
;------------------------------------------
Global.s pathW$, bgimgfileM$, bgimgfileSF$, spacer = Space(2)

;------------------------------------------
;-Load the Window Background Images
;------------------------------------------
bgimgfileM$ = pathW$ + "MainWindow.png"
LoadImage(#MainWindowBGIMG, bgimgfileM$)
bgimgfileSF$ = pathW$ + "SFWindow.png"
LoadImage(#DHSFBGIMG, bgimgfileSF$)

;------------------------------------------
;-Populate DHSF Window
;------------------------------------------
Procedure populateDHSF()
  
  Protected dbColumn.i
  
  If DatabaseQuery(#dbaseID, "SELECT * FROM DHSF")           ; get all data from database DHSF
    While NextDatabaseRow(#dbaseID)                          ; get next row in database
      dbColumn = 0
      For populate = #MonthDHSF To #B1DHSF                   ; populate columns MonthSF through B1DHSF
        SetGadgetText(populate, GetGadgetText(populate) + RSet(GetDatabaseString(#dbaseID, dbColumn), 4) + #LF$)
        dbColumn + 1
      Next
    Wend
    FinishDatabaseQuery(#dbaseID)
  EndIf
EndProcedure



;------------------------------------------
;-Initialize DB and Image Decoder
;------------------------------------------
UseSQLiteDatabase()
UsePNGImageDecoder()

;------------------------------------------
;-DataBase
;------------------------------------------
;If OpenDatabase(#dbaseID, "DHSF.sqlite", "", "")
If OpenDatabase(#dbaseID, ":memory:", "", "")
  DatabaseUpdate(#dbaseID, "CREATE TABLE DHSF (a text, b text, c text, d text, e text, f text, g text, h text)")
  DatabaseUpdate(#dbaseID, "INSERT INTO DHSF VALUES ('11', '12', '13', '14', '15', '16', '17', '18')")
  DatabaseUpdate(#dbaseID, "INSERT INTO DHSF VALUES ('21', '22', '23', '24', '25', '26', '27', '28')")
  DatabaseUpdate(#dbaseID, "INSERT INTO DHSF VALUES ('31', '32', '33', '34', '35', '36', '37', '38')")
  
  ;------------------------------------------
  ;-Main Window
  ;------------------------------------------
  wFlags = #PB_Window_BorderLess|#PB_Window_ScreenCentered
  OpenWindow(#MainWindow, 0, 0, 800, 800, "", wFlags)
  ;ResizeImage(#MainWindowBGIMG, 800, 800)
  ;ImageGadget(#MainWindowBGIMG, 0, 0, 800, 800, ImageID(#MainWindowBGIMG))
  ;DisableGadget(#MainWindowBGIMG, #True)
  ButtonGadget(#FWB1, 225, 530, 60, 20, "Window 2")
  ButtonGadget(#FWB2, 500, 530, 60, 20, "Exit")
  
  ;------------------------------------------
  ;-DHSF Window
  ;------------------------------------------
  wFlags = #PB_Window_BorderLess|#PB_Window_ScreenCentered|#PB_Window_Invisible
  OpenWindow(#DHSF, 0, 0, 800, 800, "", wFlags)
  ;ResizeImage(#DHSFBGIMG, 800, 800)
  ;ImageGadget(#DHSFBGIMG, 0, 0, 800, 800, ImageID(#DHSFBGIMG))
  ;DisableGadget(#DHSFBGIMG, #True)
  ButtonGadget(#DHSFB1, 225, 530, 60, 20, "Back")
  ButtonGadget(#DHSFB2, 500, 530, 60, 20, "Exit")
  TextGadget(#MonthDHSF, 225, 150, 90, 350, "", #PB_Text_Border)
  TextGadget(#N1DHSF, 335, 150, 29, 350, "", #PB_Text_Border)
  TextGadget(#N2DHSF, 365, 150, 29, 350, "", #PB_Text_Border)
  TextGadget(#N3DHSF, 395, 150, 29, 350, "", #PB_Text_Border)
  TextGadget(#N4DHSF, 425, 150, 29, 350, "", #PB_Text_Border)
  TextGadget(#N5DHSF, 455, 150, 29, 350, "", #PB_Text_Border)
  TextGadget(#N6DHSF, 485, 150, 29, 350, "", #PB_Text_Border)
  TextGadget(#B1DHSF, 535, 150, 29, 350, "", #PB_Text_Border)
  
  ;------------------------------------------
  ;-Window Event
  ;------------------------------------------
  Repeat
    
    Event = WaitWindowEvent()
    
    Select EventWindow() 
      Case #MainWindow
        
        Select Event
          Case #PB_Event_Gadget
            Select EventGadget()
                ;------------------------------------------
                ;-Main Window Button Routin
                ;------------------------------------------
              Case #FWB1       ; Open DHSF Window
                HideWindow(#MainWindow, #True)
                HideWindow(#DHSF, #False)
                populateDHSF()
                SetActiveWindow(#DHSF)
                
              Case #FWB2    ; Exit
                Quit = #True
                
            EndSelect
            
        EndSelect
        
      Case #DHSF
        
        Select Event
          Case #PB_Event_Gadget
            
            Select EventGadget()
                ;------------------------------------------
                ;-DHSF Window Button Routine
                ;------------------------------------------
              Case #DHSFB1
                HideWindow(#DHSF, #True)
                HideWindow(#MainWindow, #False)
                SetActiveWindow(#MainWindow)
                
              Case #DHSFB2
                Quit = #True
                
            EndSelect
        EndSelect
        
    EndSelect
    
  Until Quit
  CloseDatabase(#dbaseID)
EndIf  
While NextDatabaseRow() ... Wend is a loop over all records of the result from the select.

But you should use a ListIconGadget() instead of the TextGadgets, because you run into a problem if there are more records.

Bernd
infratec
Always Here
Always Here
Posts: 7591
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Populating the textgadget issue

Post by infratec »

With ListIconGadget()

Code: Select all

;--------------------------------------------
;-TEST TO POPULATE ALL ROWS IN LISTICONGADGET
;--------------------------------------------


Enumeration
  
  ;===================================================================================
  ;-WINDOWS
  ;===================================================================================
  #MainWindow       ; Splash Window
  #DHSF             ; DHSF Window
  
  ;------------------------------------------
  ;-BackGrounds
  ;------------------------------------------
  #MainWindowBGIMG  ; Main Window Image
  #DHSFBGIMG        ; DHSF Window BackGround Image
  
  ;------------------------------------------
  ;-Main Window Buttons
  ;------------------------------------------
  #FWB1             ; Main Window Button 1 (Open DHSF Window)
  #FWB2             ; Main Window Button 3 (X)
  
  ;------------------------------------------
  ;-DHSF Window Buttons
  ;------------------------------------------
  #DHSFB1           ; DHSF Window Button 1 (Back Main Window)
  #DHSFB2           ; DHSF Window Button 2 (Exit)
  
  ;------------------------------------------
  ;-DHSF Constants
  ;------------------------------------------
  #MonthDHSF          ; Month of Draw
  #N1DHSF             ; Field 1
  #N2DHSF             ; Field 2
  #N3DHSF             ; Field 3
  #N4DHSF             ; Field 4
  #N5DHSF             ; Field 5
  #N6DHSF             ; Field 6
  #B1DHSF             ; Field 7
  
  ;------------------------------------------
  ;-Define DB ID
  ;------------------------------------------
  #dbaseID          ; DataBase ID
  
EndEnumeration

;------------------------------------------
;- Global Declaration
;------------------------------------------
Global.s pathW$, bgimgfileM$, bgimgfileSF$, spacer = Space(2)

;------------------------------------------
;-Load the Window Background Images
;------------------------------------------
bgimgfileM$ = pathW$ + "MainWindow.png"
LoadImage(#MainWindowBGIMG, bgimgfileM$)
bgimgfileSF$ = pathW$ + "SFWindow.png"
LoadImage(#DHSFBGIMG, bgimgfileSF$)

;------------------------------------------
;-Populate DHSF Window
;------------------------------------------
Procedure populateDHSF()
  
  Protected dbColumn.i
  
  If DatabaseQuery(#dbaseID, "SELECT * FROM DHSF")           ; get all data from database DHSF
    While NextDatabaseRow(#dbaseID)                          ; get next row in database
      dbColumn = 0
      Line$ = ""
      For populate = #MonthDHSF To #B1DHSF                   ; populate columns MonthSF through B1DHSF
        Line$ + GetDatabaseString(#dbaseID, dbColumn) + #LF$
        dbColumn + 1
      Next
      RTrim(Line$, #LF$)
      AddGadgetItem(#MonthDHSF, -1, Line$)
    Wend
    FinishDatabaseQuery(#dbaseID)
  EndIf
EndProcedure



;------------------------------------------
;-Initialize DB and Image Decoder
;------------------------------------------
UseSQLiteDatabase()
UsePNGImageDecoder()

;------------------------------------------
;-DataBase
;------------------------------------------
;If OpenDatabase(#dbaseID, "DHSF.sqlite", "", "")
If OpenDatabase(#dbaseID, ":memory:", "", "")
  DatabaseUpdate(#dbaseID, "CREATE TABLE DHSF (a text, b text, c text, d text, e text, f text, g text, h text)")
  DatabaseUpdate(#dbaseID, "INSERT INTO DHSF VALUES ('11', '12', '13', '14', '15', '16', '17', '18')")
  DatabaseUpdate(#dbaseID, "INSERT INTO DHSF VALUES ('21', '22', '23', '24', '25', '26', '27', '28')")
  DatabaseUpdate(#dbaseID, "INSERT INTO DHSF VALUES ('31', '32', '33', '34', '35', '36', '37', '38')")
  
  ;------------------------------------------
  ;-Main Window
  ;------------------------------------------
  wFlags = #PB_Window_BorderLess|#PB_Window_ScreenCentered
  OpenWindow(#MainWindow, 0, 0, 800, 800, "", wFlags)
  ;ResizeImage(#MainWindowBGIMG, 800, 800)
  ;ImageGadget(#MainWindowBGIMG, 0, 0, 800, 800, ImageID(#MainWindowBGIMG))
  ;DisableGadget(#MainWindowBGIMG, #True)
  ButtonGadget(#FWB1, 225, 530, 60, 20, "Window 2")
  ButtonGadget(#FWB2, 500, 530, 60, 20, "Exit")
  
  ;------------------------------------------
  ;-DHSF Window
  ;------------------------------------------
  wFlags = #PB_Window_BorderLess|#PB_Window_ScreenCentered|#PB_Window_Invisible
  OpenWindow(#DHSF, 0, 0, 800, 800, "", wFlags)
  ;ResizeImage(#DHSFBGIMG, 800, 800)
  ;ImageGadget(#DHSFBGIMG, 0, 0, 800, 800, ImageID(#DHSFBGIMG))
  ;DisableGadget(#DHSFBGIMG, #True)
  ButtonGadget(#DHSFB1, 225, 530, 60, 20, "Back")
  ButtonGadget(#DHSFB2, 500, 530, 60, 20, "Exit")
  
  ListIconGadget(#MonthDHSF, 225, 150, 330, 350, "Month", 90, #PB_ListIcon_FullRowSelect|#PB_ListIcon_GridLines)
  AddGadgetColumn(#MonthDHSF, 1, "N1", 30)
  AddGadgetColumn(#MonthDHSF, 2, "N2", 30)
  AddGadgetColumn(#MonthDHSF, 3, "N3", 30)
  AddGadgetColumn(#MonthDHSF, 4, "N4", 30)
  AddGadgetColumn(#MonthDHSF, 5, "N5", 30)
  AddGadgetColumn(#MonthDHSF, 6, "N6", 30)
  AddGadgetColumn(#MonthDHSF, 7, "B1", 30)
  
  ;------------------------------------------
  ;-Window Event
  ;------------------------------------------
  Repeat
    
    Event = WaitWindowEvent()
    
    Select EventWindow() 
      Case #MainWindow
        
        Select Event
          Case #PB_Event_Gadget
            Select EventGadget()
                ;------------------------------------------
                ;-Main Window Button Routin
                ;------------------------------------------
              Case #FWB1       ; Open DHSF Window
                HideWindow(#MainWindow, #True)
                HideWindow(#DHSF, #False)
                populateDHSF()
                SetActiveWindow(#DHSF)
                
              Case #FWB2    ; Exit
                Quit = #True
                
            EndSelect
            
        EndSelect
        
      Case #DHSF
        
        Select Event
          Case #PB_Event_Gadget
            
            Select EventGadget()
                ;------------------------------------------
                ;-DHSF Window Button Routine
                ;------------------------------------------
              Case #DHSFB1
                HideWindow(#DHSF, #True)
                HideWindow(#MainWindow, #False)
                SetActiveWindow(#MainWindow)
                
              Case #DHSFB2
                Quit = #True
                
            EndSelect
        EndSelect
        
    EndSelect
    
  Until Quit
  CloseDatabase(#dbaseID)
EndIf  
Bernd
DT2000
User
User
Posts: 15
Joined: Tue Dec 02, 2014 5:09 am

Re: Populating the textgadget issue

Post by DT2000 »

This part of the programming is not completed thanks to all advice and the help given.

Thank you all for being understanding of my lack of knowledge. I know I will be posting a new thread shortly on how to write a more complex procedure for comparing items stored in a DB, but that will wait until I start the coding the other project I am trying.
"Occasionally stumped.... But never defeated!"
Post Reply