hey guys,
I am having a bit of an issue with a project I'm doing. Basically what
it will ultimately end up able to do is that it will accept set up a
dynamic array based on user input and allow the user to define the value
for each dimension in the array. It will output the High value, the Low
value and the average of them all. I seem to have a bit of a problem.
I can't seem to get a working function for finding the lowest value of
the array. If anyone could help me, I would be most greatful.
Source code has been included as an attachment
VERSION 5.00
Begin VB.Form frmCards
Caption = "Form1"
ClientHeight = 3990
ClientLeft = 180
ClientTop = 570
ClientWidth = 5805
LinkTopic = "Form1"
ScaleHeight = 3990
ScaleWidth = 5805
Begin VB.TextBox txtResult
Height = 285
Left = 2520
TabIndex = 4
Top = 840
Width = 2775
End
Begin VB.CommandButton cmdAve
Caption = "Command1"
Height = 495
Left = 120
TabIndex = 3
Top = 720
Width = 2055
End
Begin VB.CommandButton cmdOutput
Caption = "Output"
Height = 375
Left = 120
TabIndex = 2
Top = 2760
Width = 2175
End
Begin VB.CommandButton cmdConstructArray
Caption = "Start input"
Height = 495
Left = 120
TabIndex = 0
Top = 120
Width = 2175
End
Begin VB.Label lblNumScore
BorderStyle = 1 'Fixed Single
Height = 375
Left = 2520
TabIndex = 1
Top = 120
Width = 2775
End
End
Attribute VB_Name = "frmCards"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Global Declarations
'declare Array
Dim ArrScore() As Single
Private Sub cmdAve_Click()
'test button for making sure functions work
highestcard = Me.txtResult.Text
End Sub
Private Sub cmdConstructArray_Click()
'Information: This function is what initially populates the array.
'Sub Declarations
Dim intGetScoreNo As Integer
Dim G As Integer
'input and display array size in text field
intGetScoreNo = InputBox("Enter number of cards")
lblNumScore.Caption = intGetScoreNo
'Dynamically resize the array to what is needed
ReDim ArrScore(intGetScoreNo)
'populate empty space in array through looping
While G < intGetScoreNo
ArrScore(G) = InputBox("Enter card value ")
G = G + 1
Wend
End Sub
Private Function Ave()
'Information: Function averages information in array
Dim avgsum
Dim G As Integer
intGetScoreNo = lblNumScore.Caption
'loop
While G < intGetScoreNo
avgsum = ArrScore(G) + avgsum
G = G + 1
Wend
Ave = avgsum / intGetScoreNo
End Function
Private Function HiCard()
Dim intHiCard As Integer
Dim intIndex As Integer
For intIndex = LBound(ArrScore) To UBound(ArrScore)
If ArrScore(intIndex) > intHiCard Then
intHiCard = ArrScore(intIndex)
End If
Next intIndex
HiCard = intHiCard
End Function
Private Sub cmdOutput_Click()
MsgBox ("Average: " & Ave & vbNewLine & "Highest: " & HiCard & "Lowest: " & GetLowCard)
End Sub