Author Topic: Data entry from keypad  (Read 12424 times)

sid80555

  • Newbie
  • Posts: 36
  • I'm a llama!
    • View Profile
Data entry from keypad
« on: July 19, 2011, 02:46:50 AM »
I have downloaded your progam(HMI65to80) which i use to enter data from the keypad,and comes with the Installation CD.When i try to enter more than 10 digits it does not accept the enterred number giving me an error(some absurd number).I tried changing the lenght of Z in the custom function of the program but it does`nt help.The custom function is as below

' This function handles the keypad scanning and make sure that a key must be
' pressed and released before the next key can accepted. It reserves the use
' of the Z$ string variable so you should avoid modifying Z$ in other part of
' the program.
'============================================================================

DM[900] = INPUT[2]  ' Get data from input #17-32

IF DM[900]=0
   Z = -1       ' no key pressed
   RETURN
ENDIF
IF Z >= 0       ' previous key has been pressed.
   IF TESTBIT(DM[900],Z) RETURN  ' previous key not yet released
   ENDIF
ENDIF

FOR Z = 0 to 11   ' scan 0 to 9 and <- key
  IF TESTBIT(DM[900],Z) GOTO @10: ENDIF
NEXT

@10 IF Z = 10     ' <Del> key has been pressed.
       IF LEN(Z$)>0
         Z$ = MID$(Z$,1,LEN(Z$)-1)
       ENDIF
    ELSE          ' Check if numeric keys 0-9 has been pressed.
       IF Z < 10 AND LEN(Z$) < 10   ' not more than 10 digits
         Z$ = Z$+STR$(Z)
       ENDIF
    ENDIF




















garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:Data entry from keypad
« Reply #1 on: July 19, 2011, 12:39:58 PM »
I used the custom function that you included in the post (without the rest of the code) and played with in in simulation.  

I do not get the error (some absurd number).  I don't see the error so I can't help.  The error is not coming from this code section.  Somewhere else you have code that annoys the simulator. The simulator will catch many runtime errors. The types of errors that the simulator can catch are pretty grievous (divide by zero, call stack overflow/underflow...).

On the issue of only accepting 10 digits, that I can help. The following IF statement limits the input to 10 digits:

IF Z < 10 AND LEN(Z$) < 10  ' not more than 10 digits
        Z$ = Z$+STR$(Z)
      ENDIF

If you want to input a string longer than 10 you will need to change the the value of the constant from 10 to what you require.  Remember that there is a maximum string length that TBASIC can handle.  I think that the max is 70.

Gary D

sid80555

  • Newbie
  • Posts: 36
  • I'm a llama!
    • View Profile
Re:Data entry from keypad
« Reply #2 on: July 19, 2011, 04:59:12 PM »
Yeah it does give me an absurd number... But how can I
Help this since i need to input a number with more than
10 digits...
The suggestion u gave me is the same as what I have written in the code?

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:Data entry from keypad
« Reply #3 on: July 19, 2011, 07:15:27 PM »
OK

1. The code you posted is not the code that fails.

2. Your code has been modified to look like the following to allow a 20 character string and does not work:

If z < 10 and Len(z$) < 20
  Z$ = z$+str$(z)
Endif

3. Your code still has bugs the crash the simulator.

Lacking ESP, I don't have a clue how to help.  

Best of luck,

Gary d