Save info from a form to disk?

  • Thread starter Thread starter gsb58
  • Start date Start date
G

gsb58

Hi!

I haven't worked with streams before.

On a form I have:

A. cboValues = A combobox with text values where the user can choose
a value
B. txtText = A textbox where the user can enter text
C. cboDatePicker = A Datetime picker where the user can choose a
date

Now, when he/she chooses the OK-button, I would like to save the data
to disk into a text-file like:

Dim MyDir as string,MyFile as string,MyFileExt as string

'This directory already exists as it was created during the OnLoad
of main form.
MyDir = "C:\APlace\"

'Now the file....
MyFile = cboValues & "_" & cboDatePicker
MyFileExt = ".txt"
MyPath = Trim(MyDir & MyFile & MyFileExt)

I understand that I should use a stream. Anybody that can show me how I
do this?

Didn't understand so much from the helpfile.

Me.Name
 
Imports System.io
Imports System.Convert

Dim myStream As FileStream

Dim i As Integer
Dim letter As Char

myStream = New FileStream(MyPath, FileMode.OpenOrCreate)
For i = 1 To TextBox1.Text.Length
letter = Mid(TextBox1.Text, i, 1)
arrText = ToByte(letter)

myStream.WriteByte(arrText)
Next

You'll have probs with your path. When you convert your datepicker to string
you'll have something like "_12/9/05". This is illegal as a file path (I
think).

HTH, Phil
 
Thanks!

I know.

The full path to file contains of some text I didn't bother to write.
The full filename will be something like:

TodayFile_12/9/05.txt
 
arrText probably should be bytText but anyhow, it's Dim arrText as Byte

ToByte is actually a method of system.convert.

Good luck. Phil
 
I came to think of the following:

Why save data to disk? Why not write it directly from Form2 to Form1?

I have:

A. cboValues = A combobox with text values where the user can choose
a value
B. txtText = A textbox where the user can enter text
C. cboDatePicker = A Datetime picker where the user can choose a
date

Now suppose I remove the last option and remains with only A and B.

Should I not be able to write data to the ListView on Form1 as user
click's the OK-button? And from there I could save the ListView to disk
into a .txt-file? Shouldn't this be easier?

The ListView contains of two columns:

Column1 holds the same values as the cboValues on the Form2.
Column2 holds the text from txtText on Form2

How can I pass data from the Form2 into the ListView of Form1?

Me.Name
 
Back
Top