PC Review


Reply
Thread Tools Rate Thread

Decrease an array?

 
 
=?Utf-8?B?c3RldmVfZG9j?=
Guest
Posts: n/a
 
      14th Jul 2007
Hi all

Is it possible to decrease an array?

EG with the following Code. If I wanted to be left with the 3 highest number
in that array. I could add them to a Collection and remove them based on a
logic comparison, as 1 option. What are the other options, and are there
better watys of doing this?

Sub TestArrays()
Dim iDiceRoll(5) As Integer
Dim i As Integer

For i = 0 To 5
iDiceRoll(i) = ((6 * Rnd) + 1)
Next i
End Sub


Thanks in advance
Steve
 
Reply With Quote
 
 
 
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      14th Jul 2007
Sub TestArrays()
Dim iDiceRoll As Variant
Dim i As Integer
Randomize
ReDim iDiceRoll(0 To 5)
For i = 0 To 5
iDiceRoll(i) = Int((6 * Rnd) + 1)
Next i
iDiceRoll = Application.Large(iDiceRoll, Array(1, 2, 3))
For i = LBound(iDiceRoll) To UBound(iDiceRoll)
Debug.Print i, iDiceRoll(i)
Next
End Sub

iDiceRoll will have a lower bound of 1 after the use of Large.

--
Regards,
Tom Ogilvy


"steve_doc" wrote:

> Hi all
>
> Is it possible to decrease an array?
>
> EG with the following Code. If I wanted to be left with the 3 highest number
> in that array. I could add them to a Collection and remove them based on a
> logic comparison, as 1 option. What are the other options, and are there
> better watys of doing this?
>
> Sub TestArrays()
> Dim iDiceRoll(5) As Integer
> Dim i As Integer
>
> For i = 0 To 5
> iDiceRoll(i) = ((6 * Rnd) + 1)
> Next i
> End Sub
>
>
> Thanks in advance
> Steve

 
Reply With Quote
 
=?Utf-8?B?c3RldmVfZG9j?=
Guest
Posts: n/a
 
      14th Jul 2007
Thanks Tom
Works a charm
Any chance on an explanation on the code

Steve

"Tom Ogilvy" wrote:

> Sub TestArrays()
> Dim iDiceRoll As Variant
> Dim i As Integer
> Randomize
> ReDim iDiceRoll(0 To 5)
> For i = 0 To 5
> iDiceRoll(i) = Int((6 * Rnd) + 1)
> Next i
> iDiceRoll = Application.Large(iDiceRoll, Array(1, 2, 3))
> For i = LBound(iDiceRoll) To UBound(iDiceRoll)
> Debug.Print i, iDiceRoll(i)
> Next
> End Sub
>
> iDiceRoll will have a lower bound of 1 after the use of Large.
>
> --
> Regards,
> Tom Ogilvy
>
>
> "steve_doc" wrote:
>
> > Hi all
> >
> > Is it possible to decrease an array?
> >
> > EG with the following Code. If I wanted to be left with the 3 highest number
> > in that array. I could add them to a Collection and remove them based on a
> > logic comparison, as 1 option. What are the other options, and are there
> > better watys of doing this?
> >
> > Sub TestArrays()
> > Dim iDiceRoll(5) As Integer
> > Dim i As Integer
> >
> > For i = 0 To 5
> > iDiceRoll(i) = ((6 * Rnd) + 1)
> > Next i
> > End Sub
> >
> >
> > Thanks in advance
> > Steve

 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      14th Jul 2007
I gave you a nice long detailed explanation, but when I hit post, this great
communities web page said page not available and it was all lost. I am not
up for reentering it. So here is the abbreviated

put this in a cell

=LARGE({2,4,6,8,10,12},{1,2,3})

after entering, go to the formula bar and select the formula. Hit F9 to
evaluate it.

You will see what it returns.

hit escape to restore the formula.

See help on the Large Worksheet function in Excel.

--
Regards,
Tom Ogilvy


"steve_doc" wrote:

