|
-
Jan 6th, 2003, 10:32 AM
#1
Thread Starter
Addicted Member
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.
-
Jan 6th, 2003, 10:39 AM
#2
Member
To write to a file, you must open it,
VB Code:
open app.path & "file.txt" for output as #1
write #1 "Blah"
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:
ffile = FreeFile()
open app.path & "file.txt" for output as #ffile
write #ffile "Blah"
close #ffile
HTH
Dave
-
Jan 6th, 2003, 10:43 AM
#3
Addicted Member
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
-
Jan 6th, 2003, 10:44 AM
#4
Thread Starter
Addicted Member
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?
-
Jan 6th, 2003, 10:44 AM
#5
Thread Starter
Addicted Member
is the / thing a seperator
-
Jan 6th, 2003, 10:47 AM
#6
Member
Argg, i always forget that...
VB Code:
open app.path & "\file.txt" for output as #1
write #1 "Blah"
close #1
or
VB Code:
ffile = FreeFile()
open app.path & "\file.txt" for output as #ffile
write #ffile "Blah"
close #ffile
Dave
-
Jan 6th, 2003, 10:52 AM
#7
Addicted Member
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
-
Jan 6th, 2003, 10:55 AM
#8
Addicted Member
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
-
Jan 6th, 2003, 10:56 AM
#9
Thread Starter
Addicted Member
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?
-
Jan 6th, 2003, 10:56 AM
#10
Member
Man this is hopeless! I should have opened up VB to make sure it worked before i posted!
-
Jan 6th, 2003, 10:59 AM
#11
Member
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
-
Jan 6th, 2003, 11:02 AM
#12
Addicted Member
i just tried it too, works fine
use print instead like this
VB Code:
Open App.Path & "\file.txt" For Output As #1
Print #1, "Blah"
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
-
Jan 6th, 2003, 11:05 AM
#13
Addicted Member
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
-
Jan 6th, 2003, 11:15 AM
#14
Thread Starter
Addicted Member
I cut and pasted the code tried changing it to print. It still doesn't like the app.
-
Jan 6th, 2003, 11:18 AM
#15
Addicted Member
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
-
Jan 6th, 2003, 11:20 AM
#16
Thread Starter
Addicted Member
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.
-
Jan 6th, 2003, 11:27 AM
#17
Addicted Member
come to think of it, invalid outside procedure must mean you havent put that code into a subroutine....try this...
VB Code:
'create a command button on your form first and this gets triggered when you click it
Sub Command1_Click()
Open App.Path & "\file.txt" For Output As #1
Print #1, "Blah"
Close #1
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
-
Jan 7th, 2003, 10:48 AM
#18
Thread Starter
Addicted Member
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.
-
Jan 7th, 2003, 10:58 AM
#19
Member
Well, tht shouldnt be too hard --- i guess.
VB Code:
Sub Command1_Click() 'click on the button and it does it...
Open App.Path & "\file.htm" For Output As #1 'opens the html file
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)
Close #1 'close the file
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
-
Jan 8th, 2003, 11:13 AM
#20
Thread Starter
Addicted Member
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?
-
Jan 8th, 2003, 11:27 AM
#21
Member
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
-
Jan 8th, 2003, 11:29 AM
#22
Thread Starter
Addicted Member
whoops.
yeah it is called command 1 and text1.
I did expect something visual to happen.
whoops.
Yeah it works XD
-
Jan 9th, 2003, 11:33 AM
#23
Thread Starter
Addicted Member
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.
-
Jan 9th, 2003, 11:56 AM
#24
Member
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
-
Jan 10th, 2003, 10:25 AM
#25
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|