| | |
Sequential file problems
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Sep 2008
Posts: 25
Reputation:
Solved Threads: 0
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:
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
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)
'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
Any help would really be appreciated.
Thanks,
Ken
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:
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*
•
•
Join Date: Sep 2008
Posts: 25
Reputation:
Solved Threads: 0
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.
I cannot get it to get the numbers from the external file.
Please Help,
Ken
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)
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
Please Help,
Ken
Last edited by cscgal; Nov 5th, 2008 at 7:33 pm. Reason: Fixed code tags
![]() |
Similar Threads
- VB 6.0. Creating a file for random access (Visual Basic 4 / 5 / 6)
- Why do PowerPoint templates take long to appear? (Windows Software)
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- Delphi file creator (Pascal and Delphi)
- Help with subclasses and Methods (Java)
- only a couple of hours to go... (C++)
- C++ sequential files. (C++)
- vb6/common dialog/access db (Visual Basic 4 / 5 / 6)
- Saving a file (Java)
Other Threads in the VB.NET Forum
- Previous Thread: Novice needs help
- Next Thread: Creating or opening existing tables
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
.net .net2008 2008 access advanced application array basic beginner browser button buttons center checkbox click client code combo convert cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic eclipse excel exists fade filter forms function html images input internet listview map mobile module msaccess net number objects open panel pdf picturebox picturebox2 port position print printing problem read regex remove right-to-left save search searchvb.net serial settings shutdown socket sorting sqldatbase sqlserver survey temperature textbox timer timespan transparency txttoxmlconverter user usercontol validation vb vb.net vb2008 vba vbnet visual visualbasic visualbasic.net visualstudio.net web webbrowser winforms winsock wpf wrapingcode xml year






