Hi All,
I am sure having problems with reading from a sequential file. I created a .txt file and placed it several places within the vb.net file folder for the program that I am writing. The problem is that when I try and run the program I get the message that file is not found. I cannot figure out what to do or where to place the file. I have to e-mail the whole folder to my instructor as well.
Here is the code that I have:

'declare object reader, string variables and array count
        Dim objReader As IO.StreamReader
        Dim _strInterestRates(3) As String
        Dim intArrayCount As Integer = 0

        If System.IO.File.Exists("\interestRates.txt") = True Then
            objReader = System.IO.File.OpenText("\interestRates.txt")
            
            Do While objReader.Peek <> -1 '-1 is the null value
                _strInterestRates(intArrayCount) = objReader.ReadLine()
                intArrayCount += 1 'add one to the array counter

            Loop

            objReader.Close()
        Else : MessageBox.Show("The external interest rates file does not exist", "Mortgage Calculator", MessageBoxButtons.OK)
   End If

I have 3 values in the .txt file and read them to 3 different buttons depending which one is checked.
Any help would really be appreciated.
Thanks,
Ken

Member Avatar for iamthwee

Try pointing to the absolute path, or get rid of the first backslash in \interestrates.txt

The file should be kept in the same directory as where your program is ran.

Normally the debug.exe resides under: My documents\visual studio\projects\

Show the code you used to write the file.

waynespangler,
All I did is use NotePad to write the file:
5.35
5.5
5.75
That is all that is in the file and I saved it as strinterestRates.txt and saved it in my main program folder.
Ken

Hi All,
Evidently I found the file because I don't get the error anymore but now I am having other problems. Is there away that I can verify whats in the file?
Here is the code I used

'declare object reader, string variables and array count
    Dim _strinterestRates(3) As String
    Dim intArrayCount As Integer = 0
    Dim objReader As IO.StreamReader

    If System.IO.File.Exists("interestRates.txt") = True Then
        objReader = IO.File.OpenText("interestRates.txt")
                    _strinterestRates(intArrayCount) = objReader.ReadLine()
                  Do While objReader.Peek <> -1 '-1 is the null value
            _strinterestRates(intArrayCount) = objReader.ReadLine()
            intArrayCount += 1 'add one to the array counter
        Loop

        objReader.Close()
    Else : MessageBox.Show("The external interest rates file does not exist", "Mortgage Calculator", MessageBoxButtons.OK)
        'Me.Close()
    End If

    'shows message box explaing how to use the calculator
    MessageBox.Show("Select from the Predefined Loan Terms & Interest Rates" _
    & " or input your own values and Enter the Amount of the Mortgage" _
    & " and then press the Calculate Button to display Payment Amount")

End Sub

Now the problem is that I am trying to use the external file to read into my buttons for the different loan terms.
Here is the code for that.

 Private Sub RadioButton(ByVal sender As Object, ByVal e As System.EventArgs) Handles rbtnLoanTerm1.CheckedChanged, rbtnLoanTerm2.CheckedChanged, rbtnLoanTerm3.CheckedChanged
    Dim ThisButton As RadioButton
    Dim dblLoanTerm() As Double = {7, 15, 30}
    Dim _strinterestRates(3) As Double
    Dim dblInterestRate As Double

    ThisButton = CType(sender, RadioButton)
    If ThisButton.Checked = rbtnLoanTerm1.Checked Then
        Dim txtInterestRate = _strinterestRates(0)
   'displays array position 0 in Interest Rate text box
         Me.txtInterestRate.Text = dblInterestRate

        'displays array position 0 in loan term text box
        Me.txtLoanTerm.Text = dblLoanTerm(0)

    End If

I cannot get it to get the numbers from the external file.
Please Help,
Ken

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.