CardTrick: Comments by Steve Garman
The starting entry for this blog included reference to a simple RB CardTrick program utilizing the Windows Cards.dll file. (See http://snurl.com/inwc for the entry. The CardTrick discussion is the second part of the entry.))
In response, Steve Garman sent some useful comments. With his permission, I'm placing them here for your benefit:
Steve Garman wrote:
> Barry,
>
> I just downloaded your cardtrick program from your new windows blog.
>
> It's great to see it, the trick takes me back nearly 50 years.
>
> I hope you won't be offended but I've got a couple of suggestions.
>
> Firstly, are you aware that to dimension an array of 52 elements (0 to 51)
> Dim cards(51)
> is sufficient ?
>
> Also, did you know that RB arrays have a very efficient Shuffle method so
> your whole ShuffleCards routine could be:
> Dim i As Integer
> For i = 0 To 51
> n(i) = i
> Next i
> n.Shuffle
>
> I also have some suggetions for shortening PrepareToRedeal
> I would write it something like this.
>
> Dim i As Integer
> Dim NewArrangement(26) As Integer
>
> If WhichTime = 1 Then
> CardLocation = ColumnChosen - 1
> lblInstructions.Text = "Tell me what column your card is in now."
> ElseIf WhichTime = 2 Then
> CardLocation = CardLocation + 3 * (ColumnChosen - 1)
> lblInstructions.Text = _
> "Last time: Tell me what column your card is in."
> ElseIf WhichTime = 3 Then
> CardLocation = CardLocation + 9 * (ColumnChosen - 1)
> lblInstructions.Text = ""
> End If
>
> For i = 0 To 8
> NewArrangement(i) = n(i*3)
> NewArrangement(i+9) = n(i*3+1)
> NewArrangement(i+18) = n(i*3+2)
> Next i
>
> For i = 0 To 26
> n(i) = NewArrangement(I)
> Next i
>
> Regards,
> Steve
>
Thanks, Steve, for the comments!
Barry Traver
Home Page for This Blog: http://traverrbw.blogspot.com/
Programs and Files Discussed in the Blog: http://traver.org/traverrbw/
0 Comments:
Post a Comment
<< Home