rino_2
Nov 14th, 1999, 02:56 AM
Hi,
I need to count how many spaces there are in the current line i'm in.
Richard
Aaron Young
Nov 14th, 1999, 05:45 AM
You can use the SendMessage API to get the Current Line from a Textbox/RTFBox then you can count the spaces in 2 ways..
If you have VB6..
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const EM_GETLINE = &HC4
Private Const EM_LINEFROMCHAR = &HC9
Private Const EM_LINELENGTH = &HC1
Private Sub Command1_Click()
Dim iLen As Long
Dim iLine As Long
Dim sLine As String
iLine = SendMessage(Text1.hwnd, EM_LINEFROMCHAR, -1, 0&)
iLen = SendMessage(Text1.hwnd, EM_LINELENGTH, Text1.SelStart, 0&)
sLine = Space(iLen)
Call SendMessage(Text1.hwnd, EM_GETLINE, iLine, ByVal sLine)
MsgBox "Spaces in this line: " & (iLen - Len(Replace(sLine, " ", "")))
End Sub
Otherwise you have to count them yourself..
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const EM_GETLINE = &HC4
Private Const EM_LINEFROMCHAR = &HC9
Private Const EM_LINELENGTH = &HC1
Private Sub Command1_Click()
Dim iLen As Long
Dim iLine As Long
Dim sLine As String
Dim iSpaces As Long
iLine = SendMessage(Text1.hwnd, EM_LINEFROMCHAR, -1, 0&)
iLen = SendMessage(Text1.hwnd, EM_LINELENGTH, Text1.SelStart, 0&)
sLine = Space(iLen)
Call SendMessage(Text1.hwnd, EM_GETLINE, iLine, ByVal sLine)
iLen = 0
Do
iLen = InStr(iLen + 1, sLine, " ")
If iLen Then iSpaces = iSpaces + 1
Loop While iLen
MsgBox "Spaces in this line: " & iSpaces
End Sub
------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net