| | |
input from user from .txt
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2007
Posts: 13
Reputation:
Solved Threads: 0
First off, Thanks again for all your guys help
I worked on a project where the user was supposed to enter numbers one at a time. After each number is entered, the program is to display the number of inputs, the total numbers entered, the average, the maximum and the minimum.
But what I am trying to accomplish now (just to further myself in this field) is: Instead of the user entering numbers one at a time as in my orginal program, I want the program to read the input numbers from a text file. When the first number is requested, that data file is to be opened and the first number read and processed. The file is then to be left open for the rest of the numbers to be read. When the program is at its end, the file will be closed. A restart button is to allow the orginal file or another file to be read from the beginning.
----Orginal Project----
[Public Class Form1
Dim InpNumber, InpTotal, InpCount, InpAverage As Double
Dim InpMaximum, InpMinimum As Double
Private Sub BtnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEnter.Click
InpNumber = CDbl(txtInput.Text)
If InpCount = 0 Then
InpTotal = InpNumber
InpAverage = InpNumber
InpMinimum = InpNumber
InpMaximum = InpNumber
InpCount = InpCount + 1
Else
InpCount = InpCount + 1
InpTotal = InpTotal + InpNumber
InpAverage = InpTotal / InpCount
End If
If InpMinimum > InpNumber Then
InpMinimum = InpNumber
End If
If InpMaximum < InpNumber Then
InpMaximum = InpNumber
End If
txttotal.Text = CStr(InpTotal)
txtaverage.Text = CStr(InpAverage)
txtmin.Text = CStr(InpMinimum)
txtmax.Text = CStr(InpMaximum)
txtcount.Text = CStr(InpCount)
End Sub
Private Sub BtnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnReset.Click
InpNumber = CDbl(txtInput.Text)
If InpNumber = InpNumber Then
InpTotal = 0
InpAverage = 0
InpMinimum = 0
InpMaximum = 0
InpCount = 0
InpNumber = 0
End If
txtInput.Text = CStr(InpNumber)
txttotal.Text = CStr(InpTotal)
txtaverage.Text = CStr(InpAverage)
txtmin.Text = CStr(InpMinimum)
txtmax.Text = CStr(InpMaximum)
txtcount.Text = CStr(InpCount)
End Sub
End Class]
I worked on a project where the user was supposed to enter numbers one at a time. After each number is entered, the program is to display the number of inputs, the total numbers entered, the average, the maximum and the minimum.
But what I am trying to accomplish now (just to further myself in this field) is: Instead of the user entering numbers one at a time as in my orginal program, I want the program to read the input numbers from a text file. When the first number is requested, that data file is to be opened and the first number read and processed. The file is then to be left open for the rest of the numbers to be read. When the program is at its end, the file will be closed. A restart button is to allow the orginal file or another file to be read from the beginning.
----Orginal Project----
[Public Class Form1
Dim InpNumber, InpTotal, InpCount, InpAverage As Double
Dim InpMaximum, InpMinimum As Double
Private Sub BtnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEnter.Click
InpNumber = CDbl(txtInput.Text)
If InpCount = 0 Then
InpTotal = InpNumber
InpAverage = InpNumber
InpMinimum = InpNumber
InpMaximum = InpNumber
InpCount = InpCount + 1
Else
InpCount = InpCount + 1
InpTotal = InpTotal + InpNumber
InpAverage = InpTotal / InpCount
End If
If InpMinimum > InpNumber Then
InpMinimum = InpNumber
End If
If InpMaximum < InpNumber Then
InpMaximum = InpNumber
End If
txttotal.Text = CStr(InpTotal)
txtaverage.Text = CStr(InpAverage)
txtmin.Text = CStr(InpMinimum)
txtmax.Text = CStr(InpMaximum)
txtcount.Text = CStr(InpCount)
End Sub
Private Sub BtnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnReset.Click
InpNumber = CDbl(txtInput.Text)
If InpNumber = InpNumber Then
InpTotal = 0
InpAverage = 0
InpMinimum = 0
InpMaximum = 0
InpCount = 0
InpNumber = 0
End If
txtInput.Text = CStr(InpNumber)
txttotal.Text = CStr(InpTotal)
txtaverage.Text = CStr(InpAverage)
txtmin.Text = CStr(InpMinimum)
txtmax.Text = CStr(InpMaximum)
txtcount.Text = CStr(InpCount)
End Sub
End Class]
![]() |
Similar Threads
- Reading txt file into Hash Table (C++)
- how to reverse a numbers input by user (C)
- How to edit textboxes for second time input from user in MFC VC++ Application (C++)
- SQL statement to query user input?? (MS Access and FileMaker Pro)
- handeling wrong input from user (C++)
- Creating a GUI that accepts user input help (Java)
- Need Help With Error Checking User Input (C)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Manipulating data from excel.. Please help me!!
- Next Thread: VB > Access2000 Database Upgrade Path
Views: 599 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 429 2007 access activex add age append application basic beginner birth bmp c++ calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh report retrieve save search sendbyte sites sort sql sql2008 sqlserver struct subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





