943,634 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 1769
  • VB.NET RSS
Nov 4th, 2008
0

Sequential file problems

Expand Post »
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:
VB.NET Syntax (Toggle Plain Text)
  1. 'declare object reader, string variables and array count
  2. Dim objReader As IO.StreamReader
  3. Dim _strInterestRates(3) As String
  4. Dim intArrayCount As Integer = 0
  5.  
  6. If System.IO.File.Exists("\interestRates.txt") = True Then
  7. objReader = System.IO.File.OpenText("\interestRates.txt")
  8.  
  9. Do While objReader.Peek <> -1 '-1 is the null value
  10. _strInterestRates(intArrayCount) = objReader.ReadLine()
  11. intArrayCount += 1 'add one to the array counter
  12.  
  13. Loop
  14.  
  15. objReader.Close()
  16. Else : MessageBox.Show("The external interest rates file does not exist", "Mortgage Calculator", MessageBoxButtons.OK)
  17. 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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
tyserman5674 is offline Offline
25 posts
since Sep 2008
Nov 5th, 2008
0

Re: Sequential file problems

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\
Last edited by iamthwee; Nov 5th, 2008 at 5:21 am.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Nov 5th, 2008
0

Re: Sequential file problems

Show the code you used to write the file.
Reputation Points: 84
Solved Threads: 58
Posting Pro in Training
waynespangler is offline Offline
461 posts
since Dec 2002
Nov 5th, 2008
0

Re: Sequential file problems

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
Reputation Points: 10
Solved Threads: 0
Light Poster
tyserman5674 is offline Offline
25 posts
since Sep 2008
Nov 5th, 2008
0

Re: Sequential file problems

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
[code=vbnet]
'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
[\code]
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.
VB.NET Syntax (Toggle Plain Text)
  1. Private Sub RadioButton(ByVal sender As Object, ByVal e As System.EventArgs) Handles rbtnLoanTerm1.CheckedChanged, rbtnLoanTerm2.CheckedChanged, rbtnLoanTerm3.CheckedChanged
  2. Dim ThisButton As RadioButton
  3. Dim dblLoanTerm() As Double = {7, 15, 30}
  4. Dim _strinterestRates(3) As Double
  5. Dim dblInterestRate As Double
  6.  
  7. ThisButton = CType(sender, RadioButton)
  8. If ThisButton.Checked = rbtnLoanTerm1.Checked Then
  9. Dim txtInterestRate = _strinterestRates(0)
  10. 'displays array position 0 in Interest Rate text box
  11. Me.txtInterestRate.Text = dblInterestRate
  12.  
  13. 'displays array position 0 in loan term text box
  14. Me.txtLoanTerm.Text = dblLoanTerm(0)
  15.  
  16. End If
I cannot get it to get the numbers from the external file.
Please Help,
Ken
Last edited by cscgal; Nov 5th, 2008 at 7:33 pm. Reason: Fixed code tags
Reputation Points: 10
Solved Threads: 0
Light Poster
tyserman5674 is offline Offline
25 posts
since Sep 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Novice needs help
Next Thread in VB.NET Forum Timeline: Creating or opening existing tables





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC