Announcement

Collapse
No announcement yet.

DDT listbox difficulties...

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

  • DDT listbox difficulties...

    Hi,
    I'm working on a small programme using DDT. I have a listbox, and I want to copy its contents into a text file.

    This is what I thought would work:

    Code:
    CONTROL GET TEXT hDlg, %HDList TO text$
    REPLACE $NUL WITH $CRLF IN text$
    PRINT #1, text$
    etc.

    However, I find that text$ is of zero length. Using LISTBOX GET TEXT to retrieve only the selected line of the listbox works, but I want the whole thing. I could use DDT to select each entry in turn, but that strikes me as a very clumsy solution.


    A separate problem is this: When the user of my programme tries to add an item to the listbox when that item is already present, I want the programme to essentially ignore the (attepted!) new addition, because such duplication is impossible in the context of the application's overall purpose.
    But this is simply impssible, as far as I can tell, using DDT. Some of the DDT LISTBOX tools handle the text in (one line of) the listbox, others handle the position in the listbox of the selected item. I want to be able to scan the listbox for a specific string.


    Both of these problems appear to be solve-able by using a string array in parallel with the listbox, but it's an inefficient, and less than elegant work-around.

    Is there a better way, something I'm missing?

    d.


    [This message has been edited by Dan Soper (edited September 26, 2000).]
    Dan

  • #2
    For your AddToListBoxIfNotAlreadyThere
    Code:
    Function List_AddQueEvent(ByVal Msg$) As Long
    Local Li&
      On Error Resume Next
    '--Check to see if Msg already in listbox--------
      Li& = SendMessage(ghQList, %LB_FINDSTRINGEXACT, -1,ByVal StrPtr(Msg$))
      If Li& >= 0 Then Function = %True:Exit Function
      Li& = SendMessage(ghQList, %LB_ADDSTRING, 0, StrPtr(Msg$))
    '--If not ScrollOff set focus to the new listitem-
      If skGetCheck(ghQScroll) = 0 Then
       Li& = SendMessage(ghQList, %LB_SETCURSEL, Li&, 0)
      End If
      Call LOG_MasterLogg(Msg$)
      Function = %True
    End Function
    ---
    In DDT-coding
      Control Send hDlg,%HDList,%LB_FINDSTRINGEXACT, -1,ByVal StrPtr(Msg$) To Li&
      Control Send hDlg,%HDList,%LB_ADDSTRING, 0, StrPtr(Msg$) To Li&
      Control Send hDlg,%HDList,%LB_SETCURSEL, Li&, 0 To Li&

    ------------------
    Fred
    mailto:[email protected][email protected]</A>
    http://www.oxenby.se



    [This message has been edited by Fred Oxenby (edited September 26, 2000).]
    Fred
    mailto:[email protected][email protected]</A>
    http://www.oxenby.se

    Comment


    • #3
      Thanks, Fred. I got a syntax error, but removing the "ByVal" fixed it.

      Does anyone have any suggestions to fix the LISTBOX GET TEXT problem? I did a search of this message board, but all I found was a reference to the problem, where a work-around was mentioned... but only in passing.

      Dan.
      Dan

      Comment


      • #4
        Dan,

        Fred answered your most difficult question, and I'll try to answer your
        remaining question. I seem to remember some thread in this forum revealing
        the fact that contrary to the Users' manual on p.213, that CONTROL GET TEXT
        does not give a single string with items separated by CHR$(0). But I couldn't
        find it with a search, and couldn't find it in Lance's Errata sheets. I believe
        the book and the IDE help to be in error.

        The following code is the best that I could do, and it may be no better than
        what you have already come up with. I did use a message box instead of copying
        to a text file.

        Code:
        #COMPILE EXE
        #DIM ALL
        #INCLUDE "win32api.INC"
        DECLARE CALLBACK FUNCTION dlgProc()
        
        FUNCTION PBMAIN
           LOCAL hDlg AS LONG, style AS LONG
           DIALOG NEW 0, "Listbox Test", , , 120, 120, %WS_SYSMENU + %WS_CAPTION TO hDlg
           CONTROL ADD TEXTBOX, hDlg, 100, "", 5, 5, 100, 10
           CONTROL ADD LISTBOX, hDlg, 101, , 5, 20, 100, 70, %LBS_SORT + %WS_VSCROLL
           CONTROL ADD BUTTON, hDlg, 102, "&Add", 15, 95, 40, 20
           CONTROL ADD BUTTON, hDlg, 103, "&Copy", 65, 95, 40, 20
           DIALOG SHOW MODAL hDlg CALL dlgProc
        END FUNCTION
        
        CALLBACK FUNCTION dlgProc()
           LOCAL i AS LONG, n AS LONG
           LOCAL txt AS STRING
           LOCAL s AS ASCIIZ * 80
           SELECT CASE CBMSG
           CASE %WM_COMMAND
              IF CBCTL = 102 THEN
                 CONTROL GET TEXT CBHNDL, 100 TO txt
                 LISTBOX ADD CBHNDL, 101, txt
                 CONTROL SET TEXT CBHNDL, 100, ""
                 CONTROL SET FOCUS CBHNDL, 100
              ELSEIF CBCTL = 103 THEN
                 CONTROL SEND CBHNDL, 101, %LB_GETCOUNT, 0, 0 TO n
                 FOR i = 0 TO n - 1
                    CONTROL SEND CBHNDL, 101, %LB_GETTEXT, i, VARPTR(s)
                    txt = txt + s + $CRLF
                 NEXT i
                 MSGBOX txt
              END IF
           END SELECT
        END FUNCTION
        ------------------

        Comment

        Working...
        X
        😀
        🥰
        🤢
        😎
        😡
        👍
        👎