Announcement

Collapse
No announcement yet.

dumb question 2- keypad entry programming

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

  • dumb question 2- keypad entry programming

    Again thanks to all for the help last week. I'm starting my first little project with PB/WIN8 and would appreciate some advice. (I know that WIN10 was recommended, but I already own 8 and I don't want to spend money at this point on what is experimentation.) I am re-writing a little utility to help with a statistical conversion for neuropsychological test scores. (I had a program for PB/DOS years ago, that WIN-style programming can be made better, I think).

    I'd like to have a numeric keypad accessible with mouse clicks (with comparable data entry for the standard keyboard number keys and the keyboard keypad). My initial foray into this suggests that I probably could write the software needed to create a keypad in a window (i.e., design the button and interate each one) OR I might use Forms 1.5 or EZ-GUI to create this data entry method. I spent somewhere between 3 and 4 hours in the PB forums yesterday looking for someone else's subroutine work (I only got 1/2 way through what was available), and gave up. There was at least one published routine, but it was designed for the console compiler. Anyway... Here is the question:

    Would it be better to design a routine that creates the keypad buttons from scratch or would it be better to bite the bullet and buy forms or EZ-GUI to do this. Or, does someone have a code fragment that would do this?

    Many thanks.

    Jim Thomas
    Maine




  • #2
    Howdy, Jim!
    I don't have PBWin8 to know how you create a button, Was a DDT Control Add Button command button available in PBWin8, or do you have to create one using SDK? I'm sure someone who remembers PBWin8 will step in with a suggestion.

    Comment


    • #3
      Originally posted by Gary Beene View Post
      Howdy, Jim!
      I don't have PBWin8 to know how you create a button, Was a DDT Control Add Button command button available in PBWin8, or do you have to create one using SDK? I'm sure someone who remembers PBWin8 will step in with a suggestion.
      DDT is there. It's fairly simple to build a load of "numeric key buttons". Give me a a bit of time

      Comment


      • #4
        OK, quick and dirty "numeric keyboard". No need for a visual designer such as PBForms for something this simple
        '
        Code:
        #COMPILE EXE
        #DIM ALL
        ENUM ctrls SINGULAR
            btn0 = 1000
            btn1
            btn2
            btn3
            btn4
            btn5
            btn6
            btn7
            btn8
            btn9
            txtInput
        END ENUM
        
        FUNCTION PBMAIN() AS LONG
           LOCAL lRslt AS LONG
           LOCAL hDlg  AS DWORD
        
            DIALOG NEW 0, EXE.FULL$, , , 200, 180, %WS_SYSMENU, TO hDlg
            CONTROL ADD BUTTON , hDlg,%btn7,"7",20,20,20,20
            CONTROL ADD BUTTON , hDlg,%btn8,"8",40,20,20,20
            CONTROL ADD BUTTON , hDlg,%btn9,"9",60,20,20,20
            CONTROL ADD BUTTON , hDlg,%btn4,"4",20,40,20,20
            CONTROL ADD BUTTON , hDlg,%btn5,"5",40,40,20,20
            CONTROL ADD BUTTON , hDlg,%btn6,"6",60,40,20,20
            CONTROL ADD BUTTON , hDlg,%btn1,"1",20,60,20,20
            CONTROL ADD BUTTON , hDlg,%btn2,"2",40,60,20,20
            CONTROL ADD BUTTON , hDlg,%btn3,"3",60,60,20,20
            CONTROL ADD BUTTON , hDlg,%btn0,"0",20,80,40,20
            CONTROL ADD TEXTBOX ,hDlg,%txtInput,"",20,110,120,20
            DIALOG SHOW MODAL hDlg, CALL MainDlgCB TO lRslt
        END FUNCTION
        
        CALLBACK FUNCTION MainDlgCB()
            STATIC strInput AS STRING
            SELECT CASE AS LONG CB.MSG
                CASE %WM_COMMAND
                    SELECT CASE AS LONG CB.CTL
                        CASE %Btn0 TO %btn9
                            IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                               strInput+= FORMAT$(CB.CTL-1000)
                               CONTROL SET TEXT CB.HNDL, %txtInput, strInput
                            END IF
                    END SELECT
            END SELECT
        END FUNCTION
        '
        Click image for larger version  Name:	keyboard.jpg Views:	0 Size:	13.7 KB ID:	813606

        Comment


        • #5
          Oops, No ENUM in PB8
          Also for PBWin 8, replace CB.CTL, CB.HNDL, CB.MSG etc with the "non-dot" equivalent i.e. CBCTL, CBHNDL, CBMSG etc

          Replace
          Code:
          ENUM ctrls SINGULAR
              btn0 = 1000
              btn1
              btn2
              btn3
              btn4
              btn5
              btn6
              btn7
              btn8
              btn9
              txtInput
          END ENUM

          with
          Code:
              %btn0 = 1000
              %btn1 = 1001
              %btn2 = 1002
              %btn3 = 1003
              %btn4 = 1004
              %btn5 = 1005
              %btn6 = 1006
              %btn7 = 1007
              %btn8 = 1008
              %btn9 = 1009
              %txtInput =1010

          Comment


          • #6
            To compile Stuart's eg with PBWin8..

            ADD
            %WS_SYSMENU = &H00080000
            ( OR #INCLUDE "win32api.inc" ' has %WS_SYSMENU equate definition for PBWin8 )

            REPLACE
            EXE.FULL$ w/ "Your App Caption" ( EXE read-only user defined type n/a PBWin8 )
            USE
            strInput = strInput + FORMAT$(CBCTL-1000) ' ( += n/a PBWin8 )

            Could include ampersand to number buttons' text for keyboard shortcuts?
            ie CONTROL ADD BUTTON , hDlg, %btn7, "&7", 20,20,20,20
            Rgds, Dave

            Comment


            • #7
              Originally posted by Dave Biggs View Post
              To compile Stuart's eg with PBWin8..

              ADD
              %WS_SYSMENU = &H00080000
              ( OR #INCLUDE "win32api.inc" ' has %WS_SYSMENU equate definition for PBWin8 )

              REPLACE
              EXE.FULL$ w/ "Your App Caption" ( EXE read-only user defined type n/a PBWin8 )
              USE
              strInput = strInput + FORMAT$(CBCTL-1000) ' ( += n/a PBWin8 )

              Could include ampersand to number buttons' text for keyboard shortcuts?
              ie CONTROL ADD BUTTON , hDlg, %btn7, "&7", 20,20,20,20
              Thanks for that. It's been a long time since I used ver8 and I'd forotten some of what was added in 9 and 10.

              (It's a good illustration of the advantages of upgrading )

              Comment


              • #8
                There are no dumb questions. Not sure if you mean you want to press keypad keys via a program, but in case you do - below code shows how to simulate click on a keyboard key, in this case the NumLock key via the Keybd_Event API call. Just add a NumLock button to Stuart's fine example and insert the 2 Keybd_Event calls to toggle it on/off.

                The question if you should get a Visual Designer tool like PB Forms or Chris Boss' very fine EzGui is related to development time (and money, of course - but time = money too, so..). A Visual Designer does exacly what it says - Software Design goes so much faster and easier using one, but one can of course also do eveything "by hand" with careful positioning and many recompiles. Also, getting the upgrade to PBWin 9 or 10 is so much worth it, because most examples in Source code forum, etc, done the last 15-20 years are done using later compilers than PBWin 8 - and the code editor is also better in later versions. Anyway - without really knowing the goal - here's a way simulate key clicks via code:
                '
                Code:
                   ' repeat to toggle NumLock key on/off
                   Keybd_Event %VK_NUMLOCK, 0, 0, 0                ' press key
                   Keybd_Event %VK_NUMLOCK, 0, %KEYEVENTF_KEYUP, 0 ' release key
                
                  ' Equates for Num keys - from WIN32API.INC.
                  '%VK_NUMPAD0  = &H60
                  '%VK_NUMPAD1  = &H61
                  '%VK_NUMPAD2  = &H62
                  '%VK_NUMPAD3  = &H63
                  '%VK_NUMPAD4  = &H64
                  '%VK_NUMPAD5  = &H65
                  '%VK_NUMPAD6  = &H66
                  '%VK_NUMPAD7  = &H67
                  '%VK_NUMPAD8  = &H68
                  '%VK_NUMPAD9  = &H69
                  '%VK_MULTIPLY = &H6A
                  '%VK_ADD      = &H6B
                  '%VK_SEPARATOR= &H6C
                  '%VK_SUBTRACT = &H6D
                  '%VK_DECIMAL  = &H6E
                  '%VK_DIVIDE   = &H6F
                  '%VK_NUMLOCK  = &H90
                '

                Comment


                • #9
                  Haha, well done Stuart! You sure are fast - at 03:42 AM you wrote "Give me a bit of time". At 04:00 AM you present a complete code..

                  Comment


                  • #10
                    Originally posted by Borje Hagsten View Post
                    Haha, well done Stuart! You sure are fast - at 03:42 AM you wrote "Give me a bit of time". At 04:00 AM you present a complete code..
                    But it needed a bit of work to run on Ver8

                    Comment


                    • #11
                      Originally posted by Jim Thomas View Post
                      I'd like to have a numeric keypad accessible with mouse clicks (with comparable data entry for the standard keyboard number keys and the keyboard keypad).
                      A single sub-classed graphic control could handle both the key input and the mouse-click keypad.
                      The world is strange and wonderful.*
                      I reserve the right to be horrifically wrong.
                      Please maintain a safe following distance.
                      *wonderful sold separately.

                      Comment


                      • #12
                        Originally posted by Kurt Kuzba View Post

                        A single sub-classed graphic control could handle both the key input and the mouse-click keypad.
                        I think that may be a bit advanced for the OP at this stage.

                        Comment


                        • #13
                          IIRC one of the Petzold programs is a complete "calculator" program using an onscreen keyboard. I know there is a ZIP file of these programs posted here somewhere.

                          But using it depends ..if you are looking for the utility or looking for the experience and emotional satisfaction of creating your own.
                          Michael Mattias
                          Tal Systems (retired)
                          Port Washington WI USA
                          [email protected]
                          http://www.talsystems.com

                          Comment


                          • #14
                            Originally posted by Michael Mattias View Post
                            IIRC one of the Petzold programs is a complete "calculator" program using an onscreen keyboard. I know there is a ZIP file of these programs posted here somewhere.

                            But using it depends ..if you are looking for the utility or looking for the experience and emotional satisfaction of creating your own.
                            Have we forgotten this thread already?
                            https://forum.powerbasic.com/forum/u...ded#post813196

                            Given that this is the OP's first PBWin (or any WIndows) application and he is updating an old DOS program he wrote many years ago, I hardly think that Petzold is an appropriate recommendation at this stage. He's looking for help in starting to use PBWin

                            Comment


                            • #15
                              Originally posted by Stuart McLachlan View Post

                              I think that may be a bit advanced for the OP at this stage.
                              I don't know. Aside from setting up the subclass, the mouse click position and key
                              input handling would be pretty close to how we did things in BASIC for DOS.
                              The world is strange and wonderful.*
                              I reserve the right to be horrifically wrong.
                              Please maintain a safe following distance.
                              *wonderful sold separately.

                              Comment


                              • #16
                                Wow! Many thanks one and all for the assistance. This should/will help me jump start this little project. I don't know how others have learned, but going through a program or routine, step by step to see how something can be done has always helped me understand how it works. I am finding the DDT to essentially be a programming language unto itself and learning to use it is challenging, but also stimulating.

                                Mr. McLachian, thank you for the consult and code, I could not have asked for more. And I should add: I am impressed with your speed! (Your point in post #7 is pushing me toward upgrading, loath that I am to spend money.) And Mr. Biggs, thanks for the additional code for Ver 8.

                                Mr. Mattias, I will look for the Petzold zip file. Thank you! I haven't pursued it yet and I suspect that since it come from Petzold it relies on the WIN API (I hope that I am correct in drawing the distinction). Looking into and comparing the DDT and WIN API methods will be helpful in my re-education. Your point regarding utility versus personal satisfaction is a good one. As I do not make a living via programming, satisfaction is more important to me. My primary goal is to obtain cognitive stimulation and to correct a 20+ year delay in progressing from DOS to Win programming. I never had the time to do that because I was raising children and working a 60 hour per week job. (Time is a finite construct.)

                                Mr. Hagsten, Thank you for the reassurance re: dumb questions. I also do not believe that questions are "dumb" per se, but one of my quirks (for want of a better word) is to figure things out on my own and really, I dislike being a burden for others. Still, obviously, that's not always possible. Thanks also for the comment re: Ver 8 compared to 9 and 10. Spending a little cash may be necessary.

                                Mr. Kuzba, your recc is appreciated. With my current state of knowledge I am unable to use it, but I will explore. Thanks.

                                Lastly, Mr. Beene, thanks for the "Howdy" (and the earlier recommendations). "Howdy" is welcoming and truly appreciated. I am a little uncomfortable asking for help and feeling welcomed into the conversation means a lot. I did go over the introductory information from your website and it was quite helpful. Again, thanks.

                                Now... off to the IDE.

                                Jim

                                Comment


                                • #17
                                  Hi Jim

                                  PBWin8 is most capable in the meantime - plenty there to experiment with!

                                  Unfortunately it comes with an old (16Bit) version of DlgEdit.exe so you might want to grab a copy of ResEd.exe or similar to use as a visual designer when working out the Size and Spacing of controls on your Dialogs.

                                  Here is another compilable version of Stuart's eg to play with..
                                  '
                                  Code:
                                  #COMPILE EXE                ' PBWin8 ^
                                  #DIM ALL
                                  #INCLUDE "win32api.inc"     ' API declarations: Equates, Functions etc
                                   
                                  %btn0   = 1000
                                  %btn1   = 1001
                                  %btn2   = 1002
                                  %btn3   = 1003
                                  %btn4   = 1004
                                  %btn5   = 1005
                                  %btn6   = 1006
                                  %btn7   = 1007
                                  %btn8   = 1008
                                  %btn9   = 1009
                                  %txtInput =1010
                                  %btnOK  = %IDOK             ' Dialog Box Command ID = 1. Declared in win32api.inc
                                   
                                  $AppName = "Your App Caption"
                                  '------------------/
                                   
                                  FUNCTION PBMAIN() AS LONG
                                   LOCAL lRslt    AS LONG
                                   Local hParent  AS DWORD
                                   LOCAL sCaption AS String
                                   
                                    sCaption = $AppName
                                   
                                    CALL ShowKeypad(%HWND_DESKTOP, sCaption) TO lRslt       ' Call your Dialog
                                   
                                    IF lRslt = 0 THEN
                                      MSGBOX "Dialog Escaped, lRslt = "+FORMAT$(lRslt), %MB_SYSTEMMODAL, sCaption
                                    ELSE
                                      MSGBOX "Dialog Closed, lRslt = "+FORMAT$(lRslt), %MB_SYSTEMMODAL, sCaption
                                    END IF
                                   
                                  END FUNCTION
                                  '------------------/PBMain
                                   
                                  FUNCTION ShowKeypad(ByVal hParent AS DWORD, ByVal sCaption AS STRING) AS LONG
                                   LOCAL lRslt AS LONG
                                   LOCAL hDlg  AS DWORD
                                   
                                    DIALOG NEW hParent, $AppName, , , 200, 180, %WS_SYSMENU, TO hDlg
                                      ' First control (in source code) gets focus when Dialog opens
                                      CONTROL ADD TEXTBOX ,hDlg,%txtInput,"",20,110,120,15, %WS_TABSTOP OR %WS_BORDER OR %ES_NUMBER  ' numbers only from keyboard
                                      CONTROL ADD BUTTON , hDlg,%BtnOK, "OK",145,110,35,15
                                      CONTROL ADD BUTTON , hDlg,%btn7,"&7",20,20,20,20, %BS_FLAT  ' default styles include %WS_TABSTOP
                                      CONTROL ADD BUTTON , hDlg,%btn8,"&8",40,20,20,20, %BS_FLAT  ' default styles only applied if no styles
                                      CONTROL ADD BUTTON , hDlg,%btn9,"&9",60,20,20,20, %BS_FLAT  ' added in source code ie adding BS_FLAT style
                                      CONTROL ADD BUTTON , hDlg,%btn4,"&4",20,40,20,20, %BS_FLAT  ' removes WS_TABSTOP from number bottons
                                      CONTROL ADD BUTTON , hDlg,%btn5,"&5",40,40,20,20, %BS_FLAT
                                      CONTROL ADD BUTTON , hDlg,%btn6,"&6",60,40,20,20, %BS_FLAT  ' ampersand (&) makes following charater a
                                      CONTROL ADD BUTTON , hDlg,%btn1,"&1",20,60,20,20, %BS_FLAT  ' Keyboard accelerator (mnemonic). When character pressed
                                      CONTROL ADD BUTTON , hDlg,%btn2,"&2",40,60,20,20, %BS_FLAT  ' a notification is sent to the parent CallBack
                                      CONTROL ADD BUTTON , hDlg,%btn3,"&3",60,60,20,20, %BS_FLAT
                                      CONTROL ADD BUTTON , hDlg,%btn0,"&0",20,80,40,20, %BS_FLAT
                                      
                                    DIALOG SHOW MODAL hDlg, CALL KeypadDlgCB TO lRslt
                                   FUNCTION = lRslt
                                  END FUNCTION
                                  '------------------/ShowKeypad
                                   
                                  CALLBACK FUNCTION KeypadDlgCB()
                                   LOCAL  sNum AS STRING
                                   STATIC sRes AS STRING
                                   STATIC NL   AS LONG
                                    SELECT CASE AS LONG CBMSG
                                      CASE %WM_INITDIALOG         ' Sent once, when Dialog is initializing
                                        CALL SetNumLock(NL)       ' Test / Set NumLock
                                   
                                      CASE %WM_COMMAND            ' Sent when a (button) control sends notification to parent window
                                                                  ' or when an accelerator keystroke mnemonic is translated
                                        SELECT CASE AS LONG CBCTL
                                          CASE %Btn0 TO %btn9
                                            IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                              sNum = FORMAT$(CBCTL - 1000)
                                              CONTROL SEND CBHNDL, %txtInput, %EM_REPLACESEL, 1, StrPtr(sNum)
                                              CONTROL SET FOCUS CBHNDL, %txtInput
                                            END IF
                                          CASE %IDOK      ' Return key pressed
                                            CONTROL GET TEXT CBHNDL, %txtInput TO sRes
                                            MSGBOX sRes, %MB_SYSTEMMODAL, "Result"
                                          CASE %IDCANCEL  ' Escape key pressed
                                            DIALOG END CBHNDL, 0
                                        END SELECT
                                      CASE %WM_SYSCOMMAND
                                        If (CBWPARAM AND &H0FFF0) = %SC_CLOSE THEN   ' [X] Dialog close
                                          DIALOG END CBHNDL, 1
                                        End If
                                      CASE %WM_CLOSE
                                        CALL SetNumLock(NL)
                                    END SELECT
                                  END FUNCTION
                                  '------------------/KeypadDlgCB
                                   
                                  Sub SetNumLock(NL AS LONG)
                                   LOCAL sr AS INTEGER :  sr = GetKeyState(%VK_NUMLOCK)
                                    IF BIT(sr, 0) <> 1 OR NL = 1 THEN                 ' Check if NumLock is toggled (1 = on and lit)
                                      Keybd_Event %VK_NUMLOCK, 0, 0, 0                ' press / release NumLock key
                                      Keybd_Event %VK_NUMLOCK, 0, %KEYEVENTF_KEYUP, 0
                                      NL = 1                                          ' Flag user's NumLock setting
                                    END IF
                                  End Sub
                                  '------------------/SetNumLock
                                  '
                                  It incorporates Borje's sugestion to toggle the NumLock button.

                                  There are a few explanatory comments in the code - but feel free to ask for more
                                  Rgds, Dave

                                  Comment


                                  • #18
                                    Unfortunately it comes with an old (16Bit) version of DlgEdit.exe . . .
                                    Dave,
                                    Are you sure about that?
                                    The way I remember it is PBWin 8.01 was 16 bit, and 8.04 is 32 bit. Whether the change was actually 8.02 or 8.03 I do not remember. But all executables within a version would all be 16 bit or 32 bit.

                                    (your advice could be good anyway, I didn't like 8's editor )

                                    Cheers,
                                    Dale

                                    Comment


                                    • #19
                                      Originally posted by Dale Yarker View Post
                                      Dave,
                                      Are you sure about that?
                                      The way I remember it is PBWin 8.01 was 16 bit, and 8.04 is 32 bit. Whether the change was actually 8.02 or 8.03 I do not remember. But all executables within a version would all be 16 bit or 32 bit.
                                      Cheers,
                                      You're thinking of the compiler. DLgEdit is a MS application bundled with the PBWin instals.

                                      I've still got a DLGEDIT.EXEin my PBWIn10/bin. It's dated 2011 and it's 16 bit!

                                      Click image for larger version

Name:	WontRun.jpg
Views:	162
Size:	132.7 KB
ID:	813687

                                      Comment


                                      • #20
                                        Yeap, I was thinking PBEdit.exe. Since even the DLGEDIT.EXE that comes with PBWin 10 is 16 bit, and no one misses it, then it does not matter if PBWin 8 has it either. Mostly noone needs it! Anyone who does has already found a replacement.

                                        Cheers,
                                        Dale

                                        Comment

                                        Working...
                                        X