Connecting Tech Pros Worldwide Forums | Help | Site Map

Bit of a problem - HELP

Michael Warner
Guest
 
Posts: n/a
#1: Jul 17 '05
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


Steve Gerrard
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Bit of a problem - HELP



"Michael Warner" <cornerstonestudios@adelphia.net> wrote in message
news:h9OdnU4ggN5ZB9XfRVn-1w@adelphia.com...[color=blue]
>
> 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.
>
> 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
>[/color]

I will start you off, and hope you recognize a pattern:

Private Function LoCard()
Dim intLoCard As Integer
Dim intIndex As Integer

intLoCard = HiCard() 'starting value

For intIndex = LBound(ArrScore) To UBound(ArrScore)
' and you know the rest....


Michael Warner
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Bit of a problem - HELP


Steve Gerrard wrote:[color=blue]
> "Michael Warner" <cornerstonestudios@adelphia.net> wrote in message
> news:h9OdnU4ggN5ZB9XfRVn-1w@adelphia.com...
>[color=green]
>>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.
>>
>>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
>>[/color]
>
>
> I will start you off, and hope you recognize a pattern:
>
> Private Function LoCard()
> Dim intLoCard As Integer
> Dim intIndex As Integer
>
> intLoCard = HiCard() 'starting value
>
> For intIndex = LBound(ArrScore) To UBound(ArrScore)
> ' and you know the rest....
>
>[/color]
the low card now returns a value of 0
Steve Gerrard
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Bit of a problem - HELP



"Michael Warner" <cornerstonestudios@adelphia.net> wrote in message
news:yf6dnT_-ppi-TtXfRVn-1A@adelphia.com...[color=blue]
> Steve Gerrard wrote:[color=green]
>> "Michael Warner" <cornerstonestudios@adelphia.net> wrote in message
>> news:h9OdnU4ggN5ZB9XfRVn-1w@adelphia.com...
>>
>>[/color]
> the low card now returns a value of 0[/color]

Um, it would help if you posted your code...


Raoul Watson
Guest
 
Posts: n/a
#5: Jul 17 '05

re: Bit of a problem - HELP



"Michael Warner" <cornerstonestudios@adelphia.net> wrote in message
news:yf6dnT_-ppi-TtXfRVn-1A@adelphia.com...[color=blue]
> Steve Gerrard wrote:[color=green]
> > "Michael Warner" <cornerstonestudios@adelphia.net> wrote in message
> > news:h9OdnU4ggN5ZB9XfRVn-1w@adelphia.com...
> >[color=darkred]
> >>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.
> >>
> >>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
> >>[/color]
> >
> >
> > I will start you off, and hope you recognize a pattern:
> >
> > Private Function LoCard()
> > Dim intLoCard As Integer
> > Dim intIndex As Integer
> >
> > intLoCard = HiCard() 'starting value
> >
> > For intIndex = LBound(ArrScore) To UBound(ArrScore)
> > ' and you know the rest....
> >
> >[/color]
> the low card now returns a value of 0[/color]

You definitely don't want to include zero..

For intIndex = LBound(ArrScore) To UBound(ArrScore)
If ArrScore(intIndex) > 0 Then
If ArrScore(intIndex) < intLoCard Then
intLoCard = ArrScore(intIndex)
End If
End If
Next intIndex


Closed Thread