Results 1 to 22 of 22

Thread: [RESOLVED] Weird crash

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    160

    Resolved [RESOLVED] Weird crash

    Ok i finished making Tic-Tac-Toe yesterday in VB just for the fun of it so today i am making blackjack but ran into a weird problem... i made a function to return an integer between 1 and 52, but also excluding all other cards that have been played. here it is:

    VB Code:
    1. Private Function RndCard() As Integer
    2. lop:
    3.     RndCard = Rnd * 52
    4.     If RndCard = 0 Then
    5.         GoTo lop
    6.     ElseIf RndCard = D1 Then
    7.         GoTo lop
    8.     ElseIf RndCard = D2 Then
    9.         GoTo lop
    10.     ElseIf RndCard = D3 Then
    11.         GoTo lop
    12.     ElseIf RndCard = D4 Then
    13.         GoTo lop
    14.     ElseIf RndCard = D5 Then
    15.         GoTo lop
    16.     ElseIf RndCard = P1 Then
    17.         GoTo lop
    18.     ElseIf RndCard = P2 Then
    19.         GoTo lop
    20.     ElseIf RndCard = P3 Then
    21.         GoTo lop
    22.     ElseIf RndCard = P4 Then
    23.         GoTo lop
    24.     ElseIf RndCard = P5 Then
    25.         GoTo lop
    26.     End If
    27. End Function

    this works but what i initially tried to do was this

    VB Code:
    1. Private Function RndCard() As Integer
    2. lop:
    3.     RndCard = Rnd * 52
    4.     If RndCard = 0 Or D1 Or D2 Or D3 Or D4 Or D5 Or P1 Or P2 Or P3 Or P4 Or P5 Then
    5.         GoTo lop
    6.     End If
    7. End Function

    but forsome reason when i used my test button to display RndCard on a label it crashed every time, after i put an elseif before them all it worked, but i just dont understand why the other way kept crashing me.

    any answers would be much appreciated
    Last edited by Cruncher; Feb 12th, 2009 at 06:34 AM.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Weird crash

    What does "crashed" mean?

    What was the error and what specific line of code caused it?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    160

    Re: Weird crash

    It didnt give me an error it simply crashed visual basic alltogether and i have to reopen it...

  4. #4
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    Re: Weird crash

    Your syntax turned the "or" into a bitwise operator. If you want to do a comparison your syntax should have been

    Code:
    if (RndCard = 0 Or RndCard = D1 Or RndCard =D2 Or RndCard =D3 Or RndCard =D4 Or RndCard =D5 Or RndCard =P1 Or RndCard =P2 Or RndCard =P3 Or RndCard =P4 Or RndCard =P5 ) then
    but that's a mess.

    Try doing a shuffle of array instead of random when using card games.
    Kinda like this:
    Code:
    Dim rand(1 To 52) As Integer
    Dim x As Integer, i As Integer, j As Integer
    
    'load the deck
    For i = 1 To 52
    rand(i) = i
    Next
    
    'shuffle
    For i = 1 To 52
        x = Int(Rnd() * 52) + 1
        j = rand(i)
        rand(i) = rand(x)
        rand(x) = j
    Next
    
    'shuffle again
    For i = 1 To 52
        x = Int(Rnd() * 52) + 1
        j = rand(i)
        rand(i) = rand(x)
        rand(x) = j
    Next
    Now you can go down the deck in order 'til you reach the end. Just like a real deck of cards.
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    160

    Re: Weird crash

    Thank you very much...

    I will try that after school, but i have to go right now:P

  6. #6
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    Re: [RESOLVED] Weird crash

    I'm responding to the following PM in the forum so I can add an attachment and I thought it might help others.

    Originally Posted by Cruncher
    Heyy yesterday you responded to my problem go to http://www.vbforums.com/showthread.p...&is_resolved=1 for referance

    you gave me some code that loads and shuffles a deck, but when i tried using it i couldnt figure it out, could you possibly tell me how i get a card from the top of the deck

    thanks
    Please check out the attached code it will answer everything. Click on the card box to deal a card!

    the key is in this part of the code
    Code:
    Image1(Index).Picture = cards(rand(currentCard))
    rand's indexed value is the true card value. This form of referencing is called Indirect Indexed. Basically you are pointing to a pointer.

    This looks like the start of a draw poker game but it's just an example - no underlying game.

    Also, let me give credit where credit is due, the free card images are downloaded from http://www.jfitz.com/cards/
    Attached Files Attached Files
    Last edited by technorobbo; May 3rd, 2009 at 09:02 PM.
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    160

    Re: [RESOLVED] Weird crash

    Thank but uhh, when u used the case for it to load pictures (dont understand how that works really) but you must of had them in a ifferant location on your computer because im getting an error as soon as i try to run and its in the code where it looks for the pictures, its a command ive never used so i dont know how to fix it. in case you dont see this ill quote it in a pm too

  8. #8
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    Re: [RESOLVED] Weird crash

    Quote Originally Posted by Cruncher
    Thank but uhh, when u used the case for it to load pictures (dont understand how that works really) but you must of had them in a ifferant location on your computer because im getting an error as soon as i try to run and its in the code where it looks for the pictures, its a command ive never used so i dont know how to fix it. in case you dont see this ill quote it in a pm too
    3 Questions
    1. what command does vb highlight when the error appears
    2. Does the exec work?
    3. What error is reported


    I use the app.path for the directory so it looks for the location where the project was loaded from. So my thinking is that OLE automation is not checked in your references. Make sure it is, it's required for the stdpicture object.
    Last edited by technorobbo; Feb 17th, 2009 at 03:12 PM.
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    160

    Re: [RESOLVED] Weird crash

    i got it working, and yes the exe always worked, its because i didnt extract it, forgot that vb couldnt read archived images, but when i tried to use this i looked at your line that said

    Image1(i).Picture = LoadPicture()

    so i used

    imgD1.Picture = LoadPicture() (not using an array because i dont like them)

    i copied what you have for form load and all ur variables and everything, and when i click deal it doesnt load any picture

    EDIT: just to clarify, there is no run-time error, this is simply a logic error, i can usually debug logic errors pretty good, but since im using foreign code I dont understand why.

    EDIT2: figured it out

    1 more problem, i think this should be the last one now, how do i get it to recognize all the cards and how many points they are worth, i noticed when you load the form you have case 1 to 10 and that kinda stuff is there a way i can use that to easily determine how many points each card is worth?
    Last edited by Cruncher; Feb 18th, 2009 at 03:44 PM.

  10. #10
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    Re: [RESOLVED] Weird crash

    That's where the array comes into play.
    With a 1 to 52 array you can divide the index by 12 and find out its value and suit!!! It goes something like this
    Code:
    cardval=(index-1) mod 13
    suit=int((index-1)/13)
    cardval would then yield a number between 0 and 12 (zero being ace and 12 king)

    suit would yield a value between 0 and 3 (0=spades,1=hearts,2=clubs,3=diamonds)

    You may want to put the cards index in the picturebox tag property to easily identify it.

    You see theres a method to this array madness.
    Last edited by technorobbo; Feb 18th, 2009 at 05:11 PM.
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    160

    Re: [RESOLVED] Weird crash

    wowow you totally lost me lol

    do you have some sort of IM? so i can talk to you about this 1 on 1 in real time to help me understand? thanks pm me

  12. #12
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    Re: [RESOLVED] Weird crash

    Ok, in order to explain what I just said - I' modified the code in post six to include text boxes above the cards that tell you exactly what the card is.
    Here's a link to that upload http://www.vbforums.com/attachment.p...8&d=1235010588
    explanation:
    The tag property of an object is the programers storage space that let's him(her) store a value within that control. In this case I stored the cards value (1 thru 52) in the picturebox's tag property.

    Using the code I described in my last post I name the cards as I deal them (see code below)
    "x = Image1(index).Tag" retrieves the code I stored in the tag
    "cardvalue = (x - 1) Mod 13" looks for the remainder of a division by the number 13. Basically it loops every 13 numbers but since it's a remainder it never gets to 13 so the results is always 0 thru 12.
    "suit = Int((x - 1) / 13)" divides by thirteen and get the whole number answer. the results are 0 thru 3. this gives me the suits because the cards are organized in order of suits.

    the choose function takes these results and assigns text to them.
    You can use the cardvalue to do your blackjack math just add 1 to the number first because ace is zero (math drives that). and anything over 10 make it 10. you can use "Choose" function to do all that.


    Code:
    Private Sub NameCard(index As Integer)
    Dim x As Integer, cardvalue As Integer, suit As Integer
    x = Image1(index).Tag
    cardvalue = (x - 1) Mod 13
    suit = Int((x - 1) / 13)
    Text1(index) = Choose(cardvalue + 1, "Ace", 2, 3, 4, 5, 6, 7, 8, 9, 10, "Jack", "Queen", "King") _
        & " of " & Choose(suit + 1, "Spades", "Clubs", "Hearts", "Diamonds")
    
    End Sub
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    160

    Re: [RESOLVED] Weird crash

    I attached what i managed to make with your help, some of the code is identical to what you gave me, but i had to write lots new code and revise a lot of what you gave me to fit my needs,

    if you could tell me what you think of my code that would be cool (Im starting to figure out this array stuff)

    EDIT: attachment removed look further down.
    Last edited by Cruncher; Feb 20th, 2009 at 08:20 PM.

  14. #14
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    Re: [RESOLVED] Weird crash

    It's awesome! I got carried away playing it. Nice job. Just add the cash, splittting and doubling down and you got a winner.
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    160

    Re: [RESOLVED] Weird crash

    K, ill do that by the way i was wondering, how can i make the dealer pause between each card he plays, like whats the line of code to make visual basic stop running for 1 seconds then continue?

    thanks in advance

    Cruncher

  16. #16
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    Re: [RESOLVED] Weird crash

    Put this in a form and test.

    Code:
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    
    Private Sub Form_Load()
    
    Me.Show
    MsgBox "I'll be back in 5 seconds"
    
    Sleep 5000 '5 second delay
    MsgBox "I'm Back!"
    
    End Sub
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    160

    Re: [RESOLVED] Weird crash

    tried that one, didnt work right it glitched my cover card...

    i found this on the internet and it works:

    Public Sub Pause(NbSec As Single)
    Dim Finish As Single
    Finish = Timer + NbSec
    DoEvents
    Do Until Timer >= Finish
    Loop
    End Sub

  18. #18
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    Re: [RESOLVED] Weird crash

    try doevents before the sleep command to flush the windows message queue
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    160

    Re: [RESOLVED] Weird crash

    ill stick with what i have, uhm for a small thing is there an operator for doesnt equal 0? for instance at the end of the hit buttons code i want to put a line that makes it so if i have played 5 cards without busting, regardless of my points you win, so i need it when a(9) (which is the last card) doesnt not equal 0 (this means that its not blank) then i win.

    thanks in advance

    cruncher

    EDIT: nvm its <>
    Last edited by Cruncher; Feb 20th, 2009 at 04:30 PM.

  20. #20
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    Re: [RESOLVED] Weird crash

    actually zero means false :

    Code:
    x = 0
    If x Then
       MsgBox "x is not zero"
    Else
       MsgBox "x is zero"
    End If
    Last edited by technorobbo; Feb 20th, 2009 at 07:24 PM.
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    160

    Re: [RESOLVED] Weird crash

    OK, im gonna wrap this project up, i did everything except for the split, i am going to upload it for reference for anyone if they wanna look at it... my brother suggested that i make Yahtzee should be fun.

    Cruncher
    Attached Files Attached Files

  22. #22
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    Re: [RESOLVED] Weird crash

    Post it in the Game Demos forum so it doesn't get lost with the old threads.
    http://www.vbforums.com/forumdisplay.php?f=63
    Just tried it. Really smooth. Good Game play.

    and good luck with Yahtzee.
    Last edited by technorobbo; Feb 20th, 2009 at 10:04 PM.
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width