Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 2nd, 2005, 5:56 AM   #1
fox123
Newbie
 
Join Date: Mar 2005
Posts: 25
Rep Power: 0 fox123 is on a distinguished road
Post 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
fox123 is offline   Reply With Quote
Old Jun 3rd, 2005, 12:52 PM   #2
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
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 is offline   Reply With Quote
Old Jun 3rd, 2005, 1:12 PM   #3
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
Grr evil host! (but +1 to my post count...)

Last edited by Rory; Jun 3rd, 2005 at 1:41 PM. Reason: Whoops double post
Rory is offline   Reply With Quote
Old Jun 4th, 2005, 12:18 PM   #4
fox123
Newbie
 
Join Date: Mar 2005
Posts: 25
Rep Power: 0 fox123 is on a distinguished road
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
fox123 is offline   Reply With Quote
Old Jun 5th, 2005, 1:31 PM   #5
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
OK, I think this might be what you mean:
Private Sub Command1_Click()
    Text1.SetFocus
    VBA.SendKeys "{END}~"
End Sub
Rory is offline   Reply With Quote
Old Jun 5th, 2005, 2:10 PM   #6
fox123
Newbie
 
Join Date: Mar 2005
Posts: 25
Rep Power: 0 fox123 is on a distinguished road
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
fox123 is offline   Reply With Quote
Old Jun 5th, 2005, 2:31 PM   #7
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
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
Rory is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:37 AM.

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