Results 1 to 12 of 12

Thread: [RESOLVED] Textbox Focus

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    6

    Resolved [RESOLVED] Textbox Focus

    Hey All,

    Ok I have a onscreen keyboard but I also have a 4 onscreen text boxes. Is there a way that I can just click a keyboad letter and have it display in the text box which has the focus?

    Thanks

    Hon

  2. #2
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Textbox Focus

    VB Code:
    1. Private Sub cmdA_Click()
    2.     Text1.Text = Text1.Text & "A"
    3. End Sub
    4. Private Sub cmdB_Click()
    5.     Text1.Text = Text1.Text & "B"
    6. End Sub
    7. Private Sub cmdC_Click()
    8.     Text1.Text = Text1.Text & "C"
    9. End Sub
    10. 'and so on....
    11.  
    12. 'if the keys are in control array, then
    13. Private Sub cmdKeys_Click(Index As Integer)
    14.     Text1.Text = Text1.Text & cmdKeys(Index).Caption
    15. End Sub
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    6

    Re: Textbox Focus

    Thanks will that not just display it in the textbox1 I need it to be able to enter a letter in which textbox has the focus i.e the cursor

    Thanks

  4. #4
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: Textbox Focus

    Welcome to the forums Hondacars!
    When you click the keyboard the textbox will lose its focus, so you need a way to record which textbox last had focus.

    I suggest you create a global variable declared 'HadFocus As String' then use this:
    VB Code:
    1. Private Sub Text1_LostFocus()
    2. HadFocus = "Text1"
    3. End Sub
    4. Private Sub Text2_LostFocus()
    5. HadFocus = "Text2"
    6. End Sub
    7. Private Sub Text3_LostFocus()
    8. HadFocus = "Text3"
    9. End Sub
    10. Private Sub Text4_LostFocus()
    11. HadFocus = "Text4"
    12. End Sub
    And then in your keyboard code use a 'If... Then' statement or 'Select Case' to check which textbox had focus and then set that textboxes value.
    EDIT:
    You could use something like this:
    VB Code:
    1. Private Sub Command1_Click()
    2. Select Case HadFocus
    3.     Case "Text1"
    4.     Text1.Value = "a"
    5.  
    6.     Case "Text2"
    7.     Text2.Value = "a"
    8.  
    9.     Case "Text3"
    10.     Text1.Value = "a"
    11.  
    12.     Case "Text4"
    13.     Text1.Value = "a"
    14. End Select
    15. End Sub
    Last edited by shirazamod; Apr 20th, 2006 at 03:56 AM.
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  5. #5
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Textbox Focus

    i couldnt understand...do you want to write a char in the text box when the key got focus...
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    6

    Re: Textbox Focus

    Yeah

    for example if i click on textbox1 then click the letter "a" i would like it to add a to textbox1. if i then click on textbox2 then click "a" i would like to add it to textbox 2

    Sorry for not making sense

  7. #7
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: Textbox Focus

    Did you read my code?
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  8. #8
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Textbox Focus

    well, you can try shirazamod's coding for that kind of prob..
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  9. #9

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    6

    Re: Textbox Focus

    Hi thanks,

    I have tried the code but having a few troubles I have never used cases before I am some what a newbie .

    I'ts having trouble at the part where

    VB Code:
    1. Select Case HadFocus

    there are no errors it does not do anything

  10. #10

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    6

    Re: Textbox Focus

    This my code so far but no joy:

    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3. Select Case HadFocus
    4.     Case "Text1"
    5.     Text1.Text = "a"
    6.  
    7.     Case "Text2"
    8.     Text2.Text = "a"
    9. End Select
    10.  
    11. End Sub
    12.  
    13. Private Sub Form_Load()
    14. Dim HadFocus As String
    15. End Sub
    16.  
    17. Private Sub Text1_LostFocus()
    18. HadFocus = "Text1"
    19. End Sub
    20. Private Sub Text2_LostFocus()
    21. HadFocus = "Text2"
    22. End Sub

  11. #11
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: Textbox Focus

    The problem is that you are declaring 'HadFocus' in the Form_Load event.
    This will make it available only in Form_Load().
    You will need to change your code to look like this:
    VB Code:
    1. Dim HadFocus As String
    2.  
    3. Private Sub Command1_Click()
    4.  
    5. Select Case HadFocus
    6.     Case "Text1"
    7.     Text1.Text = "a"
    8.  
    9.     Case "Text2"
    10.     Text2.Text = "a"
    11. End Select
    12.  
    13. End Sub
    14.  
    15. Private Sub Text1_LostFocus()
    16. HadFocus = "Text1"
    17. End Sub
    18. Private Sub Text2_LostFocus()
    19. HadFocus = "Text2"
    20. End Sub
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  12. #12

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    6

    Re: Textbox Focus

    Got It Working Thanks So Much People

    I guess we can this resolved

    Thanks Again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width