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]

So you want to maintain all the numbers in one text file?

You can read good article on file handling in .NET here

Yes that is correct!
Thanks :)

Yes that is correct!
Thanks :)

Let me know if you need further help.

I'm sorry I was actually referring to the previous post about "So you want to maintain all the numbers in one text file? " I will read over the article to see if I understand how to do it. I guess I am just more or so confused on how to actually start it

Okay I am thinking I need some more help. So far this is my code and I nothing is coming up with the file.

Imports System.IO
Public Class Form1

    Private Sub BtnProcessData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnProcessData.Click
        Dim previous1 As Long
        Dim previous2 As Long
        Dim i As Integer
        Dim input As Integer
        Dim fibonacci As Long

        previous1 = 1
        previous2 = 1

        input = CInt(txtinput.Text)

        If input = 1 Then
            fibonacci = 1

        ElseIf input = 2 Then
            fibonacci = 1

        Else
            For i = 3 To input

                fibonacci = previous1 + previous2
                previous1 = previous2
                previous2 = fibonacci

            Next i
        End If

        TxtFibonacci.Text = CStr(fibonacci)
    End Sub
End Class


Public Class Form1
    Dim InpFileName As String, FileOpenFlag As Integer
    Dim FileData(100) As String, ItemCount As Integer
    Dim DataFile As StreamReader

    Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
        ' Get name of file to read and open file
        Dim dgrResult As DialogResult
        Dim dlgOpen As New OpenFileDialog
        If FileOpenFlag > 0 Then DataFile.Close()
        ' Set properties and open file dialog
        dlgOpen.InitialDirectory = "F:"
        dlgOpen.Filter = "Text Files|*.txt|Word Files|*.doc|All Files|*.*"
        dgrResult = dlgOpen.ShowDialog()

        ' If file name OK then open file for reading
        If dgrResult = DialogResult.OK Then
            InpFileName = dlgOpen.FileName      ' Get filename
            DataFile = File.OpenText(InpFileName)
            FileOpenFlag = 1
            ItemCount = 0
        Else
            txtData.Text = "File not specified"
        End If
    End Sub

    Private Sub btnReadNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReadNext.Click
        ' Read one line from the file
        Dim Temp As String
        If FileOpenFlag > 0 Then
            If DataFile.Peek <> -1 Then
                Temp = DataFile.ReadLine
                If Temp.Trim <> "" Then
                    ItemCount = ItemCount + 1
                    FileData(ItemCount) = Temp.Trim
                    txtItemNumber.Text = CStr(ItemCount)
                    txtData.Text = FileData(ItemCount)
                Else
                    txtItemNumber.Text = ""
                    txtData.Text = "Blank line - Not stored"
                End If
            End If
        End If
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If FileOpenFlag > 0 Then DataFile.Close()
    End Sub

    Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
        ' Not complete; should check that text box contains 
        '  a valid number
        Dim Index As Integer
        Index = CInt(txtItemNumber.Text)
        txtData.Text = FileData(Index)
    End Sub
End Class

I don't know really what I did wrong?
Can you please please help ?? Thanks!

I will take look at it.

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.