Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Sep 2002
    Location
    Stafford, Staffordshire, England
    Posts
    585
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Application Defined Error (2003)

    <img src=/S/hello.gif border=0 alt=hello width=25 height=29> and <img src=/S/help.gif border=0 alt=help width=23 height=15>

    I am playing around with the creation of a very simple version of Connect 4, namely, Connect 3. All seems well until a win is established which then throws up an error for which I can see no reason. Would someone look at the attached file and offer some explanation or even improvement.
    TIA
    Attached Files Attached Files
    <font color=blue><font face="Script MT Bold"><big>Rob</big></font face=script></font color=blue>

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Application Defined Error (2003)

    When someone wins, you call Reset. This makes A1 the active cell. After that, the code of CheckWin continues with the next test, but since A1 is now the active cell, ActiveCell(-1, 0) is not valid - it would be in row 0!

    The solution is either (1) to insert a line Exit Sub after each call to Reset, or (2) to use a series of ElseIfs:

    (1)

    If ActiveCell.Interior.ColorIndex = 5 And ActiveCell.Offset(-1, 1).Interior.ColorIndex = 5 And _
    ActiveCell.Offset(-2, 2).Interior.ColorIndex = 5 Then
    MsgBox "Blue wins!"
    reset
    Exit Sub
    End If

    or

    (2)

    If ActiveCell.Interior.ColorIndex = 5 And ActiveCell.Offset(-1, 1).Interior.ColorIndex = 5 And _
    ActiveCell.Offset(-2, 2).Interior.ColorIndex = 5 Then
    MsgBox ("Blue wins!")
    reset
    ElseIf ActiveCell.Interior.ColorIndex = 5 And ActiveCell.Offset(-1, 0).Interior.ColorIndex = 5 And _
    ActiveCell.Offset(-2, 0).Interior.ColorIndex = 5 Then
    ...

  3. #3
    4 Star Lounger
    Join Date
    Sep 2002
    Location
    Stafford, Staffordshire, England
    Posts
    585
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Application Defined Error (2003)

    <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>
    <font color=blue><font face="Script MT Bold"><big>Rob</big></font face=script></font color=blue>

Posting Permissions

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