Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Need help with file parsing

Avatar of leotron
leotron asked on
Visual Basic Classic
13 Comments1 Solution271 ViewsLast Modified:
I am parsing a configuration file, the file is structured with "#" in front of every line that is to be commented out. the file also contains blank lines. I have the code inside of a command button and when you click the button the file is parsed and displayed into a text box. The only things that should be displayed is everything that is not commented out (eg lines that start with a "#" and blank lines should not be displayed) This is all working so far, the one thing though is that the first line of my file has  36 spaces before the text, the rest of the lines are fine though. I am stuck now please check my code and help me find the problem. Thank you.

[Begin Code]

Private Sub Command3_Click()

' Declare variables to use
Dim strArray() As String, strNewArray() As String, strFinalArray() As String
Dim strLn As String, strStrip As String, temp As String
Dim num As Integer, Upper As Integer, Max As Integer

Open "myfile.txt" For Input As #1

strArray = Split(Input(LOF(1), 1), vbCrLf)

Upper = UBound(strArray)
ReDim strNewArray(Upper) As String

For num = 0 To Upper
    strLn = strArray(num)
    strStrip = Mid(strLn, 1, 1)
    If strStrip = "" Then
        blank$ = strStrip
    ElseIf strStrip = "#" Then
        hash$ = strStrip
        strNewArray(num) = strLn & vbCrLf
    End If

Close #1

Text1.Text = Join(strNewArray)

End Sub

[end code]

Here is a sample of the file I am parsing.

[begin file]
# Commented line
# Commented line
# Commented line
# Commented line

good data

[end file]

here is a sample of my result from running the command

[begin result]

                                    some text
more text
and more
and more yet
ok thats it

[end of result]

I am bot sure what I am doing wrong or what I am missing. Thanks for all your help
Avatar of sirbounty
This problem has been solved!
Unlock 1 Answer and 13 Comments.
See Answers