Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic (http://www.programmingforums.org/forum18.html)
-   -   Vb And Html (http://www.programmingforums.org/showthread.php?t=464)

madhattertcm Sep 4th, 2004 11:48 AM

Heres what I'm wanting to do. Theres a certain part of the HTML file where all the text is..I want a vb program to be able to open that part of the text and edit it, and place it back into the html file..

Get what I'm saying?

Thanks

thechristelegacy Sep 4th, 2004 3:28 PM

hmm maybe you could somethign with like a place holder, to sort of make a template in a way.

e.g.


Template.html

:

<html>
<body>
{TEXT}
</body>
</html>


And then the program could open up the templace file, and just replace the {TEXT} with the actual text and then resave it as the real HTML page.

Pizentios Sep 7th, 2004 9:22 AM

What i would do is have a set of html comments, one for the start of the text area and one to end it. Then just have the vb code search for these strings (the html comments) and throw the text in between the comments. So your html file would llook somthing liek this:

:

<html>
<head>
<body>
<!--start of text-->
Your text goes here.
<!--end of text-->
some text that you don't want to ever change.
</body>
</html>


madhattertcm Sep 7th, 2004 10:31 PM

the HTML part is easy, I know how to do that.
But I don't know how to get say a textbox in VB to
search for that particular part of the html document

Ooble Sep 8th, 2004 11:11 AM

The text box doesn't search the file - your code does.

First, open the file for reading. Then parse it, line by line, into a string array, checking each one for the starting comment as you go. When you reach the comments, make a note of the line number. Then parse the bits between the comments, but don't save it into the array. When you reach the ending comment, start saving it again, until you reach the end of the file.

Next, open the file for output. Until you get to the comment (you stored the line number earlier), just output the string line by line. When you do, output the stuff you want. Then send the bottom bit (the ending comment onwards). And voila! You're done!

I realise you might not know how to do some (or any) of this. If there's anything you need help with, please post back.

Pizentios Sep 10th, 2004 11:34 AM

Herečs a function that will return the text between your two markers.



:

function grabtext(filename, search as string) as variant

dim check as boolean
dim text() as string
dim tmp() as string
dim read as string
dim y, x as integer

read = Space(FileLen(filename))
Open filename For Binary As #1
  Get #1, 1, read
Close #1

tmp() = Split(read, vbCrLf)

check = false

y = 0
x = 0

for x=0 to UBound(tmp)
    if (tmp(x) == search) then
        check = true
    else
        check = false
    end if
 
    if (check = true) then
        text(y) = tmp(x)
        y = y + 1
    end if
Next x
 
return text()

end function



Anyways, this code has not been tested yet at all, so there could be bugs in it. Good luck.

Infinite Recursion Sep 10th, 2004 4:15 PM

I'll run it through the garden this weekend... I think I may have a use for something similar.

Pizentios Sep 13th, 2004 10:03 AM

Has anybody tested that code? i will somtime today if need be.


All times are GMT -5. The time now is 1:02 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC