Open command in VB express 2005

Post here about scripting and programming for HaloPC (audio, network, ai, etc.)
Post Reply
Offsprey





Posts: 80
Joined: Sun May 30, 2004 10:59 am
Location: Vienna, IL
Contact:

Open command in VB express 2005

Post 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?
Image Free Web Hosting Here
Patrickssj6




Pi Collaborator

Posts: 5426
Joined: Sat Jul 24, 2004 12:12 pm
Location: I'm a Paranoid
Contact:

Post by Patrickssj6 »

yep its an older code or not a visual basic code
...left for good
PlasmaGhost





Posts: 149
Joined: Wed Oct 05, 2005 12:23 pm

Post 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!
Onetoomanysodas





Posts: 325
Joined: Mon Mar 22, 2004 3:59 pm
Location: Everywhere but nowhere
Contact:

Re: Open command in VB express 2005

Post 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.
PlasmaGhost





Posts: 149
Joined: Wed Oct 05, 2005 12:23 pm

Post by PlasmaGhost »

did my recent post not explain it? :P lol
if any body needs more code just let me know
TfAv1228




Miner Logistician Droplet

Posts: 276
Joined: Sun Sep 05, 2004 4:40 pm

Post by TfAv1228 »

in yout imports just put

Imports Microsoft.VisualBasic
Sig breaks rules, read the rules before reposting.
Uber-Banana





Posts: 84
Joined: Wed Oct 13, 2004 4:17 pm
Location: Loading Comment...
Contact:

Post 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
PlasmaGhost





Posts: 149
Joined: Wed Oct 05, 2005 12:23 pm

Post by PlasmaGhost »

mine works dude u need to do

Code: Select all

Dim Open as New OpenFileDialog
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 :D
Post Reply