Quantcast
Viewing all articles
Browse latest Browse all 27034

[RESOLVED] VB Array help

In this project, i'm trying to find the total average, minimum, maximum, and amount of numbers below average. My logic is wrong somewhere, I just cant quite figure it out. It probably has to do with assigning variables to the array.
(I am aware I haven't done maximum yet)
If I could get some help find the problem, that would be great.





Code:


Public Class Stats
    Private Sub btnStatistics_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnStatistics.Click
        'show all stats
        MessageBox.Show(all(txtUserinput.Text))








    End Sub

 

 
    Function process_String(ByVal ps As String) As Integer()
        'define variables
        Dim usrInput(5) As Integer
        Dim x As Integer = 0
        Dim i As Integer = 0
        Dim y As Integer = 0
        Dim usrinput_ As String

        'simplify input
        usrinput_ = txtUserinput.Text
        'find comma and split numbers
        Do While x <= usrInput.GetUpperBound(0)
            y = usrinput_.IndexOf(",", i)
            usrInput(x) = CInt(txtUserinput.Text.Substring(i, y))
            i = y + 1
            x += 1
        Loop
        'return value
        Return (usrInput)



    End Function

    Function Total(ByVal a() As Integer) As Integer
        'define variables
        Dim intTotal As Integer = 0
        Dim intCount As Integer

        'total all numbers
        For intCount = 0 To (a.GetUpperBound(0))
            intTotal = +a(intCount)
        Next
        'return total
        Return (intTotal)

    End Function


    Function Average(ByVal b() As Integer) As Integer
        'define variables
        'use double for devision
        Dim intTotal As Integer = 0
        Dim dblAverage As Double
        Dim intcount As Integer
        'gathers total
        For intocount = 0 To (b.GetUpperBound(0))
            intTotal = +b(intcount)
        Next
        'devide to get average
        dblAverage = intTotal / (b.GetUpperBound(0) + 1)

        Return (dblAverage)
    End Function

    Function min(ByVal c() As Integer) As Integer
        'define variables
        Dim intCount As Integer
        Dim IntLowest As Integer
        'define lowest variable
        IntLowest = c(0)

        For intCount = 1 To (c.GetUpperBound(0))
            If c(intCount) < IntLowest Then
                IntLowest = c(intCount)
            End If
        Next
        'return lowest value
        Return (IntLowest)

    End Function



    Function belowavg(ByVal d() As Integer) As Integer

        'define variables
        Dim cntr As Integer = 0
        Dim intTotal As Integer = 0
        Dim dblAverage As Double
        Dim intcount As Integer

        For intocount = 0 To (d.GetUpperBound(0))
            intTotal = +d(intcount)
        Next

        dblAverage = intTotal / (d.GetUpperBound(0) + 1)

        'counter for counting how many numbers are below average
        For i = 0 To d.GetUpperBound(0)
            If d(i) < dblAverage Then
                cntr += 1

            End If



        Next


        Return (cntr)

    End Function
    Function all(ByVal s As String) As String
        'defines variables
        Dim minimum As Integer
        Dim maximum As Integer
        Dim average_ As Integer
        Dim total_ As Integer
        Dim underaverage As Integer
        Dim myarray() As Integer
        'assigns variables to value
        myarray = process_String(s)
        minimum = min(myarray)
        maximum =
        average_ = Average(myarray)
        total_ = Total(myarray)
        underaverage = belowavg(myarray)
        'gives a string for later use on message box
        Return ("statistics:" & ControlChars.CrLf & "average is " & average_.ToString & ControlChars.CrLf & "max is " & maximum.ToString & ControlChars.CrLf & "min is " & ControlChars.CrLf & "minimum is " & minimum.ToString & ControlChars.CrLf & "amount of numbers under average: " & average_.ToString & ControlChars.CrLf & "total " & total_.ToString)
    End Function

    Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
        Me.Close()

    End Sub

    Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
        txtUserinput.Text = " "
    End Sub
End Class


Viewing all articles
Browse latest Browse all 27034

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>