Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic (http://www.programmingforums.org/forum18.html)
-   -   Text Boxes (http://www.programmingforums.org/showthread.php?t=4236)

fox123 Jun 2nd, 2005 6:56 AM

Text Boxes
 
I am having trouble with text boxes. (Like you wouldn't have guessed from the title)
What I would like to happen is when a button is pressed the mouse cursor goes to the start of the line. (My text box has multi line enabled)

The code I have used for the button press is:
:

Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 120 Then
Call cmdTime_Click
End If
End Sub


I need the code for the cmdTime_click sub routine, which is also a command button.

Thanks for looking :)

Rory Jun 3rd, 2005 1:52 PM

Surely you mean I-bar, not the mouse cursor?
It's position and length are controlled by the selstart and sellength properties. You could count the number of line feed characters up to that point to determine the current line, and then set the position the hard way but why not just:
:

Private Sub Text1_KeyDown(KeyCode as Integer, Shift as Integer)
If KeyCode = vbKeyLeft then KeyCode = vbKeyHome
End Sub


Rory Jun 3rd, 2005 2:12 PM

Grr evil host! (but +1 to my post count...)

fox123 Jun 4th, 2005 1:18 PM

Hi,
Thanks for your help.
I am still having trouble. What i want to happen is when the user clicks a command button the time is pasted next to the time of lyric. (This i can do) However what i want to happen is for the I (Text Thing) to move down a line. I have tried using vbKeyDown but this does not work. Any ideas

Rory Jun 5th, 2005 2:31 PM

OK, I think this might be what you mean:
:

Private Sub Command1_Click()
    Text1.SetFocus
    VBA.SendKeys "{END}~"
End Sub


fox123 Jun 5th, 2005 3:10 PM

Hi,
I will try to explain what i mean more clearly.

I am programming an application to create a synchronised lyrics file. I have a text box (txtLyrics.) In this user pastes thier lyrics.

They then press the command button (cmdTime) which pastes the progress of the lyric at the start of the line.

I then need the I Text cursor to goe down to the start of the next line.

I am having trouble with the things in blue.

Thank you for your time

Rory Jun 5th, 2005 3:31 PM

Ok, this should work then. When Command1 is clicked, it moves the I-Bar to the start of the 4th line (index of line is 3 as base 0) of text1.
:

Private Sub Command1_Click()
    With Text1
        .SelLength = 0
        .SelStart = GetLineStart(Text1.Text, 3)
        .SetFocus
    End With
End Sub

Private Function GetLineStart(ByVal nText As String, ByVal nLine As Integer) As Integer
' Returns the starting character (base 0)
' of line nLine (base 0) of nText

Dim nLines() As String
Dim nLineEnum As Integer
Dim nLinePos As Integer
    nLines = Split(nText, vbNewLine)
    For nLineEnum = 0 To sUbound(nLines)
        If nLineEnum = nLine Then
            GetLineStart = nLinePos
            Exit For
        End If
        nLinePos = nLinePos + Len(nLines(nLineEnum) & vbNewLine)
    Next
End Function

Private Function sUbound(ByRef What() As String) As Integer
' Returns ubound of what or -1 if empty

On Error GoTo UnDimensioned:
    sUbound = UBound(What)
Exit Function
UnDimensioned:
    sUbound = -1
End Function



All times are GMT -5. The time now is 12:59 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC