Announcement

Collapse
No announcement yet.

Get text from Textbox

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

  • Get text from Textbox

    DDT Newbie

    How does one (after entering text in a text box) capture the entered text into a variable?

    I have tried CONTROL GET TEXT but it just gets whatever is displayed in the box when the application runs.

    What I want to do is be able to enter some text, do some checking, and if it correct go on, and if it is not, clear the textbox and enter some more text, etc.

    I really don't see how to do this, can anyone help me please?

  • #2
    If this is the same textbox that has the style %ES_READONLY you'll have to remove that style.
    Showing your full code would help tremendously.
    Rod
    In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

    Comment


    • #3
      Originally posted by Richard Schroeder View Post
      What I want to do is be able to enter some text
      Do you mean when you press enter? There are dozens of posts in these forums addressing this technique, and whether you actually need to catch the keypress message itself. Search on "Enter" in "title only" and you will see what I mean. As a clue, the answer might involve the WM_CHAR message and subclassing the edit control.

      Comment


      • #4
        Originally posted by Richard Schroeder View Post
        DDT Newbie

        How does one (after entering text in a text box) capture the entered text into a variable?

        I have tried CONTROL GET TEXT but it just gets whatever is displayed in the box when the application runs.

        What I want to do is be able to enter some text, do some checking, and if it correct go on, and if it is not, clear the textbox and enter some more text, etc.

        I really don't see how to do this, can anyone help me please?
        Richard,

        How about:
        Code:
          Control Get Text hDlg, This_id& To txt$
             If txt$ = What_I_Want_To_See$ Then
                Control Set Focus hDlg, Next_Id& 'Okay, so continue slogging on
               Else
                Control Set Text hDlg, This_id&, "          "
                Control Set Focus hDlg, This_Id& 'go back and do it again
             End If
        ===============================================
        "Assassins!"
        Arturo Toscanini (1867-1957) to his orchestra
        ===============================================
        Last edited by Gösta H. Lovgren-2; 10 Oct 2008, 10:59 AM.
        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


        • #5
          Not sure if you require the text to be monitored as it's being entered (as the below code shows how to do), or not. If you need the text to be checked/validated when a button is pressed, then that is a lot easier: just place your CONTROL GET TEXT code in response to the button's ID in WM_COMMAND.

          The following code shows how to monitor (and change) the text as it is being entered:

          Code:
          '________________________________________________________________________________________
          '
          ' Short example of text entry monitor (aka a very simple 'masked edit')
          '
          ' Kev Peel, Oct 2008
          '________________________________________________________________________________________
           
          #Compile Exe
          #Dim All
          #Include "win32api.inc"
           
          Global hDlg As Dword ' Easier to pass between functions.
           
          %IDC_TEXTBOX = 100
           
          '------------------------------------------------------------------------------
          ' Program Start Point
          '------------------------------------------------------------------------------
          Function PBMain
            Dialog New 0, "Enter Text", , , 220, 150, %ws_overlappedwindow To hDlg
            Control Add TextBox, hDlg, %IDC_TEXTBOX, "This Text Can Not Have Any Spaces!", 10, 10, 200, 12
            Dialog Show Modal hDlg Call dlgProc
           
          End Function
           
          '------------------------------------------------------------------------------
          ' Event handler callback for main dialog.
          '------------------------------------------------------------------------------
          CallBack Function dlgProc
            Select Case CbMsg
           
                   Case %wm_initdialog
                        ' For initial text formatting...
                        GoTo txtDoFormat:
           
                   Case %wm_command
                        Select Case CbCtl
                               Case %IDC_TEXTBOX
                                    If (CbCtlMsg = %en_change) Then
                                       ' This message is sent when the text has been changed...
                                       txtDoFormat:
           
                                       '-------------------------------------------------
                                       ' This section is only required if you want to change the text.
                                       Static nMasking As Long
                                       Local s As Long, e As Long
                                       If (nMasking) Then Exit Function
                                       nMasking = 1
                                       ' Save the caret position...
                                       Control Send CbHndl, %IDC_TEXTBOX, %EM_GETSEL, VarPtr(s), VarPtr(e)
                                       '-------------------------------------------------
           
           
                                       '-------------------------------------------------
                                       ' <analyze and/or change sText>
                                       Local sText As String
                                       Control Get Text CbHndl, %IDC_TEXTBOX To sText
                                       sText = Remove$(sText, $Spc) ' Sample: remove spaces.
                                       '-------------------------------------------------
           
           
                                       '-------------------------------------------------
                                       ' This section is only required if you want to change the text.
                                       Control Set Text CbHndl, %IDC_TEXTBOX, sText
                                       Control Send CbHndl, %IDC_TEXTBOX, %EM_SETSEL, s, e
                                       nMasking = 0
                                       '-------------------------------------------------
           
                                    End If
                        End Select
            End Select
           
          End Function
          kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

          Comment

          Working...
          X