You need to use a counter in the button click and based on the counter value decide what is displayed in the textbox.
debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
Try the following -
Private Sub Command1_Click()
Static xCount As Integer
Select Case xCount
Case Is = 0
Text1.Text = "2"
xCount = xCount + 1
Case Is = 1
Text1.Text = "A"
xCount = xCount + 1
Case Is = 2
Text1.Text = "B"
xCount = xCount + 1
Case Is = 3
Text1.Text = "C"
xCount = 0
End Select
End Sub
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
Then use the following -
Text1.Text = Text1.Text & "2" 'or A, B,C etc.
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
Add a timer to your form and set its enabled property to False, Interval to say 2000 (2 Seconds)
I have modified the code a bit, have not tested. Let me know if it works.
Dim strIn As String
Private Sub Command1_Click()
Static xCount As Integer
Timer1.Enabled = True
Select Case xCount
Case Is = 0
strIn = "2"
xCount = xCount + 1
Case Is = 1
strIn = "A"
xCount = xCount + 1
Case Is = 2
strIn = "B"
xCount = xCount + 1
Case Is = 3
strIn = "C"
xCount = 0
End Select
If Len(Text1) = 1 Then
Text1.Text = strIn
Else
Text1.Text = Text1.Text & strIn
End If
End Sub
Private Sub Timer1_Timer()
Text1.SetFocus
Text1.SelStart = Len(Text1.Text)
Timer1.Enabled = False
End Sub
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
I've found that it still replaces the first letter.:@ Below is something else I've tried, see if it will work for you. The problem is that we have to manipulate the cursor position without focus to the textbox, but with the command button that has focus... Selstart etc would have worked wonders under the textbox's change event.:-/
Add another textbox "Text2" to your form. Make it the same width and height as text1 and place it on top of text1. Set both textboxes Appearnce Property to Flat for enhanced look.
The following code. I'll play around tomorrow to see if I can get a better solution....;)
Dim strIn As String
Private Sub Command1_Click()
Static xCount As Integer
Timer1.Enabled = True
Text2.Visible = True
Select Case xCount
Case Is = 0
strIn = "2"
xCount = xCount + 1
Case Is = 1
strIn = "A"
xCount = xCount + 1
Case Is = 2
strIn = "B"
xCount = xCount + 1
Case Is = 3
strIn = "C"
xCount = 0
End Select
Text2.Text = strIn
End Sub
Private Sub Timer1_Timer()
Text2.Visible = False
Select Case Len(Text1.Text)
Case Is = 0
Text2.Width = Text1.Width - 150
Text2.Left = Text1.Left + 150
Case Is = 1
Text2.Width = Text1.Width - 300
Text2.Left = Text1.Left + 300
Case Is = 2
Text2.Width = Text1.Width - 450
Text2.Left = Text1.Left + 450
End Select
Text1.SetFocus
Text1.Text = Text1.Text & Text2.Text
Text1.SelStart = Len(Text1.Text)
Timer1.Enabled = False
End Sub
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
It was a huge pleasure. Happy coding.:)
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350