How to create array from StreamReader object

I need to Load the interest rates for the 7 year, 15 year, and 30 year loans from a file called rates.txt.  The file can be viewed at http://www.stevetout.com/rates.txt

I use the following code to read the file, and assign the contents from file to a variable.

    Dim oFile As System.IO.File
    Dim oRead As System.IO.StreamReader
    Dim EntireFile As String

      oRead = oFile.OpenText("C:\Documents and Settings\Steve.PORTLAND\My Documents\Visual Studio      Projects\WindowsApplication2\rates.txt")
        EntireFile = oRead.ReadToEnd()

I need to read the rate and number of years from the EntireFile string, parse it and compute a monthly payment.

Will somebody please post some code that parses the values from the txt file, and makes them available to my calculator sub?

Thanks.
gmahler5thAsked:
Who is Participating?
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.

DotNetLover_BaanCommented:
Hi there,
I guess ur problem is reading data line by line till the end of file. Here is the code part that you can use.

        Dim oFile As System.IO.File
        Dim oRead As System.IO.StreamReader
        Dim Line As String
        oRead = oFile.OpenText("C:\Documents and Settings\Steve.PORTLAND\My Documents\Visual Studio      Projects\WindowsApplication2\rates.txt")
        Try
            Do
                Line = oRead.ReadLine()
                If Not Line Is Nothing Then
                    TextBox1.Text &= Line.Substring(Line.IndexOf(",") + 1).TrimEnd(")") & vbCrLf
                End If
            Loop Until Line Is Nothing
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        oRead.Close()

Let me know if you need any help.
-Baan
0
gmahler5thAuthor Commented:
I got the error TextBox1 is not declared.

What is TextBox1 used for?  None of the variables in the file will be a part of the UI

Also, I need to access one of the lines from the rates.txt file to use in a calculation.  How do I obtain those values for the calculation?
0
platinumbayCommented:
I tested this locally with your file.

        Dim oFile As System.IO.File
        Dim oRead As System.IO.StreamReader
        Dim strLine As String
        Dim isEnd As Boolean = False
        Dim strRegExp As String = "PDR(?:\[|\()(?<Seq>\d{1})(?:\]|\))\s\((?<Num1>\d+)(?:,|\.)(?<Num2>[0-9\.]+)\)"

        oRead = oFile.OpenText("C:\rates.txt")
        Do While isEnd = False
            If oRead.Peek = -1 Then
                isEnd = True
                Exit Do
            End If
            strLine = oRead.ReadLine

            Dim iMatch As Match = Regex.Match(strLine, strRegExp)

            'MsgBox(iMatch.Groups("").Value.ToString & ":" & iMatch.Groups(1).Value.ToString & ":" & iMatch.Groups(2).Value.ToString)
            Dim seq As String = iMatch.Groups("Seq").Value.ToString
            Dim num1 As String = iMatch.Groups("Num1").Value.ToString
            Dim num2 As String = iMatch.Groups("Num2").Value.ToString

            ' Put processing here
            MsgBox(seq.ToString & ":" & num1.ToString & ":" & num2.ToString)
        Loop
        MsgBox("Done")
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
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

gmahler5thAuthor Commented:
I'm using vb.net... what are you using?

I got an error that says "Type 'Match' is not defined.

I think I'm getting close..
0
platinumbayCommented:
Ah, sorry, you need to import System.Text.RegularExpressions
0
gmahler5thAuthor Commented:
AWESOME!!! YOU ROCK!

I BEG YOU TO HELP ME ON SOME OTHER PROBLEMS I HAVE POSTED!  

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21214482.html

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21211146.html

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21202736.html

I'm desperate!  I need to get this project done ASAP.

Thanks Platinumbay!

On MSN Messenger - gmahler5th@hotmail.com
0
gmahler5thAuthor Commented:
That worked!  Thank you!  Thank you!  

More points await in the other open questions of mine here on EE :-)

Can you take a look?
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.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.