-
Code:
Function RetLineWord(ByVal str As String, linenum As Long, wordnum As Long) As String
Dim x&, pos&, pos2&
For x = 2 To linenum
pos = InStr(pos + 1, str, vbCrLf)
pos = pos + 1
Next x
For x = 2 To wordnum
pos = InStr(pos + 1, str, " ")
Next x
pos2 = InStr(pos + 1, str, " ")
If pos2 = 0 Then pos2 = Len(str) + 1
RetLineWord = Mid(str, pos + 1, pos2 - pos - 1)
End Function
That's the code I use but if there's a doublespace between the lines in the string I give it, it doesn't return the value! Can someone modify it to ignore doublespcaes or something!
-
Add this as your first line of code in RetLineWord
str = Replace(str, " ", " ')
-
A few posts ago I learned it's a good idea to use the $ wherever you need string thingies...
like mid$,left$,right$,instr$ and so on...
-
MartinLiss
Can you explain what that does to my code! Thanx for you reply!
-
It replaces all the double spaces ( ) with one space ( )
-
Why don't you ask me to maintain the code first? since i know how my own code works..
Code:
Function RetLineWord(ByVal str As String, linenum As Long, wordnum As Long) As String
Dim x&, pos&, pos2&
For x = 2 To linenum
pos = InStr(pos + 1, str, vbCrLf)
pos = pos + 1
Next x
lastspace = -1
For x = 2 To wordnum
pos = InStr(pos + 1, str, " ")
If pos - lastspace <= 1 Then x = x - 1
pos2 = InStr(pos + 1, str, " ")
If pos2 - pos = 1 Then x = x - 1
Next x
If pos2 = 0 Then pos2 = Len(str) + 1
RetLineWord = Mid(str, pos + 1, pos2 - pos - 1)
End Function
Should work with any amount of blank spaces
-
Hey Keda/Kado/Kadi.. come over to ICQ friend :)
-
KedaMAN
It doesn't work!!! Try it out your self before you give it to me please.
-
I've noticed this gets more and more complicated as i work on it, so i thought about approach it in another way. Do you need to use this for the same text over and over again? In that case, do you do it in some kind of order? Can the text change`?
-
Hallo,
Try this
*********************************
Dim MyIndex
Dim MyArray(3)
Dim Srchtext
Dim Position
' your text
MyArray(0) = Text1.text
MyArray(1) = Text2.text
MyArray(2) = Text3.text
MyArray(3) = Text4.text
' text to find in your text
Srchtext= Text5.text
' selection to find the string
MyIndex = filter(MyArray, Srchtext)
' Startposition srchtext
Position = Instr(1, MyIndex(0), Srchtext)
MsgBox = (" String = " & MyIndex(0))
MsgBox = ("Startposition = " & Position)
****************************************
Create a form witk 5 textboxes and a cmdbutton
put the code in the cmdbutton
Cheers
Ray
-
Yeah, I usually get the HTMl of a page wich changes every 20 seconds, but the text barely changes, it's only like 10 words that change!