Basic data reading

Posted on 2003-03-27
Medium Priority
Last Modified: 2010-05-01
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) = ""
   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
   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:


etc etc

Thanks in advance! =)
Question by:rjdown
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

tshdos earned 80 total points
ID: 8222243
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


Author Comment

ID: 8222301
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
LVL 11

Expert Comment

ID: 8222304
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!

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question