Announcement

Collapse
No announcement yet.

How to place value in text box

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

  • How to place value in text box

    Still a newbie

    I am trying to display a value (text) in a text box on a form.

    Here is what I tried:
    CONTROL SET TEXT hDlg, %IDC_TEXTBOX_StoreNumber, StoreNumber

    The value is in the variable 'StoreNumber' and the '%IDC_TEXTBOX_StoreNumber' is the name of the control (I have also tried using the number - which happens to be 1013).

    I am getting an error 519 which seems to be telling me that hDlg is and undeclared variable.

    Obviously I don't know what I am doing.

    Can someone please help me on this?

    Thank You

  • #2
    (very limited code shown)
    hDlg is probably local to the function containing DIALOG SHOW ...
    Your CONTROL SET TEXT ... is probably in another function or sub
    If the CONTROL SET TEXT is in the call back function, then try:
    Code:
    CONTROL SET TEXT CBHNDL, %IDC_TEXTBOX_StoreNumber, STR$(StoreNumber)
    Inside the callback only CBHNDL gets hDlg from the Windows message.

    The other change I made ( "STR$()" ) converts the binary numeric StoreNumber to a string so that what you see in the textbox makes sense.

    Cheers,
    Dale

    Comment


    • #3
      Didn't work but gives a different error message.

      Thanks for your help.
      But I am still not there yet. (I don't really understand this DDT thing)

      Here is the whole block of code, maybe you can help better if you see everything I am doing wrong


      ** Load Store Number into Store Text Box **
      '------------------------------------------------------------------------------
      FUNCTION LoadStoreNumber AS LONG
      SQL_Stmt %SQL_STMT_IMMEDIATE, "SELECT * FROM tbllocationmaintenance"

      DO
      SQL_Fetch %NEXT_ROW
      IF SQL_EOD THEN EXIT DO
      IF SQL_ErrorPending THEN EXIT DO

      LOOP
      DIM StoreNo$(1 TO SQL_ResRowCount)
      LOCAL I AS LONG

      FOR I = 1 TO SQL_ResRowCount

      StoreNo$(I)=SQL_ResColStr(11)
      StoreNumber=StoreNo$(I)
      ' SQL_Msgbox StoreNo$(I), %MSGBOX_OK - used to test if I was really getting store number and it worked

      NEXT

      'Check for errors
      IF SQL_ErrorPending THEN
      SQL_MsgBox SQL_ErrorQuickAll, %MSGBOX_OK
      END IF

      CONTROL SET TEXT CBHNDL, %IDC_TEXTBOX_StoreName, StoreNumber
      ' this gets error 547

      END FUNCTION

      Comment


      • #4
        That's because "FUNCTION LoadStoreNumber AS LONG" is not the callback.

        Is this function called by clicking on a button?
        Dale

        Comment


        • #5
          two things which will help people to help you:

          Code:
          post compileable code
          use the # symbol in the forum editor to format your code
          Not everybody has perfect vision!

          Comment


          • #6
            Also, giving the error number and message (especially the number) gives those that wish to help a clue as to what is wrong. In time it will also give you a clue.
            Rod
            I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

            Comment


            • #7
              Starting to get a glimmer

              I appreciate your help greatly.

              OK, I see what you mean, it is not part of a CallBack. But I still don't see how to do this.

              It has nothing to do with a button click. When the application starts it runs this subroutine to fetch the current store number from the database (this is set by another application - not written in PB).

              Then what I want to to is to populate the text box with the store number. (The text box should be disabled, I think, but I don't know how to disable it either, I was planning to try to solve that next.)

              Then the next thing is to enter a file name (in a different text box) and open that file for reading.

              I don't think I have any problems reading from a file, reading the database, altering values based on what was in the file I retrieved, and writing back to the database. (I hope)

              I think I can do the rest if I can just get over the DDT hurdles.

              Comment


              • #8
                Got it!

                Had the statement in the wrong place!

                Got the disable also!

                Now I have to figure out how to the input from the text box.

                Comment


                • #9
                  You might want to use the %ES_READONLY style for your textbox instead of disabling it. Just a thought.
                  Rod
                  I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                  Comment


                  • #10
                    Disable text box

                    Thanks for that tip, I will do that instead.

                    Comment


                    • #11
                      Using a function is ok, but it needs to have the value of the parent dialog (window). If your variable hDlg is not GLOBAL, then it needs to be passed to the function, as shown in tthe snip below.
                      Code:
                      FUNCTION LoadStoreNumber(BYVAL hDlg as DWORD) AS LONG
                      .....
                      CONTROL SET TEXT hDlg , %IDC_TEXTBOX_StoreName, StoreNumber
                      
                      END FUNCTION
                      If you call this function from code in your dialogs CALLBACK function, then you would call it like this:

                      LoadStoreNumber(CB.HNDL) '9.00

                      LoadStoreNumber(CBHNDL) 'pre 9.00 versions

                      If you are calling your function from other places in your code, then insert the variable with tthe dialogs handle in the place of the CB.HNDL or CBHNDL

                      This is for the one problem you identified.
                      Rick Angell

                      Comment

                      Working...
                      X