Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Find text in Richtextbox and then add it to a string

Posted on 2001-09-12
19
Medium Priority
?
430 Views
Last Modified: 2007-11-27
Dear all,

I am doing the following:
-Find something in a richtextbox control.
   a=richtextbox.find(Searchfor,0)
-Find somethine else in the same richtextbox control.
   b=richtextbox.find(Searchfor2,a)

Then I'll get two numbers.. a=index of the first found and b=index of the second found.
My problem is then to put this into a string.
What I've done is;

String=mid(richtextbox.text,a,b-a)

The textbox control downloads text from webpages, and with some of them it works fine, so I wonder if a richtextbox control may have hidden characters for the mid function?

Please help =)
0
Comment
Question by:thomas_mathiesen
  • 10
  • 4
  • 4
  • +1
19 Comments
 
LVL 4

Expert Comment

by:wileecoy
ID: 6476848
Actually, the RTB does have hidden chrs, but only if you were using RichTextBox.RTFText.

Since you are using .Text, it will be what is displayed in the RTB.

Since you are doing webpages, might it be the html tags that are in your way?

I have done a lot with this.  I have a whole app just for displaying RTB's and collecting data dynamically from each file.

I use the find function in addition to the InStr and InStrRev functions to get the position of certain text.

If you can post your code and I can test it, I am close to 100% sure that I can figure it out (much sweat getting my app to work).

Let me know if it's the html tags, or post your code and I will test.

Also - let me know if e-mail would be better.

Thanks

Wileecoy.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6476853
If all you want to do is concatenate to two string than this would be the way to go:

Debug.Print Mid(RichTextBox.Text, a, Len(Searchfor)) & Mid(RichTextBox.Text, b, Len(Searchfor2))

Anthony
0
 
LVL 1

Author Comment

by:thomas_mathiesen
ID: 6476889
Wileecoy,
sounds good, but first let me ask u;
Can I turn off the RTB function in the textbox? I need to use the richtextbox control, because the normal textbox cannot contain the number of characters I need.
And, yes, I am looking for tags, and I need to rip text between two tags. That's why I first find the first and then the second. At the end; grab the string between these two.

I'll send u the code (email).

Acperkins,
What I do:
Text: "blah1 blah2 blah3 blah4"
a=Find"blah1"
b=Find"blah4"
String=mid(textbox,a,b-a)
So that the string will be "blah1 blah2 blah3 balh4"
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:thomas_mathiesen
ID: 6476891
Wileecoy,
sounds good, but first let me ask u;
Can I turn off the RTB function in the textbox? I need to use the richtextbox control, because the normal textbox cannot contain the number of characters I need.
And, yes, I am looking for tags, and I need to rip text between two tags. That's why I first find the first and then the second. At the end; grab the string between these two.

I'll send u the code (email).

Acperkins,
What I do:
Text: "blah1 blah2 blah3 blah4"
a=Find"blah1"
b=Find"blah4"
String=mid(textbox,a,b-a)
So that the string will be "blah1 blah2 blah3 balh4"
0
 
LVL 1

Author Comment

by:thomas_mathiesen
ID: 6476893
What is ur email Wileecoy?
0
 
LVL 1

Author Comment

by:thomas_mathiesen
ID: 6476908
What is ur email Wileecoy?
0
 
LVL 1

Author Comment

by:thomas_mathiesen
ID: 6476924
What is ur email Wileecoy?
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6476930
I suspect that Wileecoy is right about the HTML characters, but to answer your question
>>
What I do:
Text: "blah1 blah2 blah3 blah4"
a=Find"blah1"
b=Find"blah4"
String=mid(textbox,a,b-a)
So that the string will be "blah1 blah2 blah3 balh4"
<<

If a < b Then
 String = mid(textbox, a, b + Len("blah4") - 1)
else
 String = mid(textbox, b, a + Len("blah1") - 1)
end if
0
 
LVL 4

Expert Comment

by:wileecoy
ID: 6477113
Please send to JakeAustinLane@aol.com

Thanks.

Wileecoy.

p.s. - I will post any pertinent code so that anyone in the future who 'buys' this question will be able to see the progress and resolution.

0
 
LVL 1

Author Comment

by:thomas_mathiesen
ID: 6477146
Here's the code:
I have a richtextbox control (txttemp).

Public Sub FindText()
On Error GoTo FindTextERR
Dim FoundFile As String
Dim a, b As Long
a = 0
b = 0
Do While a > -1
    a = frmMain.txtTemp.Find("a href", b)
    b = frmMain.txtTemp.Find(">", a)
    FoundFile = Mid(frmMain.txtTemp.Text, a, b - a)
    DoEvents
Loop
Exit Sub
FindTextERR:
End Sub

I am looking for files linked on a webpage, which should be the FoundFile string.
I suspect that a and b get different index'es than u could use in a Mid function.
Any idea?
0
 
LVL 1

Author Comment

by:thomas_mathiesen
ID: 6477170
Do you think has something to do with it?
http://support.microsoft.com/support/kb/articles/Q284/9/48.ASP

/Thomas
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6477185
This is a sample from this page:
     <a class="topMenuLink" href="http://www.devx.com/free/premierclub/premierclub.asp" target="_top">PremierClub</a>

If all you need is http://www.devx.com/free/premierclub/premierclub.asp

Than
a = 0
b = 0
Do While a > -1
   a = frmMain.txtTemp.Find("href=", b)
   b = frmMain.txtTemp.Find("""", a + Len("href=") + 1)
   FoundFile = Mid(frmMain.txtTemp.Text, a, b - a)
   DoEvents
Loop
0
 
LVL 4

Expert Comment

by:wileecoy
ID: 6477224
thomas,

What the find method does is returns the character position of the beginning of your search text.

So - you will need to include enough padding to only extract the text you want... for example... the following worked for me.

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 9">
<meta name=Originator content="Microsoft Word 9">
<link rel=File-List href="./computers_files/filelist.xml">
<link rel=Edit-Time-Data href="./computers_files/editdata.mso">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<title>Computer Features</title>
<!--[if gte mso 9]><xml>


I had to change the code to:

Public Sub FindText()
On Error GoTo FindTextERR
Dim FoundFile As String
Dim a, b As Long
a = 0
b = 0
Do While a > -1
   a = frmMain.txtTemp.Find("a href=", b)
   b = frmMain.txtTemp.Find(">", a)
   FoundFile = Mid(frmMain.txtTemp.Text, a + 8, b - 8 - a)
   DoEvents
Loop
Exit Sub
FindTextERR:
End Sub


Also - I would suggest using a search string that is exclusive but all inclusive to your needs.

By this I mean that you should include 'a href=' as a opposed to 'a href'.  the difference will be your word padding in the Mid function, but also the possibility of having the wrong spacing if there is a new or old html tag that doesn't follow the same format as your search string.

Anyway - hope this helps.

hth.

Wileecoy.
0
 
LVL 4

Expert Comment

by:wileecoy
ID: 6477232
thomas,

forgive me for bad coding - I would never suggest what I posted above:

FoundFile = Mid(frmMain.txtTemp.Text, a + 8, b - 8 - a)


I was simply stepping through the code and changing it as I went.

It is better to incorporate code more conducive to dynamic functioning.

For example...

dim sFindStr as string

sFindStr = "a href="

....etc

FoundFile = Mid(frmMain.txtTemp.Text, a + len(sFindStr), b - len(sFindStr) - a)

....etc

apologies as my tail is clearly between my legs.

Wileecoy.
0
 
LVL 1

Author Comment

by:thomas_mathiesen
ID: 6478706
Guys, I will check this tomorrow.. busy today.
0
 
LVL 1

Author Comment

by:thomas_mathiesen
ID: 6482337
Wileecoy,
You showed me just what I had already done.
The thing is that if u download a textfile that comes from a unix box, (using the inet control), the text in the richtextbox and the character's index is not correct. That means that using the mid(string) will see another string than the textbox sees.
Microsoft has tried to explain the problem for me, so what I need is someone that knows how to convert this string into the same format as the richtextbox is.

A very easy example:

Put a few lines in a richtextbox.
Search for the string "Thomas".
It will give u an index where this starts in the textbox.
Use the Found=mid(string,foundindex,6) so that Found=Thomas, BUT if the downloaded text is from a unix box, this is not working.

Any ideas?
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 600 total points
ID: 6483200
You may want to take a look at the MidB, InStrB and LenB functions.

Anthony
0
 
LVL 3

Expert Comment

by:jrspano
ID: 6483600
you might also have to convert it to unicode.  I don't know what text format unix uses, but vb uses unicode.  what you do see on the unix stuff?  does it give an error?
0
 
LVL 1

Author Comment

by:thomas_mathiesen
ID: 6493933
I see the the text as a normal textbox.. can't see anything unusal. The problem is that for each time it finds what I am looking for, the value of a seems to increase too much (and it increases per time).

I thought this could be because I am going futher down into the file, so there are more "strange/invisibile" characters found and added. I don't think my mid function sees the same string as the richtextbox control does.
When I convert it to unicode, it adds a square between every character.

/Thomas
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question