Question import a collection to export to Notepad-Exel

elianeasmar

Well-known member
Joined
Oct 3, 2013
Messages
76
Programming Experience
Beginner
Hello Experts.
I need your help in something. it got a bit hard for me, since i am a beginner.
i have a collection. (Please don't ask me why i'm using a collection :/) , it's an assignment.
--------------------------------------------------------------------------------
Dim _collection As Collection
Dim _icollection As IList(Of _schoolinfo)
Dim _inf As New _schoolinfo
Dim _info As _schoolinfo

and this is my sructure:
-----------------------
Public Structure _schoolinfo
Public Code As String
Public Name As String
Public PhoneNumber As String
Public Address As String
Public Sex As String
Public Title As String
Public Position As String
Public DateTime As DateTime
End Structure
--------------------------------
and i have these two functions.
-------------------------------
Public Sub btnNotepad_Click(sender As Object, e As EventArgs) Handles btnNotepad.Click
Using myWriter As New StreamWriter("C:\Users\ELIANE\Desktop\Exported-to-Notepad.txt", True)
myWriter.WriteLine("{0},{1},{2},{3},{4},{5}", txtCode.Text, cmbTitle.Text, txtName.Text, cmbPosition.Text, txtAddress.Text, txtPhoneNumber.Text)
End Using
End Sub


Private Sub Button3_Click_1(sender As Object, e As EventArgs) Handles Button3.Click
Using myWriter As New StreamWriter("C:\Users\ELIANE\Desktop\Exported-to-Exel.csv", True)
myWriter.Write("{0},{1},{2},{3},{4},{5}", txtCode.Text, cmbTitle.Text, txtName.Text, cmbPosition.Text, txtAddress.Text, txtPhoneNumber.Text)
End Using
End Sub



what i need is to import the collection to the new form that i am using to export what's in it. because the two functions above just export the record displayed in the textboxes.
and i need to combine the two functions in Only One.
and for that i need to apply
for each _inf in collection
.
.
.
Next


I apreciate any help. Thank you :)
 
The thing is how to import the collection that i have in my form no.1 to the other form no.2, where i'm exporting the data to Exel (or notepad)
Any help? :(

and any result about combining the two functions?
 
Hi,

I have just answered your question on combining your functions in your other thread so I will not touch on that aspect again. However, when it comes to Importing your Files into another form I would suggest using the TextFieldParser Class to read your files. Have a look through this documentation:-

TextFieldParser Class (Microsoft.VisualBasic.FileIO)

Hope that helps.

Cheers,

Ian
 
Thank you. I found a solution to it. i can just replace dim by public
Public _collection as Collection

That way i can see my collection from another form
Thanks again :)
 
Hi,

Yes, that is one way to do things but when you get into real programming the Scope, and therefore the Existence, of a variable is something that you need to take into consideration for large applications. This will not cause you any issues during your studies but you should take this into account in a real application. Have a read of this to expand your knowledge when you get some spare time:-

Scope in Visual Basic

Additionally, if you just want to pass a single Object to a New Form from an initial Form then you can also use a Constructor in the Second Form to accept any Object that you want to pass to it as an argument. Have a read of this to see how this can be done:-

Constructor Design

Cheers,

Ian
 
Back
Top