Need help with file parsing

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
   
    Else
        strNewArray(num) = strLn & vbCrLf
    End If
   
Next

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
LVL 1
leotronAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VBRocksCommented:
Would the Trim() function help you achieve your goal?  It will remove leading and trailing spaces.  Also, you can use LTrim() to remove only leading (left) spaces, and RTrim() to remove trailing (right) spaces.

strLn = Trim(strArray(num))

Hope that helps.
0
leotronAuthor Commented:
I have tried that but it continues to do the same thing. Thank you though
0
sirbountyCommented:
What about something like this...

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)
For num = 0 To Upper
    strLn = strArray(num)
    If Left(strLn, 1) <> "#" And strLn <> "" Then
        strData = strData & vbCrLf & strLn
    End If
Next
Close #1
Text1.Text = strData
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

leotronAuthor Commented:
Ok this code will display the text justified to the left but the one thing is that the first line is blank and then from the next line after the text starts to display correctly. I want to get rid of the blank lines as well. here is what I mean

[sample]
                        <------ blank line
some txt
next txt
more txt

[end sample]
0
sirbountyCommented:
Try modifying the compare...

 If Left(strLn, 1) <> "#" And Trim(strLn) <> "" Then
0
leotronAuthor Commented:
Nope same thing
0
sirbountyCommented:
Oh wait!
The problem is here...
        strData = strData & vbCrLf & strLn

First pass through strData won't hold anything, so it becomes
<cr>
[Your data]

So, let's see - try stripping it off using:

Text1.Text = mid(strData,2)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
leotronAuthor Commented:
Now that was great the only thing is that I had to add 3 instead of 2 because if not it will display a question mark symbol. But it is doing what I want it to do, Great job sirbounty. One last question how can I display a list of check boxes via a loop that will correspond to each line of the text file.
0
sirbountyCommented:
Are you trying to dynamically create a check box per line of data?
Been a while since I've done anything like that in VB...

Not really sure I'm satisfied with that solution anyway.

I don't know your data, but perhaps use the | character to build the string, like this:

strData = strData & "|" & strLn

and then clean it up at the end, like this: (trims off the first, then replaces all others with a <cr>)
Text1.Text = replace(mid(strData,2),"|",vbCrLF)
0
leotronAuthor Commented:
Yes one check box per line of data, this will be on a seperate form that I am using to delete entries in the file. So I will be reading the file in again, and then adding a check box before the line of text.  If the check box is checked the line will be deleted from the text file once the user clicks on the delete button. and that other suggestion worked great also thanks
0
sirbountyCommented:
I'm really not sure on the check box...
Found a couple of walkthroughs - perhaps this will help.
http://www.thescarms.com/vbasic/VB6Features.asp
http://www.codeguru.com/vb/controls/vb_activex/activex/article.php/c3499/
0
sirbountyCommented:
Happy to help - thanx for the grade! :^)
0
leotronAuthor Commented:
You earned it thank you for the help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.