VB6/Blinking Cursor/Textbox/Move Cursor

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • michels287
    New Member
    • Mar 2008
    • 20

    VB6/Blinking Cursor/Textbox/Move Cursor

    Right now I have a touchscreen with a virual keyboard.

    I would like to create arrow keys. If the user messed up the inputted text, he can move the blinking cursor left one space at a time between inputted characters to add a letter. Then a button to move the blinking cursor back to the end of the inputted text.

    Private Sub Left Arrow_Click()
    If Text1.SelStart Then Text1.SelStart = Text1.SelStart - 1
    Text1.SetFocus
    End Sub

    Private Sub Right Arrow_Click()
    If Text1.SelStart < Len(Text1.Text) Then Text1.SelStart = Text1.SelStart + 1
    Text1.SetFocus
    End Sub

    Private Sub Enter Letter_Click()
    Text1.Text = Text1.Text + Command1(Index) .Caption

    For i = 0 To Command1.ubound
    Command1(i).Cap tion = LCase(Command1( i).Caption)
    Next

    cmdLowercase.Vi sible = False
    End Sub

    When the cursor is moved left, I would like to have the next letter inserted where the cursor is blinking, not at the end of what's already entered.

    With what I have so far, the cursor will move left after some letters are entered into the textbox. But when the next letter is selected it inserts it at the very end.

    Basically in my textbox I want to enter more text wherever the cursor is blinking...

    If I select a random part of the entered text and enter another letter or hit the backspace button, it adds the letter at the end or backspaces from the end.

    Can anyone help me please?
  • smartchap
    New Member
    • Dec 2007
    • 236

    #2
    In the Enter Letter_Click event u have written

    Text1.Text = Text1.Text + Command1(Index) .Caption

    which will obviously add new character at the end of the Text1. First find out the current position of the cursor (in the text box) and then change text in text box when u enter a character.

    Also please let me know u want to enter character from key board (actual) or the one u have created on screen.

    If any other problem please post zip file of the project so that I will try to correct it.

    Comment

    • michels287
      New Member
      • Mar 2008
      • 20

      #3
      I wish to use the keyboard on screen, not the actual keyboard.

      Thanks.

      Currently working with another recommendation that looks like:

      Text1.Text = Left(Text1.Text , Text1.SelStart - 1) & Command1(Index) .Caption & Mid(Text1.Text, Text1.SelStart + 1)

      But I get errors when I place this in my Command1_Click( Index As Integer)

      'Invalid procedure call or argument"

      Comment

      • smartchap
        New Member
        • Dec 2007
        • 236

        #4
        Correct your MID function. It must have three arguments.

        Comment

        • QVeen72
          Recognized Expert Top Contributor
          • Oct 2006
          • 1445

          #5
          Hi,

          @SmartChap: Not Necessarily. MID is an Over-loaded function, Omitting the last Argument, returns from the Middle till the end..

          @OP,
          Once, you change the Text, Your SelStart also changes, you have to reset it..
          So that you can hit keys continously..

          Try This :
          [code=vb]
          Dim i As Integer
          i = Text1.SelStart
          Text1.text = Left(Text1.text , Text1.SelStart) & Command1(Index) .Caption & Mid(Text1.text, Text1.SelStart + 1)
          Text1.SelStart = i + 1
          [/code]

          Regards
          Veena

          Comment

          • michels287
            New Member
            • Mar 2008
            • 20

            #6
            Thanks! Resolved.

            Means a lot.

            Comment

            Working...