> Thanks Tom
> Works a charm
> Any chance on an explanation on the code
>
> Steve
>
> "Tom Ogilvy" wrote:
>
> > Sub TestArrays()
> > Dim iDiceRoll As Variant
> > Dim i As Integer
> > Randomize
> > ReDim iDiceRoll(0 To 5)
> > For i = 0 To 5
> > iDiceRoll(i) = Int((6 * Rnd) + 1)
> > Next i
> > iDiceRoll = Application.Large(iDiceRoll, Array(1, 2, 3))
> > For i = LBound(iDiceRoll) To UBound(iDiceRoll)
> > Debug.Print i, iDiceRoll(i)
> > Next
> > End Sub
> >
> > iDiceRoll will have a lower bound of 1 after the use of Large.
> >
> > --
> > Regards,
> > Tom Ogilvy
> >
> >
> > "steve_doc" wrote:
> >
> > > Hi all
> > >
> > > Is it possible to decrease an array?
> > >
> > > EG with the following Code. If I wanted to be left with the 3 highest number
> > > in that array. I could add them to a Collection and remove them based on a
> > > logic comparison, as 1 option. What are the other options, and are there
> > > better watys of doing this?
> > >
> > > Sub TestArrays()
> > > Dim iDiceRoll(5) As Integer
> > > Dim i As Integer
> > >
> > > For i = 0 To 5
> > > iDiceRoll(i) = ((6 * Rnd) + 1)
> > > Next i
> > > End Sub
> > >
> > >
> > > Thanks in advance
> > > Steve

 
Reply With Quote
 
=?Utf-8?B?c3RldmVfZG9j?=
Guest
Posts: n/a
 
      14th Jul 2007
thanks again Tom

"Tom Ogilvy" wrote:

> I gave you a nice long detailed explanation, but when I hit post, this great
> communities web page said page not available and it was all lost. I am not
> up for reentering it. So here is the abbreviated
>
> put this in a cell
>
> =LARGE({2,4,6,8,10,12},{1,2,3})
>
> after entering, go to the formula bar and select the formula. Hit F9 to
> evaluate it.
>
> You will see what it returns.
>
> hit escape to restore the formula.
>
> See help on the Large Worksheet function in Excel.
>
> --
> Regards,
> Tom Ogilvy
>
>
> "steve_doc" wrote:
>
> > Thanks Tom
> > Works a charm
> > Any chance on an explanation on the code
> >
> > Steve
> >
> > "Tom Ogilvy" wrote:
> >
> > > Sub TestArrays()
> > > Dim iDiceRoll As Variant
> > > Dim i As Integer
> > > Randomize
> > > ReDim iDiceRoll(0 To 5)
> > > For i = 0 To 5
> > > iDiceRoll(i) = Int((6 * Rnd) + 1)
> > > Next i
> > > iDiceRoll = Application.Large(iDiceRoll, Array(1, 2, 3))
> > > For i = LBound(iDiceRoll) To UBound(iDiceRoll)
> > > Debug.Print i, iDiceRoll(i)
> > > Next
> > > End Sub
> > >
> > > iDiceRoll will have a lower bound of 1 after the use of Large.
> > >
> > > --
> > > Regards,
> > > Tom Ogilvy
> > >
> > >
> > > "steve_doc" wrote:
> > >
> > > > Hi all
> > > >
> > > > Is it possible to decrease an array?
> > > >
> > > > EG with the following Code. If I wanted to be left with the 3 highest number
> > > > in that array. I could add them to a Collection and remove them based on a
> > > > logic comparison, as 1 option. What are the other options, and are there
> > > > better watys of doing this?
> > > >
> > > > Sub TestArrays()
> > > > Dim iDiceRoll(5) As Integer
> > > > Dim i As Integer
> > > >
> > > > For i = 0 To 5
> > > > iDiceRoll(i) = ((6 * Rnd) + 1)
> > > > Next i
> > > > End Sub
> > > >
> > > >
> > > > Thanks in advance
> > > > Steve

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      14th Jul 2007
Just to add to Tom's abbreviated notes.

Instead of putting that formula in one cell, select a1:C1 and enter the formula
in A1, but hit ctrl-shift-enter to see what's returned in all three cells.



Tom Ogilvy wrote:
>
> I gave you a nice long detailed explanation, but when I hit post, this great
> communities web page said page not available and it was all lost. I am not
> up for reentering it. So here is the abbreviated
>
> put this in a cell
>
> =LARGE({2,4,6,8,10,12},{1,2,3})
>
> after entering, go to the formula bar and select the formula. Hit F9 to
> evaluate it.
>
> You will see what it returns.
>
> hit escape to restore the formula.
>
> See help on the Large Worksheet function in Excel.
>
> --
> Regards,
> Tom Ogilvy
>
> "steve_doc" wrote:
>
> > Thanks Tom
> > Works a charm
> > Any chance on an explanation on the code
> >
> > Steve
> >
> > "Tom Ogilvy" wrote:
> >
> > > Sub TestArrays()
> > > Dim iDiceRoll As Variant
> > > Dim i As Integer
> > > Randomize
> > > ReDim iDiceRoll(0 To 5)
> > > For i = 0 To 5
> > > iDiceRoll(i) = Int((6 * Rnd) + 1)
> > > Next i
> > > iDiceRoll = Application.Large(iDiceRoll, Array(1, 2, 3))
> > > For i = LBound(iDiceRoll) To UBound(iDiceRoll)
> > > Debug.Print i, iDiceRoll(i)
> > > Next
> > > End Sub
> > >
> > > iDiceRoll will have a lower bound of 1 after the use of Large.
> > >
> > > --
> > > Regards,
> > > Tom Ogilvy
> > >
> > >
> > > "steve_doc" wrote:
> > >
> > > > Hi all
> > > >
> > > > Is it possible to decrease an array?
> > > >
> > > > EG with the following Code. If I wanted to be left with the 3 highest number
> > > > in that array. I could add them to a Collection and remove them based on a
> > > > logic comparison, as 1 option. What are the other options, and are there
> > > > better watys of doing this?
> > > >
> > > > Sub TestArrays()
> > > > Dim iDiceRoll(5) As Integer
> > > > Dim i As Integer
> > > >
> > > > For i = 0 To 5
> > > > iDiceRoll(i) = ((6 * Rnd) + 1)
> > > > Next i
> > > > End Sub
> > > >
> > > >
> > > > Thanks in advance
> > > > Steve


--

Dave Peterson
 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      14th Jul 2007
Just a thought,

But then you don't see the results as an array -- at least not as literally.

--
Regards,
Tom Ogilvy


"Dave Peterson" wrote:

> Just to add to Tom's abbreviated notes.
>
> Instead of putting that formula in one cell, select a1:C1 and enter the formula
> in A1, but hit ctrl-shift-enter to see what's returned in all three cells.
>
>
>
> Tom Ogilvy wrote:
> >
> > I gave you a nice long detailed explanation, but when I hit post, this great
> > communities web page said page not available and it was all lost. I am not
> > up for reentering it. So here is the abbreviated
> >
> > put this in a cell
> >
> > =LARGE({2,4,6,8,10,12},{1,2,3})
> >
> > after entering, go to the formula bar and select the formula. Hit F9 to
> > evaluate it.
> >
> > You will see what it returns.
> >
> > hit escape to restore the formula.
> >
> > See help on the Large Worksheet function in Excel.
> >
> > --
> > Regards,
> > Tom Ogilvy
> >
> > "steve_doc" wrote:
> >
> > > Thanks Tom
> > > Works a charm
> > > Any chance on an explanation on the code
> > >
> > > Steve
> > >
> > > "Tom Ogilvy" wrote:
> > >
> > > > Sub TestArrays()
> > > > Dim iDiceRoll As Variant
> > > > Dim i As Integer
> > > > Randomize
> > > > ReDim iDiceRoll(0 To 5)
> > > > For i = 0 To 5
> > > > iDiceRoll(i) = Int((6 * Rnd) + 1)
> > > > Next i
> > > > iDiceRoll = Application.Large(iDiceRoll, Array(1, 2, 3))
> > > > For i = LBound(iDiceRoll) To UBound(iDiceRoll)
> > > > Debug.Print i, iDiceRoll(i)
> > > > Next
> > > > End Sub
> > > >
> > > > iDiceRoll will have a lower bound of 1 after the use of Large.
> > > >
> > > > --
> > > > Regards,
> > > > Tom Ogilvy
> > > >
> > > >
> > > > "steve_doc" wrote:
> > > >
> > > > > Hi all
> > > > >
> > > > > Is it possible to decrease an array?
> > > > >
> > > > > EG with the following Code. If I wanted to be left with the 3 highest number
> > > > > in that array. I could add them to a Collection and remove them based on a
> > > > > logic comparison, as 1 option. What are the other options, and are there
> > > > > better watys of doing this?
> > > > >
> > > > > Sub TestArrays()
> > > > > Dim iDiceRoll(5) As Integer
> > > > > Dim i As Integer
> > > > >
> > > > > For i = 0 To 5
> > > > > iDiceRoll(i) = ((6 * Rnd) + 1)
> > > > > Next i
> > > > > End Sub
> > > > >
> > > > >
> > > > > Thanks in advance
> > > > > Steve

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      14th Jul 2007
There's always a fly in any ointment. <g>

Tom Ogilvy wrote:
>
> Just a thought,
>
> But then you don't see the results as an array -- at least not as literally.
>
> --
> Regards,
> Tom Ogilvy
>
> "Dave Peterson" wrote:
>
> > Just to add to Tom's abbreviated notes.
> >
> > Instead of putting that formula in one cell, select a1:C1 and enter the formula
> > in A1, but hit ctrl-shift-enter to see what's returned in all three cells.
> >
> >
> >
> > Tom Ogilvy wrote:
> > >
> > > I gave you a nice long detailed explanation, but when I hit post, this great
> > > communities web page said page not available and it was all lost. I am not
> > > up for reentering it. So here is the abbreviated
> > >
> > > put this in a cell
> > >
> > > =LARGE({2,4,6,8,10,12},{1,2,3})
> > >
> > > after entering, go to the formula bar and select the formula. Hit F9 to
> > > evaluate it.
> > >
> > > You will see what it returns.
> > >
> > > hit escape to restore the formula.
> > >
> > > See help on the Large Worksheet function in Excel.
> > >
> > > --
> > > Regards,
> > > Tom Ogilvy
> > >
> > > "steve_doc" wrote:
> > >
> > > > Thanks Tom
> > > > Works a charm
> > > > Any chance on an explanation on the code
> > > >
> > > > Steve
> > > >
> > > > "Tom Ogilvy" wrote:
> > > >
> > > > > Sub TestArrays()
> > > > > Dim iDiceRoll As Variant
> > > > > Dim i As Integer
> > > > > Randomize
> > > > > ReDim iDiceRoll(0 To 5)
> > > > > For i = 0 To 5
> > > > > iDiceRoll(i) = Int((6 * Rnd) + 1)
> > > > > Next i
> > > > > iDiceRoll = Application.Large(iDiceRoll, Array(1, 2, 3))
> > > > > For i = LBound(iDiceRoll) To UBound(iDiceRoll)
> > > > > Debug.Print i, iDiceRoll(i)
> > > > > Next
> > > > > End Sub
> > > > >
> > > > > iDiceRoll will have a lower bound of 1 after the use of Large.
> > > > >
> > > > > --
> > > > > Regards,
> > > > > Tom Ogilvy
> > > > >
> > > > >
> > > > > "steve_doc" wrote:
> > > > >
> > > > > > Hi all
> > > > > >
> > > > > > Is it possible to decrease an array?
> > > > > >
> > > > > > EG with the following Code. If I wanted to be left with the 3 highest number
> > > > > > in that array. I could add them to a Collection and remove them based on a
> > > > > > logic comparison, as 1 option. What are the other options, and are there
> > > > > > better watys of doing this?
> > > > > >
> > > > > > Sub TestArrays()
> > > > > > Dim iDiceRoll(5) As Integer
> > > > > > Dim i As Integer
> > > > > >
> > > > > > For i = 0 To 5
> > > > > > iDiceRoll(i) = ((6 * Rnd) + 1)
> > > > > > Next i
> > > > > > End Sub
> > > > > >
> > > > > >
> > > > > > Thanks in advance
> > > > > > Steve

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
decrease formula bar reginaj Microsoft Excel Misc 2 8th Dec 2008 04:14 PM
Redimming an array dynamically assigned from range (how to redim first dimension of a 2-D array? /or/ reverse the original array order) Keith R Microsoft Excel Programming 3 13th Nov 2007 04:08 PM
meaning of : IF(Switch; Average(array A, array B); array A) =?Utf-8?B?RFhBVA==?= Microsoft Excel Worksheet Functions 1 24th Oct 2006 06:11 PM
decrease for Kent Boogaart Microsoft C# .NET 4 11th Mar 2006 01:49 AM
Decrease in performance Az Windows XP Internet Explorer 3 22nd Sep 2003 10:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:39 PM.