Sequential file problems

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Sep 2008
Posts: 25
Reputation: tyserman5674 is an unknown quantity at this point 
Solved Threads: 0
tyserman5674 tyserman5674 is offline Offline
Light Poster

Sequential file problems

 
0
  #1
Nov 4th, 2008
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:
  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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Sequential file problems

 
0
  #2
Nov 5th, 2008
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.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Dec 2002
Posts: 461
Reputation: waynespangler is on a distinguished road 
Solved Threads: 56
waynespangler waynespangler is offline Offline
Posting Pro in Training

Re: Sequential file problems

 
0
  #3
Nov 5th, 2008
Show the code you used to write the file.
Wayne

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 25
Reputation: tyserman5674 is an unknown quantity at this point 
Solved Threads: 0
tyserman5674 tyserman5674 is offline Offline
Light Poster

Re: Sequential file problems

 
0
  #4
Nov 5th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 25
Reputation: tyserman5674 is an unknown quantity at this point 
Solved Threads: 0
tyserman5674 tyserman5674 is offline Offline
Light Poster

Re: Sequential file problems

 
0
  #5
Nov 5th, 2008
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.
  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
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC