dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: VB6.0 Help!

  1. #1
    Join Date
    Aug 2004
    Posts
    43,023

    VB6.0 Help!

    [Originally posted by DianeD]

    I'm trying to program a student scores project and can't seem to get the coding right for how many times a particular score appears in the variable array. I can get the high, low and average scores to work.˙ for example the low score click event code is:

    Dim intNum As Integer, intLow As Integer, intNumLow As Integer
    intLow = intNumsArray(1)˙ ˙ 'set Low to 1st in array
    ˙ ˙ For intNum = 2 To 20˙ ˙ ˙ ˙ 'test 2 -20 for low
    ˙ ˙ ˙ ˙ If intNumsArray(intNum) < intLow Then
    ˙ ˙ ˙ ˙ ˙ ˙ intLow = intNumsArray(intNum)
    ˙ ˙ ˙ ˙ ˙ ˙ lblLowNum.Caption = intLow˙ ˙ 'input low number in caption

    This portion works great!˙ The problem is the next section where I want the number of times the low score appears in the array to print. It is only 3 times in the array however the code gives me 6.˙ What am I doing wrong?
    ˙ ˙ ˙ ˙
    ˙ ˙ ˙ ˙ ˙ If intNumsArray(intNum) = intLow Then
    ˙ ˙ ˙ ˙ ˙ ˙ intNumLow = intNumLow + 1˙ ˙ 'update Counter
    ˙ ˙ ˙ ˙ ˙&nbsp;
    ˙ ˙ ˙ ˙ ˙ ˙ ˙ ˙ lblNumStu.Caption = intNumLow
    ˙ ˙ ˙ ˙ ˙ ˙ End If
    ˙ ˙ ˙ ˙ ˙ ˙ ˙ ˙&nbsp;
    ˙ ˙ ˙&nbsp; End If

  2. #2
    Join Date
    Aug 2004
    Posts
    43,023

    Re:VB6.0 Help!

    [Originally posted by David Chapman]

    It looks like you are doing the counting of the number of times the low number appears at e same time as looking for the lowest number.
    I think you need to change your code slightly to be more like this

    ---Code---
    Dim intNum As Integer, intLow As Integer, intNumLow As Integer
    intLow = intNumsArray(1)˙ ˙ 'set Low to 1st in array
    ˙ ˙ For intNum = 2 To 20˙ ˙ ˙ ˙ 'test 2 -20 for low
    ˙ ˙ ˙ ˙ If intNumsArray(intNum) < intLow Then
    ˙ ˙ ˙ ˙ ˙ ˙ intLow = intNumsArray(intNum)
    ˙ ˙ ˙ ˙ ˙ ˙ lblLowNum.Caption = intLow˙ ˙ 'input low number in caption
    ˙ ˙ ˙ ˙ End If
    ˙ ˙ Next ' Found lowest number now
    ˙ ˙ For intNum = 1 to 20 ' test all array positions to see if have lowest number in them
    ˙ ˙ ˙ ˙ If intNumsArray(intNum) = intLow Then
    ˙ ˙ ˙ ˙ ˙ ˙ intNumLow = intNumLow + 1˙ ˙ 'update Counter
    ˙ ˙ ˙ ˙ ˙
    ˙ ˙ ˙ ˙ ˙ ˙ lblNumStu.Caption = intNumLow
    ˙ ˙ ˙ ˙ End If
    ˙ ˙ Next
    ˙ ˙ ˙ ˙
    ---end code---
    Hope that helps you

    Dave.

  3. #3
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:VB6.0 Help!

    [Originally posted by DianeD]

    Thank You Very much for your help!˙

    The program works great now!

    Diane

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center