Results 1 to 25 of 25

Thread: write to html file

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    225

    write to html file

    Ok were trying to make a program that can create a web template (of sorts, I guess, were just supposed to show furtherment in our coding knowledge) and we need to know how to use some sort of filewrite command or write to file?

    Ring any bells?
    Last edited by amyblueeyes; Jan 9th, 2003 at 11:21 AM.

  2. #2
    Member
    Join Date
    Nov 2002
    Posts
    56
    To write to a file, you must open it,

    VB Code:
    1. open app.path & "file.txt" for output as #1
    2. write #1 "Blah"
    3. close #1

    That code opens (creates the file if not there) a file called file.txt in the application folder, writes "Blah" then closes it...

    You could also use freefile() to assign the filenumber so you dont use one that is already open:

    VB Code:
    1. ffile = FreeFile()
    2. open app.path & "file.txt" for output as #ffile
    3. write #ffile "Blah"
    4. close #ffile


    HTH

    Dave

  3. #3
    Addicted Member Cyberius's Avatar
    Join Date
    Jan 2003
    Location
    Australia
    Posts
    145
    u might need to put a blackslash on that open line like this:

    open app.path & "\file.txt" for output as #1

    otherwise if your app path was for example "C:\myfolder", your file would be outputted to "C:\myfolderfile.txt"

    i think Dunghill_Dave just made a typo
    -=[Ç¥ßè®Ìú§]=-

    How many microsoft employees does it take to change a lightbulb? None, they simply define darkness as the new industry standard.

    CAUTION: OVERCLOCKING A 386 TO 5Ghz MAY BE HAZARDOUS

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    225
    Private Sub Form_Load()
    Open App.Path & "file.txt" For Output As #1
    Write #1 "Blah"
    Close #1

    End Sub

    it says it needs a list seperator whats a list seperator?

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    225
    is the / thing a seperator

  6. #6
    Member
    Join Date
    Nov 2002
    Posts
    56
    Argg, i always forget that...

    VB Code:
    1. open app.path & "\file.txt" for output as #1
    2. write #1 "Blah"
    3. close #1

    or

    VB Code:
    1. ffile = FreeFile()
    2. open app.path & "\file.txt" for output as #ffile
    3. write #ffile "Blah"
    4. close #ffile

    Dave

  7. #7
    Addicted Member Cyberius's Avatar
    Join Date
    Jan 2003
    Location
    Australia
    Posts
    145
    i think dave made another typo, lol
    try:

    write #1, "Blah"

    in general, ',' is the list seperator
    -=[Ç¥ßè®Ìú§]=-

    How many microsoft employees does it take to change a lightbulb? None, they simply define darkness as the new industry standard.

    CAUTION: OVERCLOCKING A 386 TO 5Ghz MAY BE HAZARDOUS

  8. #8
    Addicted Member Cyberius's Avatar
    Join Date
    Jan 2003
    Location
    Australia
    Posts
    145
    actually, better still, use print instead of write, cause i think write put quotation marks around data. just replace the word write with print
    -=[Ç¥ßè®Ìú§]=-

    How many microsoft employees does it take to change a lightbulb? None, they simply define darkness as the new industry standard.

    CAUTION: OVERCLOCKING A 386 TO 5Ghz MAY BE HAZARDOUS

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    225
    Open App.Path & "\file.txt" For Output As #1
    Write #1, "Blah"
    Close #1


    It says invalid outside procedure. Why doesn't it allow app?

  10. #10
    Member
    Join Date
    Nov 2002
    Posts
    56
    Man this is hopeless! I should have opened up VB to make sure it worked before i posted!

  11. #11
    Member
    Join Date
    Nov 2002
    Posts
    56
    Originally posted by amyblueeyes
    Open App.Path & "\file.txt" For Output As #1
    Write #1, "Blah"
    Close #1


    It says invalid outside procedure. Why doesn't it allow app?
    Typo? did you copy and paste that or re-write it? it worked fine for me....

    Also, i aggree, if you are creating a web template, you wont want the " " round the info...

    Dave

  12. #12
    Addicted Member Cyberius's Avatar
    Join Date
    Jan 2003
    Location
    Australia
    Posts
    145
    i just tried it too, works fine
    use print instead like this
    VB Code:
    1. Open App.Path & "\file.txt" For Output As #1
    2. Print #1, "Blah"
    3. Close #1
    -=[Ç¥ßè®Ìú§]=-

    How many microsoft employees does it take to change a lightbulb? None, they simply define darkness as the new industry standard.

    CAUTION: OVERCLOCKING A 386 TO 5Ghz MAY BE HAZARDOUS

  13. #13
    Addicted Member Cyberius's Avatar
    Join Date
    Jan 2003
    Location
    Australia
    Posts
    145
    i think you're just having a bad day dave...happens to everyone...

    yay! one more post till ive made 100....uh....i mean....yay! 100 posts! in just a few days too...W00T!!!!
    ok...calm down....breathe in......and out....
    -=[Ç¥ßè®Ìú§]=-

    How many microsoft employees does it take to change a lightbulb? None, they simply define darkness as the new industry standard.

    CAUTION: OVERCLOCKING A 386 TO 5Ghz MAY BE HAZARDOUS

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    225
    I cut and pasted the code tried changing it to print. It still doesn't like the app.

  15. #15
    Addicted Member Cyberius's Avatar
    Join Date
    Jan 2003
    Location
    Australia
    Posts
    145
    can you zip and send your project, i'll go through in debug mode for you
    -=[Ç¥ßè®Ìú§]=-

    How many microsoft employees does it take to change a lightbulb? None, they simply define darkness as the new industry standard.

    CAUTION: OVERCLOCKING A 386 TO 5Ghz MAY BE HAZARDOUS

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    225

    prob. why it's not working huh?

    actually I have no "project" yet all I had was that bit of code. Im just trying to get a hang of it in order to try and attempt said project in the making.

  17. #17
    Addicted Member Cyberius's Avatar
    Join Date
    Jan 2003
    Location
    Australia
    Posts
    145
    come to think of it, invalid outside procedure must mean you havent put that code into a subroutine....try this...
    VB Code:
    1. 'create a command button on your form first and this gets triggered when you click it
    2. Sub Command1_Click()
    3.     Open App.Path & "\file.txt" For Output As #1
    4.     Print #1, "Blah"
    5.     Close #1
    6. End Sub

    all code except declaration and dim's must be in Subs
    -=[Ç¥ßè®Ìú§]=-

    How many microsoft employees does it take to change a lightbulb? None, they simply define darkness as the new industry standard.

    CAUTION: OVERCLOCKING A 386 TO 5Ghz MAY BE HAZARDOUS

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    225
    ok we finally have it all planned out.
    We need to make a program that takes whatever someone types in a textbox then they click a button and it automatically "writes" I guess to an html file.

  19. #19
    Member
    Join Date
    Nov 2002
    Posts
    56
    Well, tht shouldnt be too hard --- i guess.

    VB Code:
    1. Sub Command1_Click() 'click on the button and it does it...
    2.     Open App.Path & "\file.htm" For Output As #1 'opens the html file
    3.     Print #1, "<html><body>" & Text1 & "</body></html> " 'prints the text you entered in Text1 to the file (i have printed <html> too as you need this in an html file)
    4.     Close #1 'close the file
    5. End Sub 'end the sub

    You could edit this code to include <title>text2</title> tags etc. Also, in text1, you can use html tags such as <b>bold</b>

    HTH

    Dave

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    225
    Sub Command1_Click()
    Open "c:\file.htm" For Output As #1
    Print #1, "<html><body>" & Text1 & "</body></html> "
    Close #1
    End Sub

    ok I have the text box and I have button so I know that's not wrong. I have file.htm in the c drive right in the open and it still won't work.

    why?

  21. #21
    Member
    Join Date
    Nov 2002
    Posts
    56
    Hmmm, weird - is your button called command1? Also, you wont actually see the fil open, this program will open it in the background as it were, nothing visual happens. If you go to c:\ you may find your file there.

    HTH

    Dave

  22. #22

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    225
    whoops.
    yeah it is called command 1 and text1.
    I did expect something visual to happen.
    whoops.

    Yeah it works XD

  23. #23

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    225
    Option Explicit
    ' -------------------------------------------------------
    Dim Highres As String
    Dim Title As String
    Dim Datey As String
    Dim Media As String
    Dim Desc As String
    Dim WebpageLoc As String

    Private Sub cmbPublish_Click()
    'saves the file. Or, you know, publishes it.
    cdPublish.Filter = "HTML files (*.html; *.htm)|*.html; *.htm| All files (*.*)|*.*"
    cdPublish.ShowSave
    End Sub

    Private Sub cmdBrowse_Click()
    Call RandomDimming
    cdBrowse.Filter = "supported image files (*.jpg; *.gif)|*.jpg; *.gif| All files (*.*)|*.*"
    cdBrowse.ShowOpen
    'If txtWebpageLoc.Text = "" Then
    'txtFile.Text = cdBrowse.FileTitle
    'Else:
    txtFile.Text = WebpageLoc
    '& cdBrowse.FileTitle
    'End If
    End Sub

    Private Sub cmdExit_Click()
    ' Gives user option to exit
    If MsgBox("Are you sure you wish to exit ?", vbYesNo, "Quit") = vbYes Then Unload Me
    End Sub

    Private Sub cmdHigRes_Click()
    Call RandomDimming
    cdHighRes.Filter = "supported image files (*.jpg; *.gif)|*.jpg; *.gif| All files (*.*)|*.*"
    cdHighRes.ShowOpen
    If txtWebpageLoc.Text = "" Then
    txtHighRes.Text = cdHighRes.FileTitle
    Else: txtHighRes.Text = WebpageLoc & cdHighRes.FileTitle
    End If
    End Sub

    Private Sub RandomDimming()
    txtHighRes.Text = Highres
    txtFile.Text = Image
    txtTitle.Text = Title
    txtDate.Text = Datey
    txtMedia.Text = Media
    txtDesc.Text = Desc
    txtWebpageLoc.Text = WebpageLoc
    End Sub


    Ok we need the img browser thing to automatically pop the name into the textbox and for it to be put in after the web address box.

  24. #24
    Member
    Join Date
    Nov 2002
    Posts
    56
    I'm no sure as i understand - but;

    webaddressbox = (webaddressbox) & "/" & (textbox with filename in)

    That sort of thing?

    BTW, what does your program do?

    Dave

  25. #25

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    225
    wer just trying to make a template automatically pop up for a website and you can stick whatever you want on it.

    I think.

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