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..
Code:
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..
Code:
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
[email protected]
[email protected]