VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 300,495 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,846 people online right now. Registration is fast and FREE... Join Now!




Jumping To Next Batch

 

Jumping To Next Batch

midofimasr

19 Nov, 2008 - 02:37 PM
Post #1

D.I.C Head
**

Joined: 21 Oct, 2008
Posts: 68

Alright, so here i have code for a program that firstly, makes a list of random numbers (52) then sorts them in ascending order. At the same time, i have a card deck. Everytime the numbers are sorted, it also changes the corresponding card in the deck. This simulates shuffling of cards. Now, i want to deal these cards out into 4 hands, but i need like a formula or something to get it to not deal out the same cards everytime. LET ME KNOW WHAT I COULD DO! Here is the code for the DEALING part. Now it only deals from 1 to 4 but how do i get it to go on to 13?

CODE

    Sub deal()
dim i as integer        
Dim j As Integer
        For j = 1 To 13
            For i = 1 To 4
                hand1(j) = carddeck(j)
                hand2(j) = carddeck(j)
                hand3(j) = carddeck(j)
                hand4(j) = carddeck(j)
            Next
        Next
    End Sub
End Module


This post has been edited by midofimasr: 19 Nov, 2008 - 02:39 PM

User is offlineProfile CardPM
+Quote Post


magicmonkey

RE: Jumping To Next Batch

19 Nov, 2008 - 06:05 PM
Post #2

D.I.C Regular
***

Joined: 12 Sep, 2008
Posts: 484



Thanked: 97 times
My Contributions
I think you want this...

*Note: you keep using 1 as the lower bound of your arrays, this is wrong 0 is the lower bound.

vb

Sub deal()
Dim i as integer = 0
Dim j As Integer
For j = 0 To 12 '0 to 12 is 13 elements in the array
hand1(j) = carddeck(i)
hand2(j) = carddeck(i + 1)
hand3(j) = carddeck(i + 2)
hand4(j) = carddeck(i + 3)
i = i + 4
Next
End Sub

User is offlineProfile CardPM
+Quote Post

midofimasr

RE: Jumping To Next Batch

19 Nov, 2008 - 06:52 PM
Post #3

D.I.C Head
**

Joined: 21 Oct, 2008
Posts: 68

Hey,
Thanks . but im getting INDEX WAS OUT OF THE BOUNDRIES OF THE ARRAY. This is poiting to line "Dim j As Integer = 0" but if i take off the "0" then it points to line "For j = 0 To 12" i think this is because when it goes to add 3 to i it cant because i passes the 12. LET ME KNOW how to fix this!!
THANKS AGAIN ALL!
User is offlineProfile CardPM
+Quote Post

magicmonkey

RE: Jumping To Next Batch

19 Nov, 2008 - 09:52 PM
Post #4

D.I.C Regular
***

Joined: 12 Sep, 2008
Posts: 484



Thanked: 97 times
My Contributions
How are you declaring hand and carddeck? They should be... if not you need to show more code.

CODE

Dim hand1(12) as integer '13 elements
...
Dim carddeck(51) as integer '52 elements

User is offlineProfile CardPM
+Quote Post

midofimasr

RE: Jumping To Next Batch

23 Nov, 2008 - 10:02 AM
Post #5

D.I.C Head
**

Joined: 21 Oct, 2008
Posts: 68

Hey, so i showed this to my teacher and he said its good, but that i should change it. He gave me a hint of STEP 4. I think he siad something about not needing 2 variables.
Let me know what i could do, to incorperate STEP 4 !!
User is offlineProfile CardPM
+Quote Post

AdamSpeight2008

RE: Jumping To Next Batch

23 Nov, 2008 - 11:02 AM
Post #6

The Bandido Coder
Group Icon

Joined: 29 May, 2008
Posts: 2,686



Thanked: 155 times
Dream Kudos: 3925
Expert In: vb.net, LINQ

My Contributions
Here's one way.
vb

Sub deal()
For j As Integer = 0 To 12 '0 to 12 is 13 elements in the array
hand1(j) = carddeck(j * 4 + 0)
hand2(j) = carddeck(j * 4 + 1)
hand3(j) = carddeck(j * 4 + 2)
hand4(j) = carddeck(j * 4 + 3)
Next
End Sub

They possibly mean this way.
vb

Sub deal()
For j As Integer = 0 To 48 step 4'0 to 12 is 13 elements in the array
hand1(j/4) = carddeck(j + 0)
hand2(j/4) = carddeck(j + 1)
hand3(j/4) = carddeck(j + 2)
hand4(j/4) = carddeck(j + 3)
Next
End Sub

I prefer the first way cos it doesn't use division (Can be slow depending on the Instruction Set of the CPU)

This post has been edited by AdamSpeight2008: 23 Nov, 2008 - 11:07 AM
User is offlineProfile CardPM
+Quote Post

midofimasr

RE: Jumping To Next Batch

26 Nov, 2008 - 07:53 AM
Post #7

D.I.C Head
**

Joined: 21 Oct, 2008
Posts: 68

Hey, im always confused on how to get it to print to the screen the hands
could someone please explain that to me? How would i write the code so t hat it prints to the screen the hands
User is offlineProfile CardPM
+Quote Post

midofimasr

RE: Jumping To Next Batch

26 Nov, 2008 - 02:06 PM
Post #8

D.I.C Head
**

Joined: 21 Oct, 2008
Posts: 68

Hey, actully, ive figured out the post about how to print it tout. BUT BUT!!
i have something else i wanted to do:
So this is my first time working with WINDOWS APPLICATIONS. I want to take my code (which is pretty much, shuffled cards that are dealed into 4 hands) and i want to create a windows application where i have 4 textboxes and a button and when the button is clicked it deals the cards into each text box. I know how to get texboxes and butons onto the forum i just dont know how to tranfer my code from a console app into a windows app
THANKS ALL FOR THE HELP!
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 04:51AM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month