Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 5th, 2006, 11:00 PM
dwe dwe is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Brisbane Australia
Posts: 158 dwe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 36 m 42 sec
Reputation Power: 5
Talking RichTextBox

Hey Guys, my first post in this forum (I think) ... :-)

the following function, tells me the position under the cursor (ie what line it is on) and the current character under the cursor ...

what I would like to be able to do is get the WORD under the cursor ... now I know that I have to search for the first chr(32) prior to the cursor position and the first chr(32) after the cursor position ... that way I get the word in between ... but, I have little if no idea about going backwards from the cursor position in a string to find the chr(32) ...

there are API calls through the function, and these work fine ... if needed I can post the declarations and type variables ... I didnt think they would be necessary here ..

See the line commented out as '// DWE
Code:
Private Sub rtbSyntax_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    Dim P As POINTAPI, CurPos As Long, tmpChar As String
    'On Error Resume Next
    'Hide the Caret
    'If ConcealCaret Then HideCaret rtbSyntax.hwnd
    'Current position
    P.x = x / Screen.TwipsPerPixelX
    P.y = y / Screen.TwipsPerPixelY
    'Use the API to discover the character number
    CurPos = SendMessageP(Me.rtbSyntax.hwnd, EM_CHARFROMPOS, 0, P)
    Form2.lblCharacterNumber.Caption = "Character Pos: " & CurPos
    'The richtextbox will tell us the line number
    Form2.lblLineNumber.Caption = "Line: " & rtbSyntax.GetLineFromChar(CurPos)
    
    'What character is it?
    tmpChar = Mid(rtbSyntax.Text, CurPos + 1, 1)
    
    Form2.lblCharacter.Caption = "Character: " & IIf(tmpChar = vbCr, "vbCr", tmpChar)

'// DWE    
'    Form2.lblWord.Caption = "Word: " & WordUnderCursor
    
    If CBool(Form2.ChCaret.Value) Then
        'move the Caret as required
        rtbSyntax.SetFocus
        rtbSyntax.SelStart = CurPos
    End If
    If CBool(Form2.ChSelectCharacter.Value) Then
        'Select the character
        rtbSyntax.SetFocus
        rtbSyntax.SelStart = CurPos
        rtbSyntax.SelLength = 1
    End If

End Sub



MTIA

Darrin

Last edited by dwe : January 5th, 2006 at 11:04 PM.

Reply With Quote
  #2  
Old January 6th, 2006, 12:07 AM
dwe dwe is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Brisbane Australia
Posts: 158 dwe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 36 m 42 sec
Reputation Power: 5
ok .. well I have made some headway ...

the following code should be inserted into my original function, where '// DWE appears

Code:
	Dim iStartPos&
	Dim iFinishPos&
	Dim cChar$
	Dim szWord$
	If CurPos <> 0 Then
		'ok  find the position in the string, forward of the cursor position, where the first chr(32) appears
		' ok now find the position of the first chr(32) back from the cursor
		iStartPos = InStrRev(rtbSyntax.Text, Chr(32), CurPos)
		iFinishPos = InStr(CurPos, rtbSyntax.Text, Chr(32), vbTextCompare)
		If iFinishPos = 0 Then ' perhaps we dont have a space at the end of the word - see if we have a vbcrlf
		  iFinishPos = InStr(CurPos, rtbSyntax.Text, vbCrLf, vbTextCompare)
		End If
		If iFinishPos = 0 Then ' hmmmm ... ad a chr(32) ?
		 rtbSyntax.Text = rtbSyntax.Text & Chr(32)
		 ' now we have to have one
		iFinishPos = InStr(CurPos, rtbSyntax.Text, Chr(32), vbTextCompare)
		rtbSyntax.SelStart = iFinishPos - 1
		
		End If
		
		szWord = Mid(rtbSyntax.Text, iStartPos, iFinishPos - iStartPos)
		Form2.lblWord.Caption = "Word: " & szWord
	Else
		Form2.lblWord.Caption = "Word: " & ""
	End If


now I can select a word merely by holding the mouse cursor over it, EXCEPT for the very first word in the string ... HOW can I get that first word ?

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > RichTextBox


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT