Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


How to put each chars of a line of a text file  into an array ?

Posted on 2003-03-06
Medium Priority
Last Modified: 2010-05-01
here is my code:

Set textStreamObject = fso.OpenTextFile("data.tmp", 1, False, 0)
textzone2.Text = textStreamObject.ReadLine
Set textStreamObject = Nothing
Set fso = Nothing
textzone.Text = "TEST PASSED"

it reads the first line of the file data.temp and its shown in textzone2.

Now id like to put all chars of that line into an array. any suggestions ?
Question by:Punker51

Accepted Solution

navneet77 earned 200 total points
ID: 8085513
Try a loop with and use mid$
an example

Private Sub Command1_Click()
Dim str As String
Dim a() As String
Dim i As Integer
str = "hello"
ReDim a(1 To Len(str))
i = 1
Do While i <= Len(str)
a(i) = Mid$(str, i, 1)
i = i + 1

End Sub

the array a will contains "h" "e" "l" "l" "o" after this code is run
LVL 11

Expert Comment

ID: 8085520
why not use a code like this

Private Sub SomeFunc()
     Dim strLine as String

     Open "C:\data.tmp" For Input as #1

     ' Get the first line
     Line Input #1, strLine
     Close #1

     txtTextBox.Text strLine
End Sub

Good Luck

Expert Comment

ID: 8085527
Well, First, Why????
Seems like a kind of pointless thing to do.

something like

    Dim myArr() As String
    Dim ptr As Long
    ReDim myArr(1 To Len(textzone2.Text))
    For ptr = 1 To Len(textzone2.Text)
        myArr(ptr) = Mid(textzone2.Text, ptr, 1)
    Next ptr

Expert Comment

ID: 8085542
navneet77 You got there first, and good point about Mid$ rather than just Mid

Author Comment

ID: 8089213
Exactly what i wanted to know
thx m8

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.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

577 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