Page 1 of 1
Open command in VB express 2005
Posted: Fri Aug 19, 2005 5:52 pm
by Offsprey
I never been able to 'Open', so i found some code that was suposed to work, to test, and it still wont work.
I got this code from another topic on halomods.
Code: Select all
Open "C:\Documents and Settings\All Users\Desktop\Sample.txt" For Output As #1
Text = Text1.Text
Print #1, "This is whats contained in the Text1.Text Textbox: " + Text
Close #1
intMsg = MsgBox("File sample.txt Written")
I get this error whenever i try to perform Open.
Code: Select all
Error 7 'Open' is not declared. File I/O functionality is available in the 'Microsoft.VisualBasic' namespace. C:\Documents and Settings\Shane\My Documents\Visual Studio 2005\Projects\text\text\Form1.vb 6 1
text
Anyone know whats wrong here?
Posted: Fri Aug 19, 2005 5:55 pm
by Patrickssj6
yep its an older code or not a visual basic code
Posted: Wed Oct 05, 2005 12:35 pm
by PlasmaGhost
i no the code i hope it helps
Code: Select all
'dim the open as the file dialog
'u can use SaveFileDialog to save too!
Dim Open as New OpenFileDialog
'file types to show
Open.Filter = "Filetype (*.file)|*.file|All files (*.*)|*.*"
Open.Title = "Dialog Title Here"
Open.CheckFileExists = True
Open.ShowDialog(Me)
ok, now if u want it to read a text file, do this:
Code: Select all
Dim myStreamReader As System.IO.StreamReader
Dim output as New String = ""
Try
Open.OpenFile()
myStreamReader = System.IO.File.OpenText(Open.FileName)
'replace output with w/e u want it to load the text into
output = myStreamReader.ReadToEnd()
'this will catch exceptions and display a message box error
Catch ex As Exception
MsgBox("Your error message here")
End Try
so ur total code would be:
Code: Select all
'dim the open as the file dialog
'u can use SaveFileDialog to save too!
Dim Open as New OpenFileDialog
'file types to show
Open.Filter = "Filetype (*.file)|*.file|All files (*.*)|*.*"
Open.Title = "Dialog Title Here"
Open.CheckFileExists = True
Open.ShowDialog(Me)
Dim myStreamReader As System.IO.StreamReader
Dim output as New String = ""
Try
Open.OpenFile()
myStreamReader = System.IO.File.OpenText(Open.FileName)
'replace output with w/e u want it to load the text into
output = myStreamReader.ReadToEnd()
'this will catch exceptions and display a message box error
Catch ex As Exception
MsgBox("Your error message here")
End Try
ok the code would load up the open dialog, the users selects a file, the text is loaded into the string 'output' and then the code ends. ok u want it to write it directly to a textbox named 'Textbox1'? ok fine heres the code.
Code: Select all
'dim the open as the file dialog
'u can use SaveFileDialog to save too!
Dim Open as New OpenFileDialog
'file types to show
Open.Filter = "Filetype (*.file)|*.file|All files (*.*)|*.*"
Open.Title = "Dialog Title Here"
Open.CheckFileExists = True
Open.ShowDialog(Me)
Dim myStreamReader As System.IO.StreamReader
Try
Open.OpenFile()
myStreamReader = System.IO.File.OpenText(Open.FileName)
'replace output with w/e u want it to load the text into
TextBox1.Text = myStreamReader.ReadToEnd()
'this will catch exceptions and display a message box error
Catch ex As Exception
MsgBox("Your error message here")
End Try
if i messed up or u need more help or u want help in another thing, IM me on AIM, my sn is: PlasmaGrunt
sorry tho i only program vb2005
hope it helps!
Re: Open command in VB express 2005
Posted: Wed Oct 05, 2005 6:27 pm
by Onetoomanysodas
Offsprey wrote:I never been able to 'Open', so i found some code that was suposed to work, to test, and it still wont work.
Are you literally trying to load a file or write one? Because the Open statement will write a file for output.
Posted: Fri Oct 14, 2005 8:29 am
by PlasmaGhost
did my recent post not explain it?

lol
if any body needs more code just let me know
Posted: Fri Oct 14, 2005 11:42 am
by TfAv1228
in yout imports just put
Imports Microsoft.VisualBasic
Posted: Tue Oct 18, 2005 2:51 pm
by Uber-Banana
1. Open is not part of the VB2005 Syntax.
2. Use this:
make sure you have an openfiledialog named openfile
and a text box name txtcontents
Code: Select all
Dim strFile As String
Dim strContents As String
strFile = openfile.FileName()
strContents = My.computer.filesystem.readalltext(strFile)
txtcontents.text = strcontents
Posted: Wed Oct 19, 2005 5:28 pm
by PlasmaGhost
mine works dude u need to do
which i did in my code. open isnt part of the vb2005 syntax. thats why you dim it as a new openfiledialog. openfiledialog infact is part of the syntax. try it im telling u i also have a neat function to turn that into 1 line of code (not including the function). im gonna post that now in a new topic
