Saving Data

alloush25

New member
Joined
Oct 5, 2007
Messages
3
Programming Experience
Beginner
Dear all,

I have a program that works fine, but it takes too long to save the data. I think the reason for this is using a loop to build a string then saving the file. Below is my code

VB.NET:
Xpos, Ypos, Zpos, As integer
strData2 As string
strData3 As string
strData  As string
UtunnelDbl As Double
arWire2 As Double

strData2 = ""

                Do While Ala < 270000
                    strData2 = strData2 & UtunnelDbl(Ala) & vbTab & vbTab
                    Ala = Ala + 1
                Loop

                Ala = 0

                strData3 = ""

                Do While Ala < 270000
                    strData3 = strData3 & arWire2(Ala) & vbTab & vbTab
                    Ala = Ala + 1
                Loop

                Ala = 0

strData = Xpos & vbTab & vbTab & Ypos & vbTab & vbTab & Zpos & vbTab & vbTab & strData2 & vbTab & vbTab & strData3

                swStreamWriter.WriteLine(strData)

arWire2 and Utunnel dbl are an array with size 1 X 270000,


i would like to save xpos, ypos, zpos, arwire1, UtunnelDbl more efficiently is currently takes about 30 sec to write one line!!!!!


Thank you
 
Last edited by a moderator:
Use System.Text.StringBuilder to build strings, the same operation would take 0.2 seconds - and also equivalent to direct write to the streamwriter. Using a BinaryWriter-Reader operating only on the doubles takes even a third of that, down to 0.06 seconds.
 
Hi John,
Thank you for your reply,

May you please illustrate with an example, it would be great if you can show me the code equivelant to my code, because i am not sure how to do this and my familiarity with VB is minimal at the moment.

Thank you
 
create a System.Text.StringBuilder:
VB.NET:
dim sb as new System.Text.StringBuilder
then you can append as much text you want:
VB.NET:
sb.append(something)

when you want the string:
VB.NET:
sb.tostring()
 
Back
Top