• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 199
  • Last Modified:

Basic data reading

OK heres what I wanna do:

Basically, I have an encrypted CSV file "data.dat", which is loaded into richtextbox1. Then, decryption routine reads richtextbox1 and decrypts the data into richtextbox2.

BUT!!! heres the problem. To load the data into my arrays, I currently save the contents of richtextbox2 into a file "temp.txt", then read this new file into my arrays, and delete the file, thus:

''''''''''''''''''''''''''''''''''''''''''''''''''''
   fnum = FreeFile
   Open App.Path & "temp.txt" For Output As #fnum
   Print #fnum, RichTextBox2.Text
   Close #fnum
   
'clear arrays
   For i = 0 To 255
      array1(i) = ""
      array2(i) = ""
      array3(i) = ""
      array4(i) = ""
   Next
   
   Counter = 0
   fnum = FreeFile
   Open AppPath & "temp.txt" For Input As #fnum
   While Not EOF(fnum)
      Input #fnum, smurfDNS(Counter), smurfName(Counter), smurfMem(Counter), smurfAlias(Counter)
      Counter = Counter + 1
   Wend
   Close #fnum
   retval = Shell(Environ("ComSpec") & " /c " & "del " & Chr(34) & AppPath & "temp.txt" & Chr(34), vbHide)

''''''''''''''''''''''''''''''''''''''''''''''''''''

But I don't wanna have to make this temp file! HELP!

BTW the data in the file is CSV with the format:

text1,text2,text3,text4
text1,text2,text3,text4
text1,text2,text3,text4

etc etc

Thanks in advance! =)
0
rjdown
Asked:
rjdown
1 Solution
 
tshdosCommented:
With your data formatted like that you can use something like this:

Dim Lines() As String
Dim Line As Variant
Dim Parts() As String
Dim Counter As Integer

...Clear Arrays...

Lines = Split( RichTextBox2.Text, vbCrLf )
For Each Line In Lines
   Parts = Split( Line, "," )
   Array1(Counter) = Parts(0)
   Array2(Counter) = Parts(1)
   Array3(Counter) = Parts(2)
   Array4(Counter) = Parts(3)
Next Line

0
 
rjdownAuthor Commented:
Yep works great thanks a lot :)

(added a Counter=Counter+1 before the 'Next Line')

Hmm looks like I got a couple more commands to learn lol
0
 
supunrCommented:
I agree with tshdos solution.

just a comment about clearing arrays.  you could use the command calle "Erase" to clear array.

Erase array1

Good luck!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now