![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Mar 2005
Posts: 25
Rep Power: 0
![]() |
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 ![]() |
|
|
|
|
|
#2 |
|
Expert Programmer
|
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 |
|
|
|
|
|
#3 |
|
Expert Programmer
|
Grr evil host! (but +1 to my post count...)
Last edited by Rory; Jun 3rd, 2005 at 1:41 PM. Reason: Whoops double post |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Mar 2005
Posts: 25
Rep Power: 0
![]() |
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 Last edited by fox123; Jun 5th, 2005 at 12:18 PM. Reason: Unclear and confusing. Sorry |
|
|
|
|
|
#5 |
|
Expert Programmer
|
OK, I think this might be what you mean:
Private Sub Command1_Click()
Text1.SetFocus
VBA.SendKeys "{END}~"
End Sub |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Mar 2005
Posts: 25
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#7 |
|
Expert Programmer
|
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|