English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

pls help me.. codes pls?

2007-09-15 18:03:13 · 2 answers · asked by pristine 1 in Computers & Internet Programming & Design

2 answers

"save and open command?" save what? and open what? if you mean create or open existed file, input data and save it.

In that case... there are 3 types of files ,at least that's what I know, Sequential Files, Random Files and Binary Files.

Sequential files are the needed.

Open Syntax:-

open "File Name, Address, Extension" for mode as #file number

1) open > is a reserved order

2) "File Name, Address, Extension" > like this "C:\Documents and Settings\Mari1\My Documents\Notes.txt"
* "" are reserved.

3) for > is a reserved order.

4) mode > how would you want vb to deal with the file. There are 3 modes also:

a- Append : write or edit on file /if it existed/ otherwise vb will create one.

b- Input : read form file /if it existed/ otherwise vb will show error message.

c- output : write & erase on file /if it existed/ otherwise vb will create one.

5) as > is a reserved order.

6) #file number > vb would deal with files through its numbers. So choose any number you want.
* # is reserved.

---------------
For more info check this out:
http://www.profsr.com/vb/vbless08.htm

2007-09-15 19:53:45 · answer #1 · answered by ? 5 · 0 0

The following code was written using VB2005 Express:

Place this code in a button click event an use the debug mode to step through it.

The following will create a new text file using a "StreamWriter" and a "StreamReader" to view the data.
There is a difference in opening a file as you can create a new file which will erase the contents of an existing file OR append to a file so as to add data to an existing file.

You can write an IF statment to check if a file exists using the boolean returned by System.IO.File.Exists(FilePath). I did not include this in the folowing.


Dim dlg As New OpenFileDialog
Dim myReader As IO.StreamReader
Dim myWriter As IO.StreamWriter
Dim myFileName, data As String

'Create new file
myFileName = "C:\TestFile.txt"
myWriter = System.IO.File.CreateText(myFileName)
'Add some data to this new file
data = "File created on: " & Now()
myWriter.WriteLine(data)

'Close this new file
myWriter.Close()

'Repoen this file an add data to end of existing filedata
myWriter = System.IO.File.AppendText(myFileName)
data = "Appended data: " & Now()
myWriter.WriteLine(data) ' write line at end of file

'close this file again so you can open it for reading
myWriter.Close()

'Open file for reading
myReader = System.IO.File.OpenText(myFileName)

'starting at top of file loop while there is data availableto read
'Use the PEEK property to see if data ia available on next line
'if so read it and place it in a listbox or print it etc...
Do While myReader.Peek >= 0
'reuse the data string variable to hold the text read from file
data = myReader.ReadLine
Debug.WriteLine(data) 'you can add code here to place the data
'into a control or print it etc...

Loop
'end of file close
myReader.Close()

2007-09-16 09:45:12 · answer #2 · answered by MarkG 7 · 0 0

fedest.com, questions and answers