Announcement

Collapse
No announcement yet.

Question about LISTBOX ADD

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Question about LISTBOX ADD

    I'm certain something is wrong with this code. Can anybody see it plainly? I've been staring at it too long to make sense of it anymore.

    Code:
    SavedFile = FREEFILE
    OPEN $ListFileName FOR RANDOM AS SavedFile LEN = SIZEOF(CreditsForm)
       RecordCount = LOF(SavedFile) / SIZEOF(CreditsForm)
       FOR RecNo = 1 TO RecordCount
          GET #SavedFile,  RecNo, CreditsForm
          tempString = TRIM$(CreditsForm.SName)
          LISTBOX ADD hDlg, %IDC_LISTBOX1, tempString
       NEXT RecNo
       CLOSE #SavedFile
    Do not go quiet into that good night,
    ... Rage, rage against the dark.

  • #2
    Stan

    tempString needs to be an array.
    A dozen what.

    Comment


    • #3
      Code looks fine to me.

      CONTROL ADD LISTBOX requires an [optional] array, not LISTBOX ADD.
      kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

      Comment


      • #4
        my bad, What is it not doing correctly ?
        Last edited by Michael Mayerhoffer; 30 Mar 2008, 08:39 AM.
        A dozen what.

        Comment


        • #5
          Nothing is getting added to the control. I've verified that the file is present and contains valid data. I think I'll look at the CONTROL ADD LISTBOX statement (and ) to see if I've missed something in the CONTROL ADD parameters. Thanks for the clues guys.
          Do not go quiet into that good night,
          ... Rage, rage against the dark.

          Comment


          • #6
            >I've verified that the file is present and contains valid data

            Oh Really?

            I see neither ON ERROR, IF ERR THEN or a test for the number of records found in the file being greater than zero. (file can exist with size zero).

            e.g.
            Code:
            OPEN $ListFileName ..
            Is $LISTFILENAME fully qualified (code not shown)? Or are you making an assumption about your program's current path?



            MCM
            Last edited by Michael Mattias; 30 Mar 2008, 10:23 AM.
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Originally posted by Michael Mattias View Post
              >I've verified that the file is present and contains valid data

              Oh Really?

              I see neither ON ERROR, IF ERR THEN or a test for the number of records found in the file being greater than zero. (file can exist with size zero).
              Michael, you've pointed out some checks I should have done already so I did them. The following code reports no errors.
              Code:
              FUNTION ShowListBox() AS LONG
                 LOCAL lRslt  AS LONG
                 LOCAL SavedFile AS INTEGER
                 LOCAL RecordCount AS LONG
                 LOCAL RecNo AS LONG
                 LOCAL tempString AS STRING
              
                 LOCAL hDlg   AS DWORD
                 LOCAL hFont1 AS DWORD
              
                 DIALOG NEW hParent, "Lite Q", 251, 84, 190, 269, %WS_POPUP OR %WS_BORDER _
                    OR %WS_DLGFRAME OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_3DLOOK OR _
                    %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CLIENTEDGE OR _
                    %WS_EX_STATICEDGE OR %WS_EX_WINDOWEDGE OR %WS_EX_LEFT OR _
                    %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
                 DIALOG  SET COLOR    hDlg, -1, %WHITE
                 CONTROL ADD LISTBOX, hDlg, %IDC_LISTBOX1, , 5, 30, 190, 190, _
                    %WS_VISIBLE OR %WS_TABSTOP OR %WS_VSCROLL OR %LBS_STANDARD OR _
                    %LBS_SORT OR %LBS_NOTIFY OR %LBS_OWNERDRAWFIXED OR %LBS_HASSTRINGS OR _
                    %LBS_WANTKEYBOARDINPUT OR %LBS_DISABLENOSCROLL, %WS_EX_CLIENTEDGE OR _
                    %WS_EX_DLGMODALFRAME OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                    %WS_EX_RIGHTSCROLLBAR
                 CONTROL ADD BUTTON,  hDlg, %IDC_cmdOpenInRMode, "Open in R " + _
                    "Mode", 25, 225, 65, 40, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR _
                    %BS_TEXT OR %BS_MULTILINE OR %BS_PUSHBUTTON OR %BS_CENTER OR _
                    %BS_VCENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
                 CONTROL ADD BUTTON,  hDlg, %IDC_cmdOpenInPMode, "Open in " + _
                    "P Mode", 110, 225, 65, 40, %WS_CHILD OR %WS_VISIBLE OR _
                    %WS_TABSTOP OR %BS_TEXT OR %BS_MULTILINE OR %BS_PUSHBUTTON OR _
                    %BS_CENTER OR %BS_VCENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
              
                 hFont1 = PBFormsMakeFont("Times New Roman", 12, 400, %FALSE, %FALSE, _
                    %FALSE, %ANSI_CHARSET)
              
                 DIALOG  SEND hDlg, %WM_SETFONT, hFont1, 0
                 CONTROL SEND hDlg, %IDC_LISTBOX1, %WM_SETFONT, hFont1, 0
                 CONTROL SEND hDlg, %IDC_cmdOpenInRMode, %WM_SETFONT, hFont1, 0
                 CONTROL SEND hDlg, %IDC_cmdOpenInPMode, %WM_SETFONT, hFont1, 0
                
              
                 ON ERROR GOTO ListBoxErrorHandler:
                 SavedFile = FREEFILE
                 OPEN $ListFileName FOR RANDOM AS SavedFile LEN = SIZEOF(CreditsForm)
                 RecordCount = LOF(SavedFile) / SIZEOF(CreditsForm)
                 IF RecordCount < 1 THEN
                    MSGBOX "ListBox error: RecordCount < 1", %MB_TASKMODAL OR %MB_ICONWARNING, $Title
                 END IF
                 FOR RecNo = 1 TO RecordCount
                    GET #SavedFile,  RecNo, CreditsForm
                    tempString = CreditsForm.SName
                    MSGBOX "RecNo:" & TRIM$(STR$(RecNo)) & " " & tempString, %MB_TASKMODAL OR %MB_ICONINFORMATION, $Title
                    IF LEN(TRIM$(tempString)) > 0 THEN
                       LISTBOX ADD hDlg, %IDC_LISTBOX1, tempString
                    END IF
                 NEXT RecNo
                 CLOSE #SavedFile
                 ON ERROR GOTO 0
              
                 DIALOG SHOW MODAL hDlg, CALL ShowSavedShowsProc TO lRslt
              
                 FUNCTION = lRslt
                 EXIT FUNCTION
                 
                 ListBoxErrorHandler:
                    tempString = ERROR$
                    lRslt = ERRCLEAR
                    MSGBOX "ListBox error: " & tempString & " #" & TRIM$(STR$(lRslt)), %MB_TASKMODAL OR %MB_ICONWARNING, $Title
                 RETURN
              END FUNCTION
              Is $LISTFILENAME fully qualified (code not shown)? Or are you making an assumption about your program's current path?

              MCM
              Fully qualified: "d:\Program Files\MyApp\filename.ext"

              The MSGBOXes show that the file is being accessed and the information is getting into the RecNo and tempString variables as expected.

              The only thing it's NOT doing is showing the data in the listbox. (I don't think it makes a difference, but this dialog was built with PBForms 1.51.)

              Stan
              Do not go quiet into that good night,
              ... Rage, rage against the dark.

              Comment


              • #8
                Code:
                LBS_OWNERDRAWFIXED
                Are you handling WM_DRAWITEM? You must handle this message to display strings with the above list box style.
                kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

                Comment


                • #9
                  Originally posted by Kev Peel View Post
                  Code:
                  LBS_OWNERDRAWFIXED
                  Are you handling WM_DRAWITEM? You must handle this message to display strings with the above list box style.

                  thanks Kev... and no, I'm not handling that message.

                  Good Grief! the gaps in my knowledge seem to be whole galaxies wide sometimes!

                  Dumb follow-up: how do you handle that message? Would this work?

                  CASE %WM_DRAWITEM
                  CONTROL REDRAW hDlg, id&

                  Stan

                  NOPE, that didn't work.
                  Last edited by StanHelton; 30 Mar 2008, 11:41 AM. Reason: provide more info
                  Do not go quiet into that good night,
                  ... Rage, rage against the dark.

                  Comment


                  • #10
                    Well the easiest way is to remove the style

                    If you need the additional drawing features, search the forum for "LBS_OWNERDRAWFIXED" or "ownerdrawn list box", there are several examples. It's a bit more complex than placing a simple redraw message - the text and focus rectangle have to be drawn as well. Basically, anything displayed in the item rectangle must be drawn by yourself using Windows' GDI commands.
                    kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

                    Comment


                    • #11
                      OOOOOOkay.....

                      Style removed !!! Everything works perfectly now.

                      Thank you, Kev.
                      Do not go quiet into that good night,
                      ... Rage, rage against the dark.

                      Comment


                      • #12
                        Couple of thoughts I had looking at this. Of course you need to verify your reading the data and the variables have what you expect, as Kev already stated..... But also, unless you are continuing to add to already existing items, you need to clear the listbox first.

                        Listview_deleteallitems (htcl)

                        and start with a clean slate. Also, I'd recommend Turning off the listbox until you've passed all your data, otherwise it will redraw after each add.

                        SENDMESSAGE ( hCtl,%WM_SETREDRAW, %FALSE, 0) 'turn it off

                        ...fill up the listbox buffer...

                        SENDMESSAGE ( hCtl,%WM_SETREDRAW, %TRUE, 0)' display it

                        This will display quicker and look better doing it.

                        Also, may want to look at:

                        LISTVIEW_INSERTITEM
                        LISTVIEW_SETITEM

                        Depending on what your doing...
                        "Show me a young Conservative and I'll show you someone with no heart. Show me an old Liberal and I'll show you someone with no brains." ― Winston Churchill
                        "Socialism is the philosophy of failure, the creed of ignorance and the gospel of envy." ― Winston Churchill

                        Comment


                        • #13
                          Wow, the actual programming error was not in the function orginally selected for posting here.

                          But when a compilable example demonstrating the problem was posted a diagnosis and treatment followed promptly.

                          Gee, I wonder if it might not be such a bad idea to ALWAYS post a compilable example showing the problem?
                          Michael Mattias
                          Tal Systems (retired)
                          Port Washington WI USA
                          [email protected]
                          http://www.talsystems.com

                          Comment


                          • #14
                            Originally posted by Doug Hitchens View Post
                            Couple of thoughts I had looking at this. Of course you need to verify your reading the data and the variables have what you expect, as Kev already stated..... But also, unless you are continuing to add to already existing items, you need to clear the listbox first.
                            Doug:
                            Yes, that occurred to me when I first designed this dialog. There's a recent thread somewhere in these forums (please forgive my poor memory) discussing where to put loading instructions for controls. (I think they were discussing designing CONTROLS.)

                            Long story short: I load the ListBox in the ShowDIALOG() function just before the DIALOG SHOW statement. Then I don't touch the listed items in the CALLBACK except for handling the select messages.

                            If I understand correctly how this is working, the ListBox is destroyed along with the dialog when it is closed. So each time ShowDIALOG() is called I'm loading a fresh clean ListBox. This particular ListBox is loaded only once per instance of the parent dialog and the data doesn't change while this dialog is active.

                            It's limited, but it's doing what I need it to do. My theory is that I'm using less memory/stack space this way.


                            Michael:
                            Wow, the actual programming error was not in the function orginally selected for posting here.
                            I don't think that is all that unusual. Complex programs often crash on an instruction that is dependent on the code behind the real error.


                            But when a compilable example demonstrating the problem was posted a diagnosis and treatment followed promptly.
                            Judgement call. This app is over 70,000 lines code. Posting too much code would not only waste my time (removing the NDA protected parts), but might waste the time of the good people in this forum who would, no doubt, try to analyze the whole excerpt.

                            I think it is worth noting that the first 2 responses I received pointed me in the right direction and led me to the proper section of code to examine.

                            Gee, I wonder if it might not be such a bad idea to ALWAYS post a compilable example showing the problem?
                            I'm not sure I agree with "always". In this case the suggestions on the FUNCTION posted led me directly to the problem ShowDialog function instead of the whole I/O module as I was thinking when I first posted. I would like to think that I avoided wasting the time of the folks who were kind enough to help by choosing not to post a complex code sample when I had no idea where the error was.

                            The theoretical discussion helped me learn more than I would have if I just received a line or two of code to copy into my application. The really quick replies of my benefactors indicates to me that they, more experienced than I, did not spend an inordinate amount of time solving my problem.

                            Posting a compilable example is a very good method, BUT it can be overkill. I'm trying to be kind to those who are in turn kind to me by looking at my code.

                            BTW: I have a great deal of respect for Michael Meyerhoffer, Kev Peel, Michael Matthias, and Doug Hitchens, all of whom replied to my request for help. I appreciate the help and the ideas and the code snippets. I use them. Perhaps I just have a different idea of courtesy when asking for help.

                            Ok. I'm done venting.

                            Thanks again,
                            Stan
                            Do not go quiet into that good night,
                            ... Rage, rage against the dark.

                            Comment


                            • #15
                              This app is over 70,000 lines code. Posting too much code ...
                              I KNOW we have had instances here where someone had a problem with a "large" program; but when reducing their code to create a small compilable example they had either an "AHA!" or "DUH!" moment which identified the problem and pointed to the correction.

                              Posting a compilable example is a very good method, BUT it can be overkill.
                              Well, I guess that makes for at least two opinions.....


                              MCM
                              Michael Mattias
                              Tal Systems (retired)
                              Port Washington WI USA
                              [email protected]
                              http://www.talsystems.com

                              Comment


                              • #16
                                I KNOW we have had instances here where someone had a problem with a "large" program; but when reducing their code to create a small compilable example they had either an "AHA!" or "DUH!" moment which identified the problem and pointed to the correction.
                                hmmmm.....nowwww that could NOT be directed at me now could it?

                                I will admit though...the "SMALLER"(thanx to PB) my programs get (from what may be millions of lines, to thousands or hundreds of thou) the more I find some small mistake is either found in a oversimplified example of the problem, or me going when about to post a problem.

                                although I will admit, total pain when you can not figure out how to post a demo, if you can not figure out ideas of where problem points may be....but just the process of trying to break down to simple example, often brings you to
                                Engineer's Motto: If it aint broke take it apart and fix it

                                "If at 1st you don't succeed... call it version 1.0"

                                "Half of Programming is coding"....."The other 90% is DEBUGGING"

                                "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                                Comment


                                • #17
                                  Originally posted by Cliff Nichols View Post
                                  but just the process of trying to break down to simple example, often brings you to
                                  That's about the most powerful problem-solving technique going, a lot of people in the world of commercial IT are hooked on "peer review" but for my money the "isolate the problem" approach should always come first.

                                  Comment


                                  • #18
                                    Ok. Maybe I'm wrong.
                                    Do not go quiet into that good night,
                                    ... Rage, rage against the dark.

                                    Comment


                                    • #19
                                      Originally posted by Cliff Nichols View Post
                                      hmmmm.....nowwww that could NOT be directed at me now could it?
                                      Nah, it was directed at ME. I could tell just by M's tone and inflection.

                                      =========================================
                                      "Necessity is the plea
                                      for every infringement of human freedom.
                                      It is the argument of tyrants;
                                      it is the creed of slaves."
                                      William Pitt, The Younger (1759-1806)
                                      British statesman.
                                      =========================================
                                      It's a pretty day. I hope you enjoy it.

                                      Gösta

                                      JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                                      LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                                      Comment


                                      • #20
                                        MCM: "...AHA! or DUH! Moment..."
                                        Cliff: "nowwww that could NOT be directed at me now could it? "
                                        Gosta: "Nah, it was directed at ME.
                                        Search, all open forums, all dates, message text, search term: ":doh"

                                        Five+ pages of hits.

                                        MCM
                                        Michael Mattias
                                        Tal Systems (retired)
                                        Port Washington WI USA
                                        [email protected]
                                        http://www.talsystems.com

                                        Comment

                                        Working...
                                        X