Welcome Guest [Log In] [Register]
Welcome to The New Coffee Room. We hope you enjoy your visit.


You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Visual Basic
Topic Started: Jan 10 2008, 09:04 PM (188 Views)
Riley
Member Avatar
HOLY CARP!!!
How would I get this program to give me the actual high and low numbers from the list generated, rather than '1' and '10', as the LBound and UBound functions give?

Posted Image

Option Explicit
Dim strNumbers(1 To 10) As String
Dim lngIndex As Long


Sub Numbers()
strNumbers(1) = Int(99 * Rnd + 1)
strNumbers(2) = Int(99 * Rnd + 1)
strNumbers(3) = Int(99 * Rnd + 1)
strNumbers(4) = Int(99 * Rnd + 1)
strNumbers(5) = Int(99 * Rnd + 1)
strNumbers(6) = Int(99 * Rnd + 1)
strNumbers(7) = Int(99 * Rnd + 1)
strNumbers(8) = Int(99 * Rnd + 1)
strNumbers(9) = Int(99 * Rnd + 1)
strNumbers(10) = Int(99 * Rnd + 1)
Dim lngIndex As Long
For lngIndex = LBound(strNumbers) To UBound(strNumbers)
lstNumbers.AddItem strNumbers(lngIndex)
Next lngIndex
End Sub

Private Sub cmdDone_Click()
Unload frmMaxandMin
End Sub

Private Sub cmdMax_Click()
lblAnswer.Caption = "Max Number = " & UBound(strNumbers)
End Sub

Private Sub cmdMin_Click()
lblAnswer.Caption = "Min Number = " & LBound(strNumbers)
End Sub

Private Sub Form_Load()
Randomize
Call Numbers
End Sub
Online Profile Quote Post Goto Top
 
Klaus
Member Avatar
HOLY CARP!!!
Either there is a library function that computes max/min of a list of numbers, or you have to do it by hand by iterating over the list.

It is a bit messy that the numbers in strNumbers are stored as strings, though.
Trifonov Fleisher Klaus Sokolov Zimmerman
Offline Profile Quote Post Goto Top
 
Mikhailoh
Member Avatar
If you want trouble, find yourself a redhead
Can't you do an integer array in VB?
Once in his life, every man is entitled to fall madly in love with a gorgeous redhead - Lucille Ball
Online Profile Quote Post Goto Top
 
Copper
Member Avatar
Shortstop

This is kind of overkill for you problem, but this is a nice way to do it if you are dealing with more data:

http://msdn2.microsoft.com/en-us/library/s...ylist.sort.aspx

The example is here:

http://msdn2.microsoft.com/en-us/library/8k6e334t.aspx
The Confederate soldier was peculiar in that he was ever ready to fight, but never ready to submit to the routine duty and discipline of the camp or the march. The soldiers were determined to be soldiers after their own notions, and do their duty, for the love of it, as they thought best. Carlton McCarthy
Online Profile Quote Post Goto Top
 
Copper
Member Avatar
Shortstop

Actually now that I look at it, it is simple.

I thought this was the example with the "CompareTo" method which is more complex, but still a nice way to sort.
The Confederate soldier was peculiar in that he was ever ready to fight, but never ready to submit to the routine duty and discipline of the camp or the march. The soldiers were determined to be soldiers after their own notions, and do their duty, for the love of it, as they thought best. Carlton McCarthy
Online Profile Quote Post Goto Top
 
Moonbat
Member Avatar
Pisa-Carp
Yuck what a hideous language VB is. (though maybe i only think that because i don't use it).
Entia non sunt multiplicanda praeter necessitatem
Offline Profile Quote Post Goto Top
 
Copper
Member Avatar
Shortstop
Moonbat
Jan 11 2008, 10:50 AM
Yuck what a hideous language VB is. (though maybe i only think that because i don't use it).


Yup. I'm mostly C# now so I see a lot of VB since the 2 come from the same factory.

Of course 370 assembler language is still the king.
The Confederate soldier was peculiar in that he was ever ready to fight, but never ready to submit to the routine duty and discipline of the camp or the march. The soldiers were determined to be soldiers after their own notions, and do their duty, for the love of it, as they thought best. Carlton McCarthy
Online Profile Quote Post Goto Top
 
Aqua Letifer
Member Avatar
ZOOOOOM!
Moonbat
Jan 11 2008, 07:50 AM
Yuck what a hideous language VB is. (though maybe i only think that because i don't use it).

Nahh, it's fine for what it's used for, which are fairly simple computations.
I cite irreconcilable differences.
Online Profile Quote Post Goto Top
 
Klaus
Member Avatar
HOLY CARP!!!
Just to add to the confusion, here is what the DIY solution looks like in Haskell:

Quote:
 

list = [53,62,23,77,54]

maxnumber = foldl max 0 list
minnumber = foldl min 100 list
Trifonov Fleisher Klaus Sokolov Zimmerman
Offline Profile Quote Post Goto Top
 
« Previous Topic · The New Coffee Room · Next Topic »
Add Reply