More code to add to your menu:
First, add this code to THE VERY TOP of your code sheet, above where it says “Public Form1”
Imports System.IO.File
If you recall from our “Crypto” program, this allows you to create and save files in VB
Next, just beneath “Public Form1’ create the following variable:
Dim saveFolder As String
Next, give this variable a value in “Form Load”, something like this:
"C:\Documents and Settings\Paul\My Documents\Visual Studio 2005\Projects\PaulLaRueMenus\"
It’s the pathname for a folder; your pathname will be different, since you are not me
Finally, doubleclick on the SAVE command, and then add this code to it:
Dim myFile As System.IO.File
'create a file writer
Dim myWrite As System.IO.StreamWriter
'set the folder and name of file where contents of textbox will be written
myWrite = IO.File.CreateText(saveFolder & "My Words.doc")
'write the contents of your textbox to a file
myWrite.WriteLine(MyWords.Text)
'closes the file no more writing to it
myWrite.Close()
Now, SAVE your work, then run the program and see if you can save a text file from the text you type in your textbox
Cheers,
Mr. L

No comments:
Post a Comment