Results 1 to 15 of 15

Thread: Lots Of Help?

  1. #1

    Thread Starter
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188

    Question Lots Of Help?

    Sorry for all the questions!

    1) How can i open a html file into a rich text box or normal text box? Is it the same as opening a text file? I want the code to show?

    2) How can i then only show a specific bit/s of the code. So basically someone with no knowledge of web programming can come in and add text it etc.

    3) Then save the file as filename.html overwriting the old one!!

    Thanks for any help!

    Beacon

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    open it using Open #1 as ...
    and write it using Write

    use Squencial (sp) or Binary Modes

  3. #3
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    I have never done it but i understand that a RTB can open and display an HTML document

    As for addding text and then saving it back to html I would think you may have to parse the text back into html format to save it

    I think i saw a control that did it somewhere
    i will check for you

  4. #4
    Tygur
    Guest
    Opening and saving files with a rich text box is very easy

    Opening:
    RichTextBox1.LoadFile "c:\test.htm", rtfText

    Closing:
    RichTextBox1.SaveFile "c:\test.htm", rtfText

  5. #5
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    See I thought that it could be done with the RTB

    The control I saw I think was for handling Html files without using the rtb just using OPEN FILE method

  6. #6

    Thread Starter
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    thanks ppl!

    Howabout number 2??

    thanks

  7. #7
    Tygur
    Guest
    I don't understand number 2 well enough to answer it..

    You just want to show part of the file? What part?

  8. #8
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    you could use a second RTB and mid the section that you want to display out of the first RTB. Then join the two back together for saving

  9. #9

    Thread Starter
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    Basically what would be ideal would to be able to filter out all the code!!!!
    And just have the text.
    I.e Just have Hi how r u bl blah blah

    Instead of all the tags and stuff around it!!

  10. #10
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    ah well you see thats what i was meaning with this control i saw it did that for you

    damn I still trying to find where it was i saw it

  11. #11
    Tygur
    Guest
    Oh, I see. In order to do that' you need to get the text from the file into a string, here's how you can load from and save to a string. Both bits of code assume that sString is declared someplace else.

    VB Code:
    1. 'Loading the text from the file
    2. Dim FileNum As Long
    3. FileNum = FreeFile
    4. Open "c:\test.htm" For Input As FileNum
    5. sString = Input(LOF(FileNum), FileNum)
    6. Close FileNum
    7.  
    8. 'Saving the text to the file
    9. Dim FileNum As Long
    10. FileNum = FreeFile
    11. Open "c:\test.htm" For Output As FileNum
    12. Print #FileNum, sString;
    13. Close FileNum
    By the way, if any of you are wondering why there's a semicolon at the end of one of the lines in the saving code, it's so the Print statement doesn't stick a newline at the end of the file.


    I can post some code to strip off all the tags, but I don't see how it'd be useful. Do you know about the string manipulation functions VB provides? Basically, you gotta get creative with those.

    I'll put together some code to strip off the tags right now, just as an example...

  12. #12
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    But even once the tags are stripped of you will still need to be able to format the text into the rtf properly

    and then If changes are made he will have to reinsert the old tags and modify them to match any changes the user has made. Finally he will have to apply the approiate new tags to accomadate any new text and formatting that the user has applied and save it all back as a fully functioning HTML document.

  13. #13

    Thread Starter
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    hmm seems more complicated then i first thought! dammit!

  14. #14
    Tygur
    Guest
    Stripping off the tags isn't so useful, anyway. This is just an example of how the functions can be used. It should be easy enough to understand how to use this function:
    VB Code:
    1. Function StripOffTags(sString As String) As String
    2. Dim LTPos As Long
    3. Dim GTPos As Long
    4. Dim sOut As String
    5. LTPos = InStr(sString, "<")
    6. GTPos = 1
    7. Do Until LTPos = 0
    8.     sOut = sOut & Mid(sString, GTPos, LTPos - GTPos)
    9.     GTPos = InStr(LTPos, sString, ">") + 1
    10.     If GTPos <> 1 Then
    11.         LTPos = InStr(GTPos, sString, "<")
    12.     Else
    13.         Exit Do
    14.     End If
    15. Loop
    16. If LTPos = 0 Then
    17.     sOut = sOut & Mid(sString, GTPos)
    18. End If
    19. StripOffTags = sOut
    20. End Function

    If you try this on an html file, you'll see that the title gets left at the top of the text, <br> tags aren't converted to newlines, and there are many other things that aren't done. All this does is take out the tags.

  15. #15

    Thread Starter
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    thanks tygur
    and rudvs2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width