Results 1 to 10 of 10

Thread: Next without for

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    32

    Next without for

    i have this code that i'm making a dice game with 6 dice. I can't get one command button to roll all of them. when i use this code it just gives me a compile error: NEXT witout FOR . on the NEXT inCount before picDieThree
    can someone help me

    Private Sub Command1_click()
    'Player One (Die One)
    'Definitions
    Dim intShow As Integer
    Dim intCount As Integer
    'Roll Dice
    Randomize Timer
    intShow = Int((5 * Rnd))
    For intCount = 0 To intShow
    picDieOne(intCount).ZOrder (0)
    Next intCount
    picDieTwo(intCount).ZOrder (0)
    Next intCount
    picDieThree(intCount).ZOrder (0)
    Next intCount
    picDieFour(intcout).ZOrder (0)
    Next intCount
    picDieSix(intCount).ZOrder (0)

    thanks Zayn Kalyan

  2. #2
    Addicted Member kewakl's Avatar
    Join Date
    Oct 2006
    Location
    between keyboard and chair
    Posts
    220

    Re: Next without for

    what do you want the routine to do.
    i guess that you want the for ... next loop to make the 6 dice take their ZOrder position in sequence, not simultaneously.? am i close?
    Do not use if shrinkwrap is broken or missing!
    I'm learning how to fish, too!

  3. #3
    Addicted Member kewakl's Avatar
    Join Date
    Oct 2006
    Location
    between keyboard and chair
    Posts
    220

    Re: Next without for

    do you already have the six die faces drawn? - not the actual 6 DICE, but their DOT faces
    what are the pic names for each side?
    Do not use if shrinkwrap is broken or missing!
    I'm learning how to fish, too!

  4. #4

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    32

    Re: Next without for

    i have all the sides drawn but i want them to be random i'll give you the code for how they are drawn. I do not care how the take their ZOrder postions

    [CODE]Private Sub Form_Load()
    'Initialise Dice
    frmMain.Caption = "Lucky Dice"
    'Definitions
    Dim intTop As Integer
    Dim intLeft As Integer
    Dim intRadius As Integer
    Dim intColour As Integer
    Dim intCount As Integer
    'Set Circle Settings
    intRadius = 60
    intColour = vbBlack
    'Die One
    'Set Die One Settings
    intLeft = picDieOne(0).Left
    intTop = picDieOne(0).Top
    'Setup Picture Boxes (Move, Fill and Visbility)
    For intCount = 0 To 5
    picDieOne(intCount).Left = intLeft
    picDieOne(intCount).Top = intTop
    picDieOne(intCount).FillStyle = vbFSSolid
    picDieOne(intCount).Visible = True
    picDieOne(intCount).BackColor = vbWhite
    Next intCount
    'Render Dice Patterns
    'Number One
    picDieOne(0).Circle (280, 280), intRadius, intColour
    'Number Two
    picDieOne(1).Circle (140, 120), intRadius, intColour
    picDieOne(1).Circle (400, 400), intRadius, intColour
    'Number Three
    picDieOne(2).Circle (140, 120), intRadius, intColour
    picDieOne(2).Circle (280, 280), intRadius, intColour
    picDieOne(2).Circle (440, 440), intRadius, intColour
    'Number Four
    picDieOne(3).Circle (140, 120), intRadius, intColour
    picDieOne(3).Circle (140, 440), intRadius, intColour
    picDieOne(3).Circle (440, 120), intRadius, intColour
    picDieOne(3).Circle (440, 440), intRadius, intColour
    'Number Five
    picDieOne(4).Circle (140, 120), intRadius, intColour
    picDieOne(4).Circle (140, 440), intRadius, intColour
    picDieOne(4).Circle (280, 280), intRadius, intColour
    picDieOne(4).Circle (440, 120), intRadius, intColour
    picDieOne(4).Circle (440, 440), intRadius, intColour
    'Number Six
    picDieOne(5).Circle (140, 120), intRadius, intColour
    picDieOne(5).Circle (140, 270), intRadius, intColour
    picDieOne(5).Circle (140, 440), intRadius, intColour
    picDieOne(5).Circle (440, 120), intRadius, intColour
    picDieOne(5).Circle (440, 270), intRadius, intColour
    picDieOne(5).Circle (440, 440), intRadius, intColour
    'Die Two
    'Set Die Two Settings
    intLeft = picDieTwo(0).Left
    intTop = picDieTwo(0).Top
    'Setup Picture Boxes (Move, Fill and Visbility)
    For intCount = 0 To 5
    picDieTwo(intCount).Left = intLeft
    picDieTwo(intCount).Top = intTop
    picDieTwo(intCount).FillStyle = vbFSSolid
    picDieTwo(intCount).Visible = True
    picDieTwo(intCount).BackColor = vbWhite
    Next intCount
    'Render Dice Patterns
    'Number One
    picDieTwo(0).Circle (280, 280), intRadius, intColour
    'Number Two
    picDieTwo(1).Circle (140, 120), intRadius, intColour
    picDieTwo(1).Circle (400, 400), intRadius, intColour
    'Number Three
    picDieTwo(2).Circle (140, 120), intRadius, intColour
    picDieTwo(2).Circle (280, 280), intRadius, intColour
    picDieTwo(2).Circle (440, 440), intRadius, intColour
    'Number Four
    picDieTwo(3).Circle (140, 120), intRadius, intColour
    picDieTwo(3).Circle (140, 440), intRadius, intColour
    picDieTwo(3).Circle (440, 120), intRadius, intColour
    picDieTwo(3).Circle (440, 440), intRadius, intColour
    'Number Five
    picDieTwo(4).Circle (140, 120), intRadius, intColour
    picDieTwo(4).Circle (140, 440), intRadius, intColour
    picDieTwo(4).Circle (280, 280), intRadius, intColour
    picDieTwo(4).Circle (440, 120), intRadius, intColour
    picDieTwo(4).Circle (440, 440), intRadius, intColour
    'Number Six
    picDieTwo(5).Circle (140, 120), intRadius, intColour
    picDieTwo(5).Circle (140, 270), intRadius, intColour
    picDieTwo(5).Circle (140, 440), intRadius, intColour
    picDieTwo(5).Circle (440, 120), intRadius, intColour
    picDieTwo(5).Circle (440, 270), intRadius, intColour
    picDieTwo(5).Circle (440, 440), intRadius, intColour
    'Set Die Three Settings
    intLeft = picDieThree(0).Left
    intTop = picDieThree(0).Top
    'Setup Picture Boxes (Move, Fill and Visbility)
    For intCount = 0 To 5
    picDieThree(intCount).Left = intLeft
    picDieThree(intCount).Top = intTop
    picDieThree(intCount).FillStyle = vbFSSolid
    picDieThree(intCount).Visible = True
    picDieThree(intCount).BackColor = vbWhite
    Next intCount
    'Render Dice Patterns
    'Number One
    picDieThree(0).Circle (280, 280), intRadius, intColour
    'Number Two
    picDieThree(1).Circle (140, 120), intRadius, intColour
    picDieThree(1).Circle (400, 400), intRadius, intColour
    'Number Three
    picDieThree(2).Circle (140, 120), intRadius, intColour
    picDieThree(2).Circle (280, 280), intRadius, intColour
    picDieThree(2).Circle (440, 440), intRadius, intColour
    'Number Four
    picDieThree(3).Circle (140, 120), intRadius, intColour
    picDieThree(3).Circle (140, 440), intRadius, intColour
    picDieThree(3).Circle (440, 120), intRadius, intColour
    picDieThree(3).Circle (440, 440), intRadius, intColour

  5. #5
    Addicted Member kewakl's Avatar
    Join Date
    Oct 2006
    Location
    between keyboard and chair
    Posts
    220

    Re: Next without for

    with the attached example, you can see how to assign the desired face to the desired die.

    I have picboxes for six DICE and six DIE FACES.
    click the button and the routine RaNDomly picks a die FACE to apply to a DIE.
    I included my quickly drawn die faces as .bmps because my example loads the pics as opposed to drawing the pics as your prog does.

    hopefully you can follow it. it is only 15 lines
    the For Next loops through the DICE and RND-picks a FACE.

    good luck and goodnight.

    added a .zip file for compliance with forum
    Attached Files Attached Files
    Last edited by kewakl; Apr 18th, 2007 at 10:43 PM. Reason: people here abhor RAR files
    Do not use if shrinkwrap is broken or missing!
    I'm learning how to fish, too!

  6. #6
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: Next without for

    Re: Syntax error in your first post

    vb Code:
    1. Private Sub Command1_click()
    2.  
    3.     'Player One (Die One)
    4.     'Definitions
    5.     Dim intShow As Integer
    6.     Dim intCount As Integer
    7.     'Roll Dice
    8.     Randomize Timer
    9.     intShow = Int((5 * Rnd))
    10.  
    11.     For intCount = 0 To intShow
    12.         picDieOne(intCount).ZOrder (0)
    13.     Next intCount
    14.  
    15.     picDieTwo(intCount).ZOrder (0)
    16. Next intCount '--> orphan
    17.  
    18. picDieThree(intCount).ZOrder (0)
    19. Next intCount '--> orphan
    20.  
    21. picDieFour(intcout).ZOrder (0)
    22. Next intCount '--> orphan
    23.  
    24. picDieSix(intCount).ZOrder (0)
    25.  
    26. End Sub
    The Nexts marked as 'orphan' do not have a correcponding For. Every For must have its corresponding closing Next

    Also, the For Next <Counter> format is slower. You don't need to add the counter after the Next - it will be faster.

    you can write the above code as:
    vb Code:
    1. For intCount = 0 To intShow
    2.         picDieOne(intCount).ZOrder (0)
    3.         picDieTwo(intCount).ZOrder (0)
    4.         picDieThree(intCount).ZOrder (0)
    5.         picDieFour(intcout).ZOrder (0)
    6.         picDieSix(intCount).ZOrder (0)
    7.     Next ' No counter here
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    32

    Re: Next without for

    thanks kewakl for the code
    and thanks for the .bmps

    thanks

  8. #8
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Next without for

    Quote Originally Posted by iPrank
    Also, the For Next <Counter> format is slower. You don't need to add the counter after the Next - it will be faster.
    Untrue. In compiled code there is no difference was the counter put there or not: it compiles to the exact same code both ways. For code readability it is better to put it in (and that's why we have it).

  9. #9
    Addicted Member kewakl's Avatar
    Join Date
    Oct 2006
    Location
    between keyboard and chair
    Posts
    220

    Re: Next without for

    Quote Originally Posted by a5bcap
    thanks kewakl for the code
    and thanks for the .bmps

    thanks
    you are welcome!

    there is nothing wrong with the prog drawing the images at runtime:
    the total program footprint would be smaller.
    you do not have to include images in the install.


    you could do the program without any dice pictureboxes -- they can be drawn on the form itself.

    i have a peg solitaire game that has no controls or windows except the main form. all pegs and buttons are drawn on the form.
    Do not use if shrinkwrap is broken or missing!
    I'm learning how to fish, too!

  10. #10
    Addicted Member kewakl's Avatar
    Join Date
    Oct 2006
    Location
    between keyboard and chair
    Posts
    220

    Re: Next without for

    you may have noticed that you cannot roll a '6'

    change this
    Code:
    Private Sub cmdRoll_Click()
    Dim nDieFaceVal As Integer
    Dim nDie As Integer
    For nDie = 0 To 5
        nDieFaceVal = Int((6 * Rnd))
        picDie(nDie).Picture = picDieFace(nDieFaceVal)
    Next
    End Sub
    also you can LOCK individual dice so that they will not change on a roll.
    you *can* use the .Appearance property -- if you like.
    Code:
    Private Sub cmdRoll_Click()
    .
    .
    .
        If picDie(nDie).Appearance = 0 Then picDie(nDie).Picture = picDieFace(nDieFaceVal)
    .
    .
    .
    Next
    End Sub
    and in picDie_Click
    Code:
    Private Sub picDie_Click(Index As Integer)
    If picDie(Index).Appearance = 0 Then
        picDie(Index).Appearance = 1
    Else
        picDie(Index).Appearance = 0
    End If
    End Sub
    **could not find a declaration for the vb Appearance property value.
    Do not use if shrinkwrap is broken or missing!
    I'm learning how to fish, too!

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