Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,558 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,931 people online right now. Registration is fast and FREE... Join Now!




Create a text file FROM a Array

 
Reply to this topicStart new topic

Create a text file FROM a Array

pfales
12 Apr, 2008 - 08:30 AM
Post #1

New D.I.C Head
*

Joined: 12 Apr, 2008
Posts: 11

I need help, I am trying to create a text file from an array. This is my script so far:

vb

Dim _strLocationandNameofFile As String = "F:\MiramarBooks.txt"

Dim objWriter As New IO.StreamWriter("F:\Inventory.txt")

Dim intCount As Integer

Dim strFileErrorMessage As String = "The File is not available. Restart when it is available."


If IO.File.Exists(_strLocationandNameofFile) Then

objWriter.Write(_strInventoryItem)

objWriter.Write(",")

objWriter.Write(_decPrice)

objWriter.Write(",")

objWriter.Write(_intQuantityonHand)

objWriter.Write(",")

objWriter.Write(_intQuantityonOrder)

intCount += 1

End If

objWriter.Close()

*edit: Please use code tags in the future, thanks! code.gif


At this point I can get the text file but the information is not what I need. The file shows me this when created:

System.String[],System.Decimal[],System.Int32[],System.Int32[]

I need to show the actual data, Title, Item Price, Numbers on Hand, Total Price of Numbers on Hand.

I also need to show more than just one record (actually 20 records total) in the text file.

Please help.

This post has been edited by Martyr2: 12 Apr, 2008 - 08:37 AM
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Create A Text File FROM A Array
12 Apr, 2008 - 08:56 AM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,213



Thanked: 217 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Now I take it each of those variables are actually arrays right? You are going to want to loop through the array using a subscript, not just the name of the array. So for instance, instead of _strInventoryItem you are going to want _strInventoryItem(0) to print the first item.

Now notice this uses a subscript number, you will use this in a loop which will iterate the array printing each time. Assuming these arrays are parallel (strInventoryItem(0) price is in _decPrice(0) whos quantity is in _quantityonhand(0)) then you can use something along these lines...

vb

Dim i as integer

' Loop through inventory item array and pluck out each value
' from it and its parallel arrays
For i = 0 to _strInventoryItem.length - 1
objWriter.Write(_strInventoryItem(i))
objWriter.Write(",")
objWriter.Write(_decPrice(i))
objWriter.Write(",")
objWriter.Write(_intQuantityonHand(i))
objWriter.Write(",")
objWriter.Write(_intQuantityonOrder(i))

' If you want to then end the line you could write in the carriage return
objWriter.Write(Constants.vbCrlf)
Next


So play around with this code above and you should get it working in no time. What was happening is that you were feeding it the array and it was printing its type, like an array of strings. You actually have to write the individual elements of the array.

Enjoy!

"At DIC we be array writing code ninjas... we also write flowery mushy poetic stuff but we can't show you that because we are suppose to be cool!" decap.gif
User is offlineProfile CardPM
+Quote Post

pfales
RE: Create A Text File FROM A Array
12 Apr, 2008 - 11:30 AM
Post #3

New D.I.C Head
*

Joined: 12 Apr, 2008
Posts: 11

Sorry about the first reply still learning this site.

Martyr2,

Thank you for your advice and guidance. I will apply what you have pointed out and I will practice it.

Again Thank you and all those that are willing to assist thos eof us trying to learn.blink.gif

icon_up.gif

This post has been edited by pfales: 12 Apr, 2008 - 11:34 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 11:28PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month