Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTML and Visual Basic

Status
Not open for further replies.

mettodog

Vendor
Jul 11, 2000
94
US
Hi, I am trying to help out my friend with a program, and anyway, I need to do this:

the vb program will write links to other pages once you enter the appropriate data into fields. the name of the page will be automaticaly assigned to it, so there is no field for that, but the name of the link will be the title of the page it is linking to. for example, the page that it will be linking to is in the /notes directory of the same server as the links page, so the url of the link is notes/blah.html, and the title of the link will be the title of the page being linked to. i want the vb code to find the last </a> and put the code <a href=&quot;notes/blah.html&quot;>Todays Notes</a> in it. How do i program this?
 
If you are using VB5 and down try using a Do While Loop with the Instr(startpoint, myhtml, &quot;</a>&quot;) function within it to iterate through all of the &quot;</a>&quot;'s in the html script, resetting the startpoint each time to reflect where we got up to through the script.

Public Sub FindLastPoint()
Dim myhtml$, startpoint&, currentpoint&, newhtml$

myhtml = &quot;hidehidehideho teriffic stuff </a> hello thereth </a>howe arste your pumpernikkels</a>hi aginst, youre transiente misre&quot;

'find the first point if it exists
startpoint = InStr(myhtml, &quot;</a>&quot;)
currentpoint = startpoint

'enter the loop if there are some </a>'s in existance
Do While startpoint > 0

'find the next point
startpoint = InStr(currentpoint + 1, myhtml, &quot;</a>&quot;)
If startpoint > 0 Then currentpoint = startpoint

Loop

currentpoint = currentpoint + Len(&quot;</a>&quot;) - 1

'add your new section of text here
newhtml = &quot;<a>inserted text<a/>&quot;
myhtml = Left(myhtml, currentpoint) & newhtml & Right(myhtml, Len(myhtml) - currentpoint)

End Sub

If your using VB6 on the other hand you can replace the whole looping section with the function InstrRev which looks up the last occurence of a string within a string and works its way foward.

chat soon
Michael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top