Page 1 of 1

Reputation:

# Choosing the highest and lowest out of a set of numbers in vb6

Posted 14 April 2010 - 05:57 PM

Okay, so I have a homework assignment that I've been trying to figure out for three days but am getting nowhere. The assignment is to use an inputbox to enter in any amount of test scores and the program should pick out the highest and lowest from all of them. As of now all it does is if I enter in 55,66, and 99, it brings up 556699 in both highest and lowest. Any type of help would be appreciated. Here's my code:

```

For x = 1 To 2
End If
Next

For x = 1 To 2

End If
Next

End Sub
```

Is This A Good Question/Topic? 0

## Replies To: Choosing the highest and lowest out of a set of numbers in vb6

### #2 vb5prgrmr

• D.I.C Lover

Reputation: 109
• Posts: 1,016
• Joined: 21-March 09

## Re: Choosing the highest and lowest out of a set of numbers in vb6

Posted 14 April 2010 - 06:16 PM

Okay, two variables MyH as Integer and MyL As Integer. Enter loop until a value of cancel is entered. While in loop, test MyH<input and if so MyH = input and do the same for MyL>input.

Good Luck

Reputation:

## Re: Choosing the highest and lowest out of a set of numbers in vb6

Posted 15 April 2010 - 03:15 PM

Okay, i've still been working on this and have changed the code somewhat but now it only changes the highest score and displays the lowest as 0. I'm not sure what i'm doing wrong so if anyone can offer up an example or something that would be appreciated.

```Dim intgrades As String = InputBox("Enter grades.", "What are your grades?")

For x = 1 To 20
End If

End If

Next

```

### #4 keakTheGEEK

• D.I.C Regular

Reputation: 108
• Posts: 344
• Joined: 23-February 10

## Re: Choosing the highest and lowest out of a set of numbers in vb6

Posted 15 April 2010 - 04:30 PM

```'This statement. How are you entering your grades? 55 98 75 or 55,88,99 etc
'If you're entering them separated by space, then you need to split them up
'into individual grades to check each one to see which one is highest and lowest.
'You can split on a space, comma, or any other delimiter...

'So, after the statement above is executed (lets say grades were entered like so: 68, 55, 88, 98, 77)
'Split them up. VB6 has a split function that will spit each element into an array:

'Now arrayGrades has each grade as individual elements of the array. You can iterate through the
'array and check each grade to see which one is highest and which one is lowest.

'Modify your for loop so that you are iterating through the arrayGrades:
Dim x As Integer

Next

```

There's a lot more you will need to code to get the highest and lowest grades. But first you need to understand how to store each grade individually for computation. Also, just some advice, I would get out of the habit of using the Val() function. By default it will return zero if the parameter passed to it cannot be converted to a numerical type w/o any kind of warning. Hope that points you in the right direction. Good Luck!

Also, are you sure that this is VB6?
```Dim intgrades As String = InputBox("Enter grades.", "What are your grades?")

```

That looks like VB .NET to me...

### #5 Raju2047

Reputation: 6
• Posts: 55
• Joined: 16-February 09

## Re: Choosing the highest and lowest out of a set of numbers in vb6

Posted 15 April 2010 - 04:51 PM

Hope this may help u lil bit.
```Dim a, b, c, d, e As Integer
a = InputBox("How many scores to be entered.")
For b = 1 To a
c = InputBox("enter the score.")
If b = 1 Then
e = c
d = c
End If
If c > d Then
d = c
End If
If c < e Then
e = c
End If
Next
lblHighest.Text = d
lblLowest.Text = e
```

This post has been edited by Raju2047: 15 April 2010 - 04:53 PM

### #6 vb5prgrmr

• D.I.C Lover

Reputation: 109
• Posts: 1,016
• Joined: 21-March 09

## Re: Choosing the highest and lowest out of a set of numbers in vb6

Posted 15 April 2010 - 11:02 PM

You will need to initially set the lowest grade to some high value like 1000 before you start your comparisons...

Good Luck

### #7 vb5prgrmr

• D.I.C Lover

Reputation: 109
• Posts: 1,016
• Joined: 21-March 09

## Re: Choosing the highest and lowest out of a set of numbers in vb6

Posted 15 April 2010 - 11:02 PM

You will need to initially set the lowest grade to some high value like 1000 before you start your comparisons...

Good Luck

### #8 Raju2047

Reputation: 6
• Posts: 55
• Joined: 16-February 09

## Re: Choosing the highest and lowest out of a set of numbers in vb6

Posted 16 April 2010 - 05:38 AM

is there any mistakes in my coding... i haven't set lowest grade to some high value..bt i couldn't find any...

### #9 vb5prgrmr

• D.I.C Lover

Reputation: 109
• Posts: 1,016
• Joined: 21-March 09

## Re: Choosing the highest and lowest out of a set of numbers in vb6

Posted 16 April 2010 - 06:45 AM

You set the variable that is to hold the lowest value to some high number prior to entering the loop or comparing it other input...

Good Luck

### #10 thava

• D.I.C Lover

Reputation: 180
• Posts: 1,606
• Joined: 17-April 07

## Re: Choosing the highest and lowest out of a set of numbers in vb6

Posted 16 April 2010 - 04:37 PM

seems there is no prob in Raju2047's algorithm

### #11 bytelogik

Reputation: 22
• Posts: 218
• Joined: 06-October 09

## Re: Choosing the highest and lowest out of a set of numbers in vb6

Posted 19 April 2010 - 10:39 PM

hi Maegan,
working with comparisons for highest and lowest is a little bit of confusing to most of the beginner coders. try this. (VB6)

```        Dim intgrades As String
dim x as integer,Grade as integer

'setting the initial values is the logic for comparison

'use some error checking if intgrades is NULL

For x = 0 To ubound(grades)
Next

```

all the best.

This post has been edited by bytelogik: 19 April 2010 - 10:42 PM

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }