I need to make a program to shuffel cards, i have 81 cards and i tried assigning a random number from 1 to 81 to an array which stores the cards order. I would have it check all the other arrays to see if the number was placed, and if it was it would generate another one. Something went wrong and it made my computer crash. I have no idea how to shuffle cards, can anyone help?
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Shuffling A Deck Of Cards?
could someone help me to do this...
I Have a string var. Array with 60 different Places to hold info (It's a Type called Deck .. Ie... Deck1.Card1 = "Ace"
How Can I tell it to switch Those Randomly with out alot of fuss.. (You know shuffle the deck) maybe with a api somehow..
Playing Mp3 Or Wav With 2 Sounds Cards Using API MCI (How To Select One Of The Cards
I have two sounds cards in my system and I need to know how to select one of them to play mp3 or wav files all of this with Api mci.
I use the mciSendString Api function that I suppose you already know to play these files but i can't find a function to select one of the sounds cards and play alternately.
Any help will be appreciated. Thanks in advance.
Painting Corners Of Cards With Cards.dll
First I would like to thank all of the people who have posted answers on this forum. I use to code VB 5.0 back in college. I hadn't done any VB since 98 or so. Just stated with VB .NET 2003 a couple of weeks ago and have been searching this form all the time. Lots of my questions where answered by just searching.
My current project is a solitaire game for my dad. I wrote on in 5.0 (lost the source code) and now reduing it again in .NET a few years later. I am using cards.dll after reading this post. Everything is ok other then the fact that the corners of the cards are always white. I need to change the color of the corners depening on where the card is. I don't remember having this problem before. I believe that if I could set the corners to transparent then every thing would work fine. Does anybody know how to do that? Otherwise I will have an ugly solitare game or have to paint the corners manually.
Thanks in Advanced,
I have to make a solitare type game....but the problem is shiffling...I have these requirements.
I am Given 52 cards i order of their suits. (i.e Ace of Spades, then 2 Spades, 3, 4, 5, 6, and so on untill Hearts, Diamonds and Club.)
First I have to take N amount of cards from the Center in this case 12. So i have to remove 12 cards from the middle that is cards 20 to 31 and move these to the top of the deck then i have to take 4 cards from the center again and place them on the bottom of the deck. This has to to be repeated 4 times and i have to find out what card is on top after 4 repetitions. Help me understand this... I m trying to do it in a list box but i just can't seem o wrap my head around it.
Thanks a lot for the help in the past
'Shuffling' An Array?
I have an array: box(1 to 22)
There are 22 boxes and each box will have one of 22 different values (and only one of each).
I have been able to do this using loads of IF THEN statements (see attachment if you want to see) but am interested in doing it the quicker way.
(Yes I'm programming deal or no deal )
Help With Shuffling An Array
As part of my final project in vb 2005, I need to make an array for a deck of cards, and then shuffle the cards. My question is quite simply.... how do I do this? I know how to build the array I just dont know how to go about shuffling it. Im fairly new to vb and am very confused on what to do or even where to start. Any help would be appreciated.
3 type of card shuffling, break, in&out riffles. for a deck of 8cards.
user inputs b,i or o in box to do a shuffle...
Dim p(1 To 8) As Integer, tmp(1 To 8) As Integer, multiplier As Integer
Dim testfornumber As Boolean
Private Sub bt_go_Click()
Dim count As Integer, Char As String
For count = 1 To Len(txt_input) 'cycle through each character
Char = Mid(txt_input, count, 1) 'make char = 1 character each cycle
testfornumber = IsNumeric(Char) 'if char is a number
If testfornumber = True Then
multiplier = Char 'store the number
GoTo nxtcount 'skip the select case cos it was a number
For i = 1 To 8 'store all positions into tmp(1 to 8)
tmp(i) = p(i)
Select Case Char
For X = 1 To multiplier 'run this however many times the number before b was
For i = 1 To 8
If i = 8 Then 'dont move it to 9, put it to 1
p(8) = tmp(1)
Else: p(i) = tmp(i + 1) 'otherwise add 1
For X = 1 To multiplier
For i = 2 To 7
If i <= 4 Then
p(i) = tmp(i + (i - 1))
Else: p(i) = tmp(i - (8 - i))
For X = 1 To multiplier
For i = 1 To 8
If i <= 4 Then
p(i) = tmp(i + i) 'from i=1to4, tmp shud b (i+i) ie.p(4)=tmp(4+4=8) correct
Else: p(i) = tmp(i - (9 - i)) 'fromi=5to8, tmp is (i-(9-i) ie. p(5)=tmp(5-(9-5)=1) correct
End If 'is p(8)=tmp(8-(9-8)=1) correct
For i = 1 To 8
c(i).Left = p(i) 'reposition all labels! nice & easy grafix!!!
Private Sub bt_reset_Click()
multiplier = 1
txt_input = ""
For i = 1 To 8
p(i) = i
c(i).Left = p(i)
Private Sub btq1_Click()
Private Sub btq3_Click()
Private Sub Form_Load()
q2.ScaleMode = 0 'usermode
q2.ScaleWidth = 10 'divide form by 10
q2.ScaleHeight = 3 '& 3
multiplier = 1 'default times by 1 - makes no difference!
For i = 1 To 8
p(i) = i 'defualt positions - 1 to 8
c(i).Left = p(i) 'each .left is exactly x/10 of the form width!
c(i).Top = 2 '2/3s down the screen
I need to allow user to type in lexpressions such as
which wud do:
how do i change to allow for brackets etc.... I have tried but got nowhere!?
Shuffling An Array, EZ Way.
This is in response to something I saw in the code library... shuffling an array need not be so complicated.
Public Sub Shuffle(a() As myType)
Dim e As Long, i As Long
Dim r As Long
Dim temp As myType
e = UBound(a)
For i = LBound(a) To e-1
r = i + Int(Rnd * (1 + e - i))
temp = a(i)
a(i) = a(r)
a(r) = temp
Replace 'myType' with the type of array you are shuffling. No collections. No complicated tests to see what values have been selected. I use this function for shuffling a deck of cards but it works with anything. The distribution is normal.
Shuffling A Listbox
I am working on this strategy card game. So far, two of the people who have tried it have asked for a deck shuffling option. Now the game is limited to 50 cards in the listbox at the start of the game.
Anyone have a short and not too complicated code snippet to do this?
Sorry if my title does'nt give much information. I have written code for a quiz game. There are questions loaded into a microsoft access database. Once the user clicks the answer the next question loads, this is done via the data control. I want the program to shuffle the database uppon opening so that the records are shuffled. This is so people cannot memorise all the questions.
Listview (shuffling It Around)
I load up a text file into a listview on program load:
File = text1.text
Open App.Path & "/info.txt" For Input As 1
Do Until EOF(1)
Line Input #1, File
ListView1.ListItems.Add , , File
How can i make it so it loads this up at random? For example, say in the info.txt file "blah" is on line 1, "choc" is on line 2, and "doke" is on line 3. What i want is for line 3 to end up on a different line, and line 2 on a different one, etc.
Array Shuffling - Can It Be Done?
What I'm looking for, in brief, is a way of shuffling the entries in an array so that they are in a completely random, unpredictable order. I've tried using Rnd, but it seems to interfere with IF statements and go its own sweet way...
That just about sums it up. Thanks in advance to any willing to help.
Shuffling Script I Wrote....have Fun!!!
I just thought I'd show this code I wrote this morning to make and "shuffle" a deck of cards. This method is fool proof and has no chance of duplicating cards. It makes a deck of 52 cards and then each random card it picks is removed and added to another list until the first deck is empty and the new "random" deck is full.
Here is the script to create the random deck of cards:
Dim deck As New Collection
Dim test As New Collection
Dim B As Integer
Dim c As Integer
Private Sub Shuffle_Deck()
For i = 1 To 13
deck.Add Item:="d" & i
For i = 14 To 26
deck.Add Item:="h" & (i - 13)
For i = 27 To 39
deck.Add Item:="c" & (i - 26)
For i = 40 To 52
deck.Add Item:="s" & (i - 39)
B = 52
Dim MyCard As String
Dim a As Long
While B > 0
a = Int((B * Rnd) + 1)
MyCard = deck.Item(a)
B = B - 1
'---------everything below this line just outputs to excel to show you that it works....you can delete this section
d = 1
While d < 53
Sheet1.Cells(d, 1) = test(d)
d = d + 1
Also, here is a script I wrote to delete that deck so you can shuffle a new one:
g = test.Count
i = 1
While i < g
i = i + 1
Shuffling Contents Of A Listbox?
is this possible? im trying to make a listbox that displays a playlist of songs and i want to be able to shuffle it
any help will be very much appreciated
Shuffling Database Entrys
i have set up an videofile playlist in a access database and now would like to play them randomly but without repeats....so i better need to say i want to shuffle them
i need to also mention, that i am doing a weighted random! which means i pass an array with numbers which represents the weight of each recset!
this is the code i am using to get a random number in a defined range of numbers (beginning at 0 and ending at the total count of recsets in the database table):
Private Function WeightRandomFootage(PlayWeights() As Integer, iLBound As Integer, iUBound As Integer) As Integer
Dim RetVal As Integer, PlayLoop As Integer, TopNum As Integer, PlayNum As Integer
For PlayLoop = iLBound To iUBound
'Add up all of the weights
TopNum = TopNum + PlayWeights(PlayLoop)
'Pick a random integer in the range one to that total
PlayNum = Int(TopNum * Rnd + 1)
TopNum = 0
For PlayLoop = iLBound To iUBound
TopNum = TopNum + PlayWeights(PlayLoop)
If PlayWeights(PlayLoop) > 0 Then
'Count forward till the weightings equal or exceed the random value
If TopNum >= PlayNum Then
If PlayLoop = PastRandomNoFootage Then
'we have the biased random result so jump out of the loop
RetVal = PlayLoop
'PastRandomNoFootage is a public var which i made to prevend to get the same number two times in a row !
PastRandomNoFootage = RetVal
i then use the returned number to move to a random recset!
how can i prevent to get the same number twice, triple or more??
i know i would need to setup some kind of array to sort the recsets out that already have been randomy choosed...but how?
thx & greets
Card Shuffling And IsArray
I don't understand IsArray and I'm not sure how to call a function properly. I found the following function for shuffling cards at this thread. isArray always returns false. If you can, please help me get started. Basically I want to shuffle cards that have baseball results. Here's a low down of what the card types will eventually be: 9 out (cards), 4 strikeouts, 3 walks, 5 extra base hits, 3 singles
Dim X As Integer
Private Sub Form_Load()
For X = 1 To 24
carddeck = Int(24 * Rnd) + 1 '1 to 24
aData(X) = carddeck
'function from ExtremeVBForum
Private Function ShuffleArray(aData As Variant) As Boolean
'shuffles array adata. Returns true unless there is a problem
Dim max As Long
Dim i As Long, j As Long, v As Variant
If IsArray(aData) Then
max = UBound(aData)
For i = max To 1 Step -1
j = Int(Rnd() * (i + 1)) 'pick one to switch
If i <> j Then
v = aData(i)
aData(i) = aData(j)
aData(j) = v
ShuffleArray = True
Card Shuffling [SOLVED]
How would one go about shuffling an array of 40 integers? I've tried several examples, but either I'm not doing them properly or they just don't work.
BTW: I'm not doing this directly within the form, but from inside a class module... I'm trying to do as little in-form coding as possible, in the hopes that it might make my programs run a little faster.
Card Shuffling (Full Deck)
I've got a 52 card deck each card is a image control named imgcard(0)....
And i have this code to shuffle it but i know i'm doing something wrong but cn't figure out what:
Private Sub Form_Load()
imgDeal2.Picture = imgBack.Picture
Dim i As Integer, p As Integer, t As Integer
Cards = Array(imgCard(0).Picture, imgCard(1).Picture)
For i = 0 To 51: CardSel(i) = i: Next 'initialize the array
'to hold the number 0 to 5
'Now scramble the order of numbers in the array
For i = 51 To 0 Step -1
p = Int(i * Rnd)
t = CardSel(i)
CardSel(i) = CardSel(p)
CardSel(p) = t
Rnd Used For Dice Throws & Card Shuffling.
Does anybody know of a pseudo random number generator and/or algorithm suitable for the following?
I recently developed a Visual Basic application which simulates Casino Craps (Dice) and simulates dealing from a 52 card deck. The application does only a fair job with the dice, and does a poor job with the cards.
I used the standard pseudo random number generator provided by VB. See code below for shuffling algorithm.
The results were interesting.
The Dice throwing simulation got the following results after about 10 million pass line bets (about 34 million dice throws).Each die simulation indicated the correct probabilities to about 5 digits of precision. True probability for each digit is 1/6 (.1666666666 . . .). Simulation indicated .16666xx for most numbers.The simulated totals were precise to about 5-6 digits.The probabilities of making various points were precise to slightly less than 3 digits.The overall probability of winning a pass line bet was wrong in the third digit.
True probability: .4929292929 . . . Simulated probability: .4937xxxxThe above results seemed to have stabilized after 3-5 millions pass line bets, not getting more precise as the number of dice throws increased.
The above suggests that the pseudo random number generator did a good, but not excellent job of simulating dice throw probabilities. If it was excellent, the precision would continue to improve as the number of throws increased. It did a poor job of simulating the overall probability of wining a pass line bet.
BTW: I wrote a similar application many years ago using a different version of the Basic language. That simulation indicated that the player should expect to beat the casino, due to bad simulation of the probabilities of making a point. For that simulation, the other simulated probabilities were fairly good. Apparently, the Rnd Function was improved significantly some time in the past 10-15 years.
Making a point requires throwing a particular total before throwing a seven. Although the simulated frequencies for the various totals are fairly precise, the simulated probabilities of making a point are poor. It is like a trick question about train schedules for which the less likely event is very likely to occur first, due to unexpected clustering.
Suppose there are ten trains each hour from Philadelphia to New York and only one train per hour from Philadelphia to Washington. Now suppose that the New York trains leave every minute starting on the hour, while the single Washington train leaves at one minute before each hour. If you arrive at a random time, the next train to leave is far more likely to be a Washington train than a New York train.
Probability, random number generation, and simulations are fraught with subtleties, which are counter intuitive.
The card dealing simulation was only precise to about 3 digits. This application simulated the dealing of 5-card poker hands & 13 card bridge hands. It also simulated drawing a single card from a 52 card deck. The Visual Basic pseudo random number generator does not do a good job of simulating the dealing of cards. Perhaps using the Rnd Function in a different manner might help.
Private Sub Shuffler()Dim J As IntegerDim K As IntegerDim ThisCard As Integer For J = 0 To 51 'Make pseudo random swaps in array of 52 cards. ThisCard = Card(J) K = Int(Rnd * 52) Card(J) = Card(K) Card(K) = ThisCard Next J For J = 51 To 0 Step -1 'Backwards in case Rnd is biased toward either high or low values. ThisCard = Card(J) K = Int(Rnd * 52) Card(J) = Card(K) Card(K) = ThisCard Next J End Sub
Note there is a nonzero probability (1/52 ?) of any particular card staying in the same place in the deck. This suggests that for most shuffles at least one card stays in the same place. I do not think this is a serious problem.
Shuffling Blocks Of Text Might Be An Easy One
I teach school and I have a test that is in the form of a word document. The formating is complicated enough so that I can't really just cut and paste it into excel or anything. The questions are multiple choice an are in this format:
4. Which of the following is NOT a valid filename?
5. A folder is the same as a directory. (T/F)
6. Windows considers the file names "MYDATA.TXT" and "mydata.txt" to be identical. (T/F)
They vary back and forth from multiple choice and True and False. I am looking to write a macros that will shuffle these questions. There are 150 of these bad boys and I really don't feel like cutting and pasting all night. I would love any suggestions that may come my way. I thought about putting them all in textboxes but I program mostly in VB and not VBA. I wouldn't know how to access the textbox's index so that they could be shuffled.
Class Module For Shuffling An Array
am a newbie to this site n i want to offer whatever little help i can to fellowcoders. here's a small class module to shuffle the elements of an array. this class module comes in handy when you have a problem of shuffling the elements of an array and wish to save some time.
i know many of you know many a better ways of doing such things and i would certainly like to know about them too.
plzz reply about it.
Array Shuffling - Help Refining Code For Custom-type Arrays?
Ok, here's my problem. A while back I posted a query concerning Array Shuffling to squish a particularly persistent bug, and received a few good ideas (thanks again to all who helped).
Unfortunately, the bug still exists despite these ideas. Against all reason and in direct violation of more than one If statement, the bug exists. So I surfed the net for more information on Array Shuffling and ran across something pretty interesting.
This is where I get technical. I'm using a custom type array and am trying to shuffle it. Custom type arrays are declared through a specific Type statement, and allow you to combine several lists in one array, just like a standard two-dimensional array. The great thing about them, however, is that these do not have to be all integer, all text etc., saving the need for running different two-dimensional arrays by type and align them so that they function as one. But then you probably knew that.
This code is not mine. According to freeVBcode.com, this code was created by the featured developer Intelligent Solutions Inc, and if this is incorrect then my source is.
'PURPOSE OF CODE:
'TO RANDOMLY SHUFFLE CONTENTS OF AN ARRAY
'Array Type and size does not matter
'same technique can be used for arrays of different sizes/types
Dim iArray(200) As Integer 'array to be randomly shuffled
'for demo purposes only
Dim iTempArray(200) As Integer 'copy of the array
Dim iCtr As Integer
Dim iCtr2 As Integer
Dim iTemp As Integer
Dim iMaxElement As Integer
Dim iMinElement As Integer
'Populate array and Temp Copy for
For iCtr = 0 To 200
iArray(iCtr) = iCtr
iTempArray(iCtr) = iCtr
'iTempArray is an array to hold
'original values. you must duplicate the orignal
'array for this technique to work
'this is the technique
Dim bArray() As Boolean
iMaxElement = UBound(iArray)
iMinElement = LBound(iArray)
ReDim bArray(iMinElement To iMaxElement) As Boolean
For iCtr = iMinElement To iMaxElement
iTemp = Int((iMaxElement - iMinElement + 1) * Rnd) + _
If bArray(iTemp) = False Then
iArray(iTemp) = iTempArray(iCtr)
bArray(iTemp) = True
'just a test to prove that it worked
For iCtr = iMinElement To iMaxElement
I can pretty much see how this works, but I'm not sure how to adapt this for a custom array. (I'll not bore you with details of the array - I reason that a custom array of type 'Custom', which contains - the type, that is - 'Number' and 'String' will do for example purposes.)
Any help would be appreciated. This bug must die!!
TCG With X No. Of Cards
Im trying to make a TCG (card game), I was wondering how you could show each card you hold in your hand without using a picture box per card?
The number of cards in hand is usually 7 but can be unlimited sometimes.
The card must be able to disappear (discard/removed), if possible: drag & drop and rotate 90 degrees.
Currently I have 2 pictureboxes (per card) representing the card and a image on the card.
Oh, and this game has lots of different card that affects the game, is it a better idea to code each effect or write every possible parts of each effect and call what the effect uses up?
Thanks in advance
how would i call up a card (doesnt matter which, we'll use Ace of Spades) into an image control using Cards.DLL (its filename its c:windowscards.dll, and we can assume the image is named image1)
I've heard that there's some dll file that I can access with all of the card images and stuff in it. Where do I learn how to call this file and use the cards in it?
The more I C, the less I see.
Using Vb Cards
I have just started using vb cards for visual basic 6.0 and I am having great difficulties with it is there a website or anything that can help me work with them?
I'm trying to make a card game with home made cards. I've seen cards.dll of windows and it is very handy. How can i make a DLL with my own cards (so the dll must include picture and some data of a card) can someone give me a starter or a tutorial about this ?
Does anyone have any info on the file cards.dll that used to (and might still) come with Windows for all the card games that come with Windows like Solitaire? Is it possible to use that dll in my card programs?
Im using the same version of cards.dll on two different computers. My home computer which uses windows XP displays the cards correctly on screen for my blackjack game. The machine in school which I copied cards from my machine to so it would be the same version only displays 4 small dots, when on mine it would display a card, The other computer is in school but I don't see why it is not working as my code is the exact same?
Out team is looking at doing ID cards for our customers. We want them to look like an insurance card or driver license without the picture. Any ideas of software or any tools that do this?
Can anybody tell me where i can find the functions in Cards.dll... I wish to make a game using Cards.
Also can anybody give some tips for Card Game Programming.. ?
HI, I'm making card playing game.
Where I gen get all playing cards pictures?
PS. Sorry that this is not programing question.
Printing Id Cards
I need help with printing business cards through an application that i'm developing. I use standard business card paper. Basically, i use an ActiveX control which has the size of a business card, and i need to be able to a) preview the card and b) be able to print it on any location on the paper.
Any help on this would be greatly appreciated.
I got 52 images, I want to shuffle then like a playing card.
does any body know how to do this on vb?
I am trying to create a small flash card game for children to use. I was just wondering if anyone might have any previous experience with something like this? If so, what did you use as a card? Like, did you create the card from a actual image or did you just like make it out of a text box or something else?
Vb6 And Audio Cards...
I'm wondering if you might know of anyway in VB6 to direct audio such as wave files to a different audio card. In other words, if I install a 2nd audio card in the PC is there a way through VB6 to direct audio to it and not the default card?
Problem With Cards.dll
im having a problem using cards.dll when ever i minimize the screen the cards i have drawn onto the screen will disappear ???
what's wrong with this code (i keep getting Error 49, which says Bad DLL Calling Convention)
Private Declare Function cdtInit Lib "Cards32.Dll" (dx As Long, dy As Long) As Long
Private Declare Function cdtDrawExt Lib "Cards32.Dll" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal dx As Long, ByVal dy As Long, ByVal ordCard As Long, ByVal iDraw As Long, ByVal clr As Long) As Long
Private Declare Function cdtDraw Lib "Cards32.Dll" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal iCard As Long, ByVal iDraw As Long, ByVal clr As Long) As Long
Private Declare Function cdtTerm Lib "Cards32.Dll" () As Long
Private Sub Command1_Click()
cdtDrawExt Me.hdc, 200, 200, 100, 100, 0, 0, vbWhite
How could I contstuct an array of 52 playing cards so that either the suits or the numbers of each card could be compared? All help welcome, thanks.
MCI And Sound Cards
Does anyone know how to play mp3 with Window Media Player (MCI-OCX) on different sound card.
I have 2 sound cards and I want to be able to switch between them.
Has anyone ever successfully interfaced with a smartcard reader/writer? So far, all I can find is SDK's for c++ and JAVA, nothing for VB, and a search here doesn't show the info I am looking for. If anyone has ever done this before, or knows more about this, please share your experience. Links to some products that are compatible with VB are welcome too. Thanks
Generate Cards Help
i need to figure out how to genereate a deck of 52 cards, this is quite simple, simply do rnd 52 times, the trick is i can only have 4 of each number. can sum1 gimme a hint? thx
I have a richtext box.Now i want to find the string by regular expression.The cursor has to move from charcter by charcter when Findnext button is clicked.How can I?
Does anyone know how to clear cards off a form which have been dealt using cards.dll?, like in my game of blackjack when I click deal for a new game the cards which I recieved from hits still stay on the screen is there any whay of clearing these off when I click deal?
Could anybody there to tell me "How to find out the type of chip embedded on the Smart Card" like SLE4428, SLE4442, ACOS1, ACOS2 etc.
Does any one have (from a previous or current project) or know where to get all 52 playing cards, like those of the game solitaire, i need them for a game i am making.
Dissapearing Cards ?
Hi, in my blackjack game I have everythin working fine and dandy now, thnaks but I need screen shots but evrytime a window appears over the card it will dissapear or if i minimise the window the cards will dissapear, this makes it a pain when trying to use print screen, is there any way 2 make the cards stop dissapearing??
Array With Cards?
I have a list of pocket cards for texas hold em with rank from 1 to 169, i want the user to enter his cards, for instance AA or AKs, where s means suited then the program tells if its in the top 25 hands, top 50, top 75 etc. I was thinking of doing it with an array and getting the vallue of myArray(AKs) then if its greater then 25 that label goes green, if not it goes red. Am I on the right track?