-
May 29th, 2014, 04:23 AM
#1
Keyboard with command buttons on the form
Hi all,
I have created a dialer in VB6 to dial a phone number. It have following buttons: the digits 0-9, backspace, "Call", and "Disconnect". Each one has separate command button associated with it. Now I want to enter numbers using the numpad of the keyboard. Keys are displayed in the text box. In the text box, any key can be typed in using the keypad. But I only want the number pad to operate.
For that I checked ASCII values using the KeyPress event for Text box checking if the pressed key value lies in between 47 and 58. But along with the key values its ASCII values are also getting displayed in the text box.
One more thing - I have one MS Flex Grid on the form along with the dialer. So when the cursor is on the form, or if the mouse is clicked anywhere other than the text box, values don't display in the text box. So how do I always keep focus on the text box? Here is the code
Code:
Dim val As Integer
Private Sub append(val As Integer)
Text1.Text = Text1.Text & val
End Sub
Private Sub Backspace_Click()
With Text1
'FOCUS TO THE TEXTBOX
.SetFocus
'PUT THE CURSOR AT THE END OF THE TEXT
.SelStart = Len(.Text)
'SEND THE KEY
SendKeys ("{BACKSPACE}")
'AND THATS IT :D
End With
End Sub
Private Sub key_0_Click()
val = 0
append val
End Sub
Private Sub key_1_Click()
val = 1
append val
End Sub
Private Sub key_2_Click()
val = 2
append val
End Sub
Private Sub key_3_Click()
val = 3
append val
End Sub
Private Sub key_4_Click()
val = 4
append val
End Sub
Private Sub key_5_Click()
val = 5
append val
End Sub
Private Sub key_6_Click()
val = 6
append val
End Sub
Private Sub key_7_Click()
val = 7
append val
End Sub
Private Sub key_8_Click()
val = 8
append val
End Sub
Private Sub key_9_Click()
val = 9
append val
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii > 47 And KeyAscii < 58) Then
val = KeyAscii
append val
Else
KeyAscii = 0
' Text1.Text = KeyAscii End If End Sub
'Private Sub Text1_LostFocus()
' Text1.SetFocus
'End Sub
-
May 29th, 2014, 09:11 PM
#2
Re: Keyboard with command buttons on the form
When you have focus on a textbox and press a key tht gets added to the textbox automatically. You are then adding it again through code
remove this from your key press event
Why are you using sendkeys?
If you want to remove the last character when a button is clicked then you should use code to do so
Depending on how you want this to work you may want to use the Mid$() function or Left$() or Right$() Or you may want to use the textbox .selstart .sellength and .seltext properties
You definitely should not use sendkeys though
Always use [code][/code] tags when posting code.
-
May 31st, 2014, 01:24 AM
#3
Re: Keyboard with command buttons on the form
Originally Posted by DataMiser
remove this from your key press event
Why are you using sendkeys?
You definitely should not use sendkeys though
Thanks for the reply data miser. However what is the other way to append the pressed digits to text box. I am totally new to VB. Trying to write code with available information. Why i should not use sendkeys though.
One more issue is,I have written one more code for serial communication with GSM modem. Its working fine. Data string i get when GSM modem receives a call is RING+CLIP: "+919823596784",145,"",,"",0", with No Carrier signal sometimes and AT + clip command sometimes. I have to check 2-3 events in my program such as whether i am receiving a call or getting a message. For that i was thinking of checking starting bits of received string such as RING+CLIP, for incoming call. But as i told, data keeps on getting shifted from left to right. Can you tell me the logic of separating the characters and then checking whether particular string is present or not, then receiving it till the end of string to check i have got the valid string then extracting phone number from it. I created a hyperterminal using text box. Please suggest me some logic. DO i need to create another thread for this.
-
May 31st, 2014, 11:09 AM
#4
Re: Keyboard with command buttons on the form
On the appending text. When you press a key and a textbox has focus the key gets into the text box automatically. You don't need to append anything. This is why you were getting two characters instead of one. One was coming in automatically and then you were appending it again. From your buttons you would need to append the character but not from the keypress.
As for the Com stuff. Normally there is a CR character at the end of every string. Normally you would use a buffer and append any incoming data to that buffer, then you would check for a CR in that buffer and read the data from the buffer up to the CR.
Have a look at Instr(), Left$(), Right$() and Mid$()
Always use [code][/code] tags when posting code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|