Announcement

Collapse
No announcement yet.

How to read textbox and do keybd action???

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

  • How to read textbox and do keybd action???

    I have a sample code doing a simple addition but would like to do the addtion with just having the program read the textbox input and show the sum. as you type in a number. This would eliminate the SUM button.

    I know this would require doing some API calls which I am not familar with.
    Any sample code appreciated.

    Code:
    #COMPILE EXE
    #DIM ALL
    GLOBAL hDlg, SUM AS LONG, SUMA AS STRING
    
    CALLBACK FUNCTION ENDPROG()
     DIALOG END hDlg, 1
    END FUNCTION
    
    CALLBACK FUNCTION SUMPROG()
    LOCAL SUM1, SUM2 AS STRING
    CONTROL GET TEXT hDlg, 100  TO SUM1
    CONTROL GET TEXT hDlg, 101  TO SUM2
    
    SUM=VAL(SUM1)+VAL(SUM2): SUMA=STR$(SUM)
    CONTROL SET TEXT hDlg, 103, SUMA
    END FUNCTION
    
    FUNCTION PBMAIN() AS LONG
    LOCAL result AS LONG ': DIM SET1 AS SETUP1
    
    DIALOG NEW 0, "Read Text Box Change and Take Action"  ,,,240, 150, %WS_MINIMIZEBOX+%WS_SYSMENU, 0 TO hDlg
    
    CONTROL ADD TEXTBOX,hDlg, 100 ,""            ,80, 20, 30,14,
    CONTROL ADD TEXTBOX,hDlg, 101 ,""            ,80, 40, 30,14,
    CONTROL ADD LABEL  ,hDlg, 103 ,SUMA          ,80, 60, 30,14,
    CONTROL ADD BUTTON ,hDlg, 200 ,"&Sum"        ,80, 80, 70,14,  CALL SUMPROG
    CONTROL ADD BUTTON ,hDlg, 201 ,"&End Program",80,100, 90, 14, CALL ENDPROG
    
    CONTROL SET FOCUS hDlg, 102
    
    DIALOG SHOW MODAL hDlg TO result
    END FUNCTION
    Robert

  • #2
    I know this would require doing some API calls which I am not familar with
    False.

    You want to "do your thing" when .....
    (CBMSG= WM_COMMAND ) AND (CBCTLMSG = EN_CHANGE (or EN_UPDATE)) AND (CBCTL=%IDC_EDIT_CONTROL)
    Last edited by Michael Mattias; 13 Oct 2008, 07:19 PM.
    Michael Mattias
    Tal Systems Inc. (retired)
    Racine WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      I just got help with this same issue in this thread-
      http://www.powerbasic.com/support/pb...ad.php?t=38749

      Comment


      • #4
        Well that was simple thanks to Michael and Conrad's help.

        I did have problem with the the CASE..SELECT CASE code. I am not 100% in understanding this. Looking at the code, looks to me like it could be simplified.

        Code:
        #COMPILE EXE
        #DIM ALL
        GLOBAL hDlg, SUM AS LONG, SUMA AS STRING
        
        CALLBACK FUNCTION SumDIALOG1Proc()
            SELECT CASE AS LONG CB.MSG
                CASE %WM_COMMAND
                    SELECT CASE AS LONG CB.CTL
                        CASE 100
                            IF CB.CTLMSG = %EN_CHANGE THEN
                                 CALL SUMPROG
                            END IF
                    END SELECT
                    SELECT CASE AS LONG CB.CTL
                        CASE 101
                            IF CB.CTLMSG = %EN_CHANGE THEN
                                 CALL SUMPROG
                            END IF
                    END SELECT
            END SELECT
        END FUNCTION
        
        CALLBACK FUNCTION ENDPROG
         DIALOG END hDlg, 1
        END FUNCTION
        
        SUB SUMPROG()
        LOCAL SUM1, SUM2 AS STRING
        CONTROL GET TEXT hDlg, 100  TO SUM1
        CONTROL GET TEXT hDlg, 101  TO SUM2
        SUM=VAL(SUM1)+VAL(SUM2): SUMA=STR$(SUM)
        CONTROL SET TEXT hDlg, 103, SUMA
        END SUB
        
        FUNCTION PBMAIN() AS LONG
        LOCAL result AS LONG ': DIM SET1 AS SETUP1
        
        DIALOG NEW 0, "Read Text Box Change and Take Action"  ,,,240, 150, %WS_MINIMIZEBOX+%WS_SYSMENU, 0 TO hDlg
        
        CONTROL ADD TEXTBOX,hDlg, 100 ,""            ,80, 20, 30,14,
        CONTROL ADD TEXTBOX,hDlg, 101 ,""            ,80, 40, 30,14,
        CONTROL ADD LABEL  ,hDlg, 103 ,SUMA          ,80, 60, 30,14,
        CONTROL ADD BUTTON ,hDlg, 201 ,"&End Program",80,100, 90,14, CALL ENDPROG
        CONTROL SET FOCUS hDlg, 102
        
        DIALOG SHOW MODAL hDlg, CALL SumDIALOG1Proc TO result
        
        END FUNCTION
        Robert

        Comment


        • #5
          Yes it can be simplified, as follows:
          Code:
          SELECT CASE AS LONG CB.CTL
            CASE 100
                IF CB.CTLMSG = %EN_CHANGE THEN
                  CALL SUMPROG
                END IF
                      
            CASE 101
               IF CB.CTLMSG = %EN_CHANGE THEN
                 CALL SUMPROG
               END IF
            END SELECT
          Just use one SELECT/CASE to handle the CB.CTL value.
          Rod
          I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

          Comment


          • #6
            Just use one SELECT/CASE to handle the CB.CTL value
            And maybe just one 'case' therein....?

            Code:
             SELECT CASE AS LONG CB.CTL 
                CASE 100, 101 
                    IF CB.CTLMSG = %EN_CHANGE THEN 
                          CALL SUMPROG
                    END IF 
             END SELECT
            Michael Mattias
            Tal Systems Inc. (retired)
            Racine WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Or even:
              Code:
              SELECT CASE AS LONG CB.CTL 
                  CASE 100, 101 
                      IF CB.CTLMSG = %EN_CHANGE THEN CALL SUMPROG        
               END SELECT
              As long as one doesn't mind single line IF/THEN statements.
              4 lines in place of 12 in three easy steps.
              Rod
              I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

              Comment


              • #8
                > As long as one doesn't mind single line IF/THEN statements.

                Not an issue. I NEVER use single-line IF.

                And I certainly would never "mix" single-line IF with Block IF-THEN-ELSE in the same procedure (And neither should anyone else).
                Michael Mattias
                Tal Systems Inc. (retired)
                Racine WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  Originally posted by Rodney Hicks View Post
                  Or even...
                  If it's compact you're looking for:
                  Code:
                  MACRO mMCN(msg, ctl, notif) = MAK(DWORD, msg,MAK(WORD,ctl, notif))
                  .....
                  CALLBACK FUNCTION SumDIALOG1Proc()
                      SELECT CASE AS LONG MAK(DWORD,CB.MSG,MAK(WORD,CB.CTL, CB.CTLMSG))
                          CASE mMCN(%WM_COMMAND, 100, %EN_CHANGE) : BEEP
                          CASE mMCN(%WM_COMMAND, 101, %EN_CHANGE) : BEEP
                          CASE mMCN(%WM_COMMAND, 201, %BN_CLICKED) : DIALOG END CBHNDL, 0
                      END SELECT
                  Of course, you don't have to use the above method to combine the three numeric values, there are plenty of other ways of doing that.

                  Comment


                  • #10
                    I believe in "IF THEN" as one line, but only if (and ONLY IF) checking for 1 result.

                    Otherwise I check for multiple cases via "SELECT CASE"

                    (makes it much easier to code, and MUCH easier to read later after years of not reading the code)
                    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


                    • #11
                      Oh, well, boys will be boys....looks like the start of another "mine's smaller than yours" thread.....
                      Michael Mattias
                      Tal Systems Inc. (retired)
                      Racine WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment


                      • #12
                        looks like the start of another "mine's smaller than yours" thread.....
                        I surely didn't intend to start that, I was just thinking that new users could see steps in making their code less verbose, yet still be quite clear on what was happening.

                        As far as single line IF statements, I use MACRO SHOULD=IF and only use SHOULD in the place of a single line. I usually don't post code snippets with that because it causes other confusion.
                        Rod
                        I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                        Comment


                        • #13
                          As far as single line IF statements, I use MACRO SHOULD=IF and only use SHOULD in the place of a single line.....
                          Now THAT is a clever use of MACROs! (SHOULD X = 3 THEN ....)
                          Michael Mattias
                          Tal Systems Inc. (retired)
                          Racine WI USA
                          [email protected]
                          http://www.talsystems.com

                          Comment


                          • #14
                            Originally posted by Cliff Nichols View Post
                            I believe in "IF THEN" as one line...
                            IF you take the view that reducing the complexity (as seen by a human reader) of a function is desirable then

                            Code:
                            IF condition THEN EXIT FUNCTION
                            stuff....
                            beats
                            Code:
                            IF NOT condition THEN
                                 stuff....
                            END IF
                            by a short head

                            Comment

                            Working...
                            X