Hi all,

I'm a VB newbie in this respect so please be patient with me! I have an app that requires the user to input a bunch of values for various things in textboxes, datagridviews and propertygrids. I want this user input to be written to a text file in a specific format (say, on the click of a button, but dynamic writing wouldn't be so bad!)

What is the best way to do this? I'm thinking using a dataset, but I'm no expert so a bit of advice would be helpful.

Cheers

Recommended Answers

All 3 Replies

So many data into a text file? Is this a smart way to do it? How will you then know what is what?
You can use flags like some special characters that the code can recognize them as NOT-TEXT, but like: this is from button1, this is from datagridview, and so on. You can put this into square brackets: [textBox1], or [datagridview1],...

To get all data to be written into text file would be best to use StringBuilder class, and append all to it from all controls.
From textboxes its simple to get Text, from dataGridView (dgv) its a bit harder. I assume your dgv is already bound to some data source (like dataset, or datatable) so you can loop through rows of dataTable and create a stirng from each row (if its not bound you can do the same with looping through dgv it self).

Can you handle this?

I have done this thing...chec below if it helps u

'Path1 is a string variable declared globally


 Dim di As DirectoryInfo = New DirectoryInfo(Application.StartupPath & "\Images\" + patientname + Date.Today.ToString("yyyy.MM.dd")) --- checked if a directory exists
 If Not di.Exists Then 'if no create the directory
     di.Create()
     Dim fileLoc As String = Application.StartupPath & "\Images\" + patientname + Date.Today.ToString("yyyy.MM.dd") + "\PatientRegEntry.txt"
     FileOpen(1, fileLoc, OpenMode.Output)
     Path1 = txtPatientID.Text + "*" + patientname + "*" + txtFName.Text + "*" + MName + "*" + LName + "*" + Age + "*" + Gender + "*" + Address + "*" + PhoneNo + "*" + MobNo + "*" + ReasonCurr + "*" + DenHist + "*" + DOB + "*" + ImagePath + "*" + DocName
     Print(1, Path1)
     FileClose()
End If

Mitja,

It has to be a text file because another program I use at work will read the text file and do an analysis. Also, I can handle writing the data from text boxes and DGVs (in fact, I've done it already), but I have a number of customised PropertyGrids, and writing the data from these is proving to be difficult.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.