?
Solved

How to create array from StreamReader object

Posted on 2004-11-21
7
Medium Priority
?
1,924 Views
Last Modified: 2008-02-01
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.
0
Comment
Question by:gmahler5th
  • 4
  • 2
7 Comments
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 12640997
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
 

Author Comment

by:gmahler5th
ID: 12641013
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
 
LVL 6

Accepted Solution

by:
platinumbay earned 2000 total points
ID: 12641036
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:gmahler5th
ID: 12641055
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
 
LVL 6

Expert Comment

by:platinumbay
ID: 12641077
Ah, sorry, you need to import System.Text.RegularExpressions
0
 

Author Comment

by:gmahler5th
ID: 12641134
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
 

Author Comment

by:gmahler5th
ID: 12641190
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

809 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