# VB Loop Minimum Sum and Divisibles

Page 1 of 1

## 1 Replies - 933 Views - Last Post: 20 November 2009 - 01:25 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=140334&amp;s=cf2c196b25df9cd8a83ce2843d5fdee1&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 missystarburst

Reputation: 0
• Posts: 2
• Joined: 19-November 09

# VB Loop Minimum Sum and Divisibles

Posted 19 November 2009 - 10:34 PM

Hello:

I have run into a snag in my loop program. I was able to figure out the maxium sum and average of the sum. But am not able to figure out how to:
1) List the minimum value
2) List the sum of the numers divisible by 5.

These are the numbers.text displayed:

5
15
6
12
7
11
21
25
8
10
14

This is the code:

Private Sub butStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butStart.Click
Dim sr As IO.StreamReader = IO.File.OpenText("numbers.txt")

Dim num As Integer
Dim count, max, min As Integer
Dim sum, avg As Double

sum = 0
count = 0
min = 0

Do While sr.Peek <> -1

sum = sum + num
count += 1

If count = 1 Then
max = num
Else
If num > max Then 'for later numbers look for a new max
max = num
End If
Loop

sr.Close()

' compute statistics
If count > 0 Then
avg = sum / count
Else
End If

End Sub

Is This A Good Question/Topic? 0

## Replies To: VB Loop Minimum Sum and Divisibles

### #2 theunborncoder

Reputation: 13
• Posts: 123
• Joined: 15-October 09

## Re: VB Loop Minimum Sum and Divisibles

Posted 20 November 2009 - 01:25 AM

``` Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim num As Integer
Dim count, max, min As Integer
Dim sum, avg As Double
Dim noDivbyfive As Integer

sum = 0
count = 0

Do While sr.Peek <> -1

sum = sum + num
count += 1
If num Mod 5 = 0 Then
noDivbyfive += num
End If
If count = 1 Then
max = num
min = num
Else
If num > max Then 'for later numbers look for a new max
max = num
End If
If num < min Then
min = num
End If
End If
Loop

sr.Close()

' compute statistics
If count > 0 Then
avg = sum / count
Else