"Invalid procedure call..." on "txtDim(0).SetFocus" 
Author Message
 "Invalid procedure call..." on "txtDim(0).SetFocus"

I'm having the damnedest time trying to resolve a compile time error
in some code I'm working on.

I'm getting the following error:

    Runtime error '5'
    Invalid procedure call or argument

on the following line of code:

    txtDim(0).SetFocus

What's interesting is that I use exactly the same line
of code elsewhere without a problem.  This leads me to believe
there's something about the context that's making a difference,
but I have no idea what it could be....

I've got a control array of 4 TextBoxes (txtDim(0) -> txtDim(3)) that
I manipulate in a variety of ways for a variety of reasons.

If someone could/would point out what I'm missing, I'd appreciate it

adTHANKSvance!

Simeon

P.S. The is still being developed... I know my numeric validation still
     needs a bunch of work.

     I apologize if I've included too much detail for a posting to this
     forum.  I always figure too much info is better than not enough.

S

Here's the context where it works:

Private Sub cmdCalc_Click()

    Dim dblNum1 As Double
    Dim dblNum2 As Double
    Dim dblNum3 As Double
    Dim dblNum4 As Double

    Dim dblPerimSurf As Double
    Dim dblAreaVol As Double
    Dim txtPerimSurf As Double
    Dim txtAreaVol As DragConstants
    Dim blnOK As Boolean

    ' Validate the numbers

    If Len(Trim(txtDim(0).Text)) > 0 Then
        dblNum1 = CDbl(txtDim(0))
    End If

    If Len(Trim(txtDim(1).Text)) > 0 Then
        dblNum2 = CDbl(txtDim(1))
    End If

    If Len(Trim(txtDim(2).Text)) > 0 Then
        dblNum3 = CDbl(txtDim(2))
    End If

    If Len(Trim(txtDim(3).Text)) > 0 Then
        dblNum4 = CDbl(txtDim(3))
    End If

    If lstShapes.List(lstShapes.ListIndex) = "Triangle" Or _
       lstShapes.List(lstShapes.ListIndex) = "Prism" Then
       If Not GoodTriangle(dblNum1, dblNum2, dblNum3) Then
            MsgBox "Invalid triangle parms specfied", vbCritical, "Invalid
Input"
            txtDim(0).SelStart = 0
            txtDim(0).SelLength = Len(txtDim(0).Text)
            txtDim(0).SetFocus         '<<<===========================
Here's the code
            Exit Sub
       End If
    End If

    ' Perform the calculations

    Select Case lstShapes.List(lstShapes.ListIndex)
        Case "Circle"
            dblPerimSurf = PerimOfCircle(dblNum1)
            dblAreaVol = AreaOfCircle(dblNum1)

        Case "Rectangle"
            dblPerimSurf = PerimOfRect(dblNum1, dblNum2)
            dblAreaVol = AreaOfRect(dblNum1, dblNum2)

        Case "Cylinder"
            dblPerimSurf = SurfOfCyl(dblNum1, dblNum2)
            dblAreaVol = VolOfCyl(dblNum1, dblNum2)

        Case "Cone"
            dblPerimSurf = SurfOfCone(dblNum1, dblNum2)
            dblAreaVol = VolOfCone(dblNum1, dblNum2)

        Case "Sphere"
            dblPerimSurf = SurfOfSphere(dblNum1)
            dblAreaVol = VolOfSphere(dblNum1)

        Case "Triangle"
            dblPerimSurf = PerimOfTriangle(dblNum1, dblNum2, dblNum3)
            dblAreaVol = AreaOfTriangle(dblNum1, dblNum3, dblNum3)

        Case "Block"
            dblPerimSurf = SurfOfBlock(dblNum1, dblNum2, dblNum3)
            dblAreaVol = VolOfBlock(dblNum1, dblNum2, dblNum3)

        Case "Prism"
            dblPerimSurf = SurfOfPrism(dblNum1, dblNum2, dblNum3, dblNum4)
            dblAreaVol = VolOfPrism(dblNum1, dblNum2, dblNum3, dblNum4)

    End Select

    'Display the results

    lblAreaVal = FormatNumber(dblAreaVol, 5, vbTrue, vbFalse, vbUseDefault)
    lblPerimVal = FormatNumber(dblPerimSurf, 5, vbTrue, vbFalse,
vbUseDefault)

End Sub

Here's the context that gives the compile error:

Private Sub lstShapes_Click()

    HideInputAreas

    Select Case lstShapes.List(lstShapes.ListIndex)

        Case "Circle"
            lblDim(0).Caption = "Radius"
            lblDim(0).Visible = True
            txtDim(0).Visible = True
            lblPerim.Caption = "Perimeter = "
            lblArea.Caption = "Area = "
            chkDispPerim.Caption = "Display Perimeter?"
            chkDispArea.Caption = "Display Area?"

        Case "Rectangle"
            lblDim(0).Caption = "Length"
            lblDim(0).Visible = True
            txtDim(0).Visible = True
            lblDim(1).Caption = "Width"
            lblDim(1).Visible = True
            txtDim(1).Visible = True
            lblPerim.Caption = "Perimeter = "
            lblArea.Caption = "Area = "
            chkDispPerim.Caption = "Display Perimeter?"
            chkDispArea.Caption = "Display Area?"

        Case "Cylinder"
            lblDim(0).Caption = "Radius"
            lblDim(0).Visible = True
            txtDim(0).Visible = True
            lblDim(1).Caption = "Height"
            lblDim(1).Visible = True
            txtDim(1).Visible = True
            lblPerim.Caption = "Surface Area = "
            lblArea.Caption = "Volume = "
            chkDispPerim.Caption = "Display Surface Area?"
            chkDispArea.Caption = "Display Volume?"

        Case "Cone"
            lblDim(0).Caption = "Radius"
            lblDim(0).Visible = True
            txtDim(0).Visible = True
            lblDim(1).Caption = "Height"
            lblDim(1).Visible = True
            txtDim(1).Visible = True
            lblPerim.Caption = "Surface Area = "
            lblArea.Caption = "Volume = "
            chkDispPerim.Caption = "Display Surface Area?"
            chkDispArea.Caption = "Display Volume?"

        Case "Sphere"
            lblDim(0).Caption = "Radius"
            lblDim(0).Visible = True
            txtDim(0).Visible = True
            lblPerim.Caption = "Surface Area = "
            lblArea.Caption = "Volume = "
            chkDispPerim.Caption = "Display Surface Area?"
            chkDispArea.Caption = "Display Volume?"

        Case "Prism"
            lblDim(0).Caption = "Side 1"
            lblDim(0).Visible = True
            txtDim(0).Visible = True
            lblDim(1).Caption = "Side 2"
            lblDim(1).Visible = True
            txtDim(1).Visible = True
            lblDim(2).Caption = "Side 3"
            lblDim(2).Visible = True
            txtDim(2).Visible = True
            lblDim(3).Caption = "Height"
            lblDim(3).Visible = True
            txtDim(3).Visible = True
            lblPerim.Caption = "Surface Area = "
            lblArea.Caption = "Volume = "
            chkDispPerim.Caption = "Display Surface Area?"
            chkDispArea.Caption = "Display Volume?"

        Case "Triangle"
            lblDim(0).Caption = "Side 1"
            lblDim(0).Visible = True
            txtDim(0).Visible = True
            lblDim(1).Caption = "Side 2"
            lblDim(1).Visible = True
            txtDim(1).Visible = True
            lblDim(2).Caption = "Side 3"
            lblDim(2).Visible = True
            txtDim(2).Visible = True
            lblPerim.Caption = "Perimeter = "
            lblArea.Caption = "Area = "
            chkDispPerim.Caption = "Display Perimeter?"
            chkDispArea.Caption = "Display Area?"

        Case "Block"
            lblDim(0).Caption = "Length"
            lblDim(0).Visible = True
            txtDim(0).Visible = True
            lblDim(1).Caption = "Width"
            lblDim(1).Visible = True
            txtDim(1).Visible = True
            lblDim(2).Caption = "Height"
            lblDim(2).Visible = True
            txtDim(2).Visible = True
            lblPerim.Caption = "Surface Area = "
            lblArea.Caption = "Volume = "
            chkDispPerim.Caption = "Display Surface Area?"
            chkDispArea.Caption = "Display Volume?"
    End Select

    txtDim(0).SetFocus  '<<<<<<================= Here's the code again

End Sub



Wed, 17 Aug 2005 05:18:49 GMT  
 "Invalid procedure call..." on "txtDim(0).SetFocus"
Didn't see this in your code, but I get the same error when my object that
is getting focus is set .Enabled = False

May be something to look at...


Quote:
> I'm having the damnedest time trying to resolve a compile time error
> in some code I'm working on.

> I'm getting the following error:

>     Runtime error '5'
>     Invalid procedure call or argument

> on the following line of code:

>     txtDim(0).SetFocus

> What's interesting is that I use exactly the same line
> of code elsewhere without a problem.  This leads me to believe
> there's something about the context that's making a difference,
> but I have no idea what it could be....

> I've got a control array of 4 TextBoxes (txtDim(0) -> txtDim(3)) that
> I manipulate in a variety of ways for a variety of reasons.

> If someone could/would point out what I'm missing, I'd appreciate it

> adTHANKSvance!

> Simeon

> P.S. The is still being developed... I know my numeric validation still
>      needs a bunch of work.

>      I apologize if I've included too much detail for a posting to this
>      forum.  I always figure too much info is better than not enough.

> S

> Here's the context where it works:

> Private Sub cmdCalc_Click()

>     Dim dblNum1 As Double
>     Dim dblNum2 As Double
>     Dim dblNum3 As Double
>     Dim dblNum4 As Double

>     Dim dblPerimSurf As Double
>     Dim dblAreaVol As Double
>     Dim txtPerimSurf As Double
>     Dim txtAreaVol As DragConstants
>     Dim blnOK As Boolean

>     ' Validate the numbers

>     If Len(Trim(txtDim(0).Text)) > 0 Then
>         dblNum1 = CDbl(txtDim(0))
>     End If

>     If Len(Trim(txtDim(1).Text)) > 0 Then
>         dblNum2 = CDbl(txtDim(1))
>     End If

>     If Len(Trim(txtDim(2).Text)) > 0 Then
>         dblNum3 = CDbl(txtDim(2))
>     End If

>     If Len(Trim(txtDim(3).Text)) > 0 Then
>         dblNum4 = CDbl(txtDim(3))
>     End If

>     If lstShapes.List(lstShapes.ListIndex) = "Triangle" Or _
>        lstShapes.List(lstShapes.ListIndex) = "Prism" Then
>        If Not GoodTriangle(dblNum1, dblNum2, dblNum3) Then
>             MsgBox "Invalid triangle parms specfied", vbCritical, "Invalid
> Input"
>             txtDim(0).SelStart = 0
>             txtDim(0).SelLength = Len(txtDim(0).Text)
>             txtDim(0).SetFocus         '<<<===========================
> Here's the code
>             Exit Sub
>        End If
>     End If

>     ' Perform the calculations

>     Select Case lstShapes.List(lstShapes.ListIndex)
>         Case "Circle"
>             dblPerimSurf = PerimOfCircle(dblNum1)
>             dblAreaVol = AreaOfCircle(dblNum1)

>         Case "Rectangle"
>             dblPerimSurf = PerimOfRect(dblNum1, dblNum2)
>             dblAreaVol = AreaOfRect(dblNum1, dblNum2)

>         Case "Cylinder"
>             dblPerimSurf = SurfOfCyl(dblNum1, dblNum2)
>             dblAreaVol = VolOfCyl(dblNum1, dblNum2)

>         Case "Cone"
>             dblPerimSurf = SurfOfCone(dblNum1, dblNum2)
>             dblAreaVol = VolOfCone(dblNum1, dblNum2)

>         Case "Sphere"
>             dblPerimSurf = SurfOfSphere(dblNum1)
>             dblAreaVol = VolOfSphere(dblNum1)

>         Case "Triangle"
>             dblPerimSurf = PerimOfTriangle(dblNum1, dblNum2, dblNum3)
>             dblAreaVol = AreaOfTriangle(dblNum1, dblNum3, dblNum3)

>         Case "Block"
>             dblPerimSurf = SurfOfBlock(dblNum1, dblNum2, dblNum3)
>             dblAreaVol = VolOfBlock(dblNum1, dblNum2, dblNum3)

>         Case "Prism"
>             dblPerimSurf = SurfOfPrism(dblNum1, dblNum2, dblNum3, dblNum4)
>             dblAreaVol = VolOfPrism(dblNum1, dblNum2, dblNum3, dblNum4)

>     End Select

>     'Display the results

>     lblAreaVal = FormatNumber(dblAreaVol, 5, vbTrue, vbFalse,
vbUseDefault)
>     lblPerimVal = FormatNumber(dblPerimSurf, 5, vbTrue, vbFalse,
> vbUseDefault)

> End Sub

> Here's the context that gives the compile error:

> Private Sub lstShapes_Click()

>     HideInputAreas

>     Select Case lstShapes.List(lstShapes.ListIndex)

>         Case "Circle"
>             lblDim(0).Caption = "Radius"
>             lblDim(0).Visible = True
>             txtDim(0).Visible = True
>             lblPerim.Caption = "Perimeter = "
>             lblArea.Caption = "Area = "
>             chkDispPerim.Caption = "Display Perimeter?"
>             chkDispArea.Caption = "Display Area?"

>         Case "Rectangle"
>             lblDim(0).Caption = "Length"
>             lblDim(0).Visible = True
>             txtDim(0).Visible = True
>             lblDim(1).Caption = "Width"
>             lblDim(1).Visible = True
>             txtDim(1).Visible = True
>             lblPerim.Caption = "Perimeter = "
>             lblArea.Caption = "Area = "
>             chkDispPerim.Caption = "Display Perimeter?"
>             chkDispArea.Caption = "Display Area?"

>         Case "Cylinder"
>             lblDim(0).Caption = "Radius"
>             lblDim(0).Visible = True
>             txtDim(0).Visible = True
>             lblDim(1).Caption = "Height"
>             lblDim(1).Visible = True
>             txtDim(1).Visible = True
>             lblPerim.Caption = "Surface Area = "
>             lblArea.Caption = "Volume = "
>             chkDispPerim.Caption = "Display Surface Area?"
>             chkDispArea.Caption = "Display Volume?"

>         Case "Cone"
>             lblDim(0).Caption = "Radius"
>             lblDim(0).Visible = True
>             txtDim(0).Visible = True
>             lblDim(1).Caption = "Height"
>             lblDim(1).Visible = True
>             txtDim(1).Visible = True
>             lblPerim.Caption = "Surface Area = "
>             lblArea.Caption = "Volume = "
>             chkDispPerim.Caption = "Display Surface Area?"
>             chkDispArea.Caption = "Display Volume?"

>         Case "Sphere"
>             lblDim(0).Caption = "Radius"
>             lblDim(0).Visible = True
>             txtDim(0).Visible = True
>             lblPerim.Caption = "Surface Area = "
>             lblArea.Caption = "Volume = "
>             chkDispPerim.Caption = "Display Surface Area?"
>             chkDispArea.Caption = "Display Volume?"

>         Case "Prism"
>             lblDim(0).Caption = "Side 1"
>             lblDim(0).Visible = True
>             txtDim(0).Visible = True
>             lblDim(1).Caption = "Side 2"
>             lblDim(1).Visible = True
>             txtDim(1).Visible = True
>             lblDim(2).Caption = "Side 3"
>             lblDim(2).Visible = True
>             txtDim(2).Visible = True
>             lblDim(3).Caption = "Height"
>             lblDim(3).Visible = True
>             txtDim(3).Visible = True
>             lblPerim.Caption = "Surface Area = "
>             lblArea.Caption = "Volume = "
>             chkDispPerim.Caption = "Display Surface Area?"
>             chkDispArea.Caption = "Display Volume?"

>         Case "Triangle"
>             lblDim(0).Caption = "Side 1"
>             lblDim(0).Visible = True
>             txtDim(0).Visible = True
>             lblDim(1).Caption = "Side 2"
>             lblDim(1).Visible = True
>             txtDim(1).Visible = True
>             lblDim(2).Caption = "Side 3"
>             lblDim(2).Visible = True
>             txtDim(2).Visible = True
>             lblPerim.Caption = "Perimeter = "
>             lblArea.Caption = "Area = "
>             chkDispPerim.Caption = "Display Perimeter?"
>             chkDispArea.Caption = "Display Area?"

>         Case "Block"
>             lblDim(0).Caption = "Length"
>             lblDim(0).Visible = True
>             txtDim(0).Visible = True
>             lblDim(1).Caption = "Width"
>             lblDim(1).Visible = True
>             txtDim(1).Visible = True
>             lblDim(2).Caption = "Height"
>             lblDim(2).Visible = True
>             txtDim(2).Visible = True
>             lblPerim.Caption = "Surface Area = "
>             lblArea.Caption = "Volume = "
>             chkDispPerim.Caption = "Display Surface Area?"
>             chkDispArea.Caption = "Display Volume?"
>     End Select

>     txtDim(0).SetFocus  '<<<<<<================= Here's the code again

> End Sub



Wed, 17 Aug 2005 05:46:46 GMT  
 "Invalid procedure call..." on "txtDim(0).SetFocus"

Quote:
> I'm getting the following error:

>     Runtime error '5'
>     Invalid procedure call or argument

> on the following line of code:

>     txtDim(0).SetFocus

<...>
> If someone could/would point out what I'm missing, I'd appreciate it

> Here's the context that gives the compile error:

> Private Sub lstShapes_Click()

>     HideInputAreas

  ...

Quote:
>     txtDim(0).SetFocus

A control has to be visible, and enabled to receive focus....

LFS



Wed, 17 Aug 2005 06:03:59 GMT  
 "Invalid procedure call..." on "txtDim(0).SetFocus"


Quote:
> Didn't see this in your code, but I get the same error when my object that
> is getting focus is set .Enabled = False

> May be something to look at...

Thanks for the tip... I'll try it out.

I first make all the textboxes invisible (.Visible = False) and then
make the ones I want (depending in the selection in the listbox)
visible again.

It seems weird that I'd also have to "Enable" them as well.

I'll let you know if your suggestion works.

Simeon



Wed, 17 Aug 2005 05:53:19 GMT  
 "Invalid procedure call..." on "txtDim(0).SetFocus"

Quote:

> A control has to be visible, and enabled to receive focus....

But that's surely not something the compiler can pick up?


Wed, 17 Aug 2005 06:31:20 GMT  
 "Invalid procedure call..." on "txtDim(0).SetFocus"


Quote:

> > I'm getting the following error:

> >     Runtime error '5'
> >     Invalid procedure call or argument

> > on the following line of code:

> >     txtDim(0).SetFocus

> <...>
> > If someone could/would point out what I'm missing, I'd appreciate it

> > Here's the context that gives the compile error:

> > Private Sub lstShapes_Click()

> >     HideInputAreas
>   ...

> >     txtDim(0).SetFocus

> A control has to be visible, and enabled to receive focus....

Each case under the select clause has one of these:

                txtDim(0).Visible = True

I'll see if "Enable"ing the txt box after making it visible fixes things

Simeon



Wed, 17 Aug 2005 06:46:21 GMT  
 "Invalid procedure call..." on "txtDim(0).SetFocus"

<cut>

Quote:
>> A control has to be visible, and enabled to receive focus....

> Each case under the select clause has one of these:

>                 txtDim(0).Visible = True

> I'll see if "Enable"ing the txt box after making it visible fixes
> things

In addition, as far as I know the form also has to be visible and enabled;
you can;t set focus to a window unless it is actually eligible to get focus
at that time


Wed, 17 Aug 2005 07:05:47 GMT  
 "Invalid procedure call..." on "txtDim(0).SetFocus"

Quote:
> > A control has to be visible, and enabled to receive focus....

> Each case under the select clause has one of these:

>                 txtDim(0).Visible = True

But it may be that none of the Cases are executed, for instance,
if the ListIndex was -1, none of the cases would be used.

LFS



Wed, 17 Aug 2005 08:20:48 GMT  
 "Invalid procedure call..." on "txtDim(0).SetFocus"
# But that's surely not something the compiler can pick up?

No, its a runtime error occurring when the code executes and hits the wall.
Like the method says ... in order to set focus the textbox must be
"focusable" ... on screen, visible and enabled.

--

Randy Birch
MVP Visual Basic
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.



Wed, 17 Aug 2005 09:02:05 GMT  
 "Invalid procedure call..." on "txtDim(0).SetFocus"
Are you getting this error when executing your code in the Form_Load
event?

Rick - MVP


Quote:
> I'm having the damnedest time trying to resolve a compile time error
> in some code I'm working on.

> I'm getting the following error:

>     Runtime error '5'
>     Invalid procedure call or argument

> on the following line of code:

>     txtDim(0).SetFocus

> What's interesting is that I use exactly the same line
> of code elsewhere without a problem.  This leads me to believe
> there's something about the context that's making a difference,
> but I have no idea what it could be....

> I've got a control array of 4 TextBoxes (txtDim(0) -> txtDim(3)) that
> I manipulate in a variety of ways for a variety of reasons.

> If someone could/would point out what I'm missing, I'd appreciate it

> adTHANKSvance!

> Simeon

> P.S. The is still being developed... I know my numeric validation
still
>      needs a bunch of work.

>      I apologize if I've included too much detail for a posting to
this
>      forum.  I always figure too much info is better than not enough.

> S

> Here's the context where it works:

> Private Sub cmdCalc_Click()

>     Dim dblNum1 As Double
>     Dim dblNum2 As Double
>     Dim dblNum3 As Double
>     Dim dblNum4 As Double

>     Dim dblPerimSurf As Double
>     Dim dblAreaVol As Double
>     Dim txtPerimSurf As Double
>     Dim txtAreaVol As DragConstants
>     Dim blnOK As Boolean

>     ' Validate the numbers

>     If Len(Trim(txtDim(0).Text)) > 0 Then
>         dblNum1 = CDbl(txtDim(0))
>     End If

>     If Len(Trim(txtDim(1).Text)) > 0 Then
>         dblNum2 = CDbl(txtDim(1))
>     End If

>     If Len(Trim(txtDim(2).Text)) > 0 Then
>         dblNum3 = CDbl(txtDim(2))
>     End If

>     If Len(Trim(txtDim(3).Text)) > 0 Then
>         dblNum4 = CDbl(txtDim(3))
>     End If

>     If lstShapes.List(lstShapes.ListIndex) = "Triangle" Or _
>        lstShapes.List(lstShapes.ListIndex) = "Prism" Then
>        If Not GoodTriangle(dblNum1, dblNum2, dblNum3) Then
>             MsgBox "Invalid triangle parms specfied", vbCritical,
"Invalid
> Input"
>             txtDim(0).SelStart = 0
>             txtDim(0).SelLength = Len(txtDim(0).Text)
>             txtDim(0).SetFocus         '<<<===========================
> Here's the code
>             Exit Sub
>        End If
>     End If

>     ' Perform the calculations

>     Select Case lstShapes.List(lstShapes.ListIndex)
>         Case "Circle"
>             dblPerimSurf = PerimOfCircle(dblNum1)
>             dblAreaVol = AreaOfCircle(dblNum1)

>         Case "Rectangle"
>             dblPerimSurf = PerimOfRect(dblNum1, dblNum2)
>             dblAreaVol = AreaOfRect(dblNum1, dblNum2)

>         Case "Cylinder"
>             dblPerimSurf = SurfOfCyl(dblNum1, dblNum2)
>             dblAreaVol = VolOfCyl(dblNum1, dblNum2)

>         Case "Cone"
>             dblPerimSurf = SurfOfCone(dblNum1, dblNum2)
>             dblAreaVol = VolOfCone(dblNum1, dblNum2)

>         Case "Sphere"
>             dblPerimSurf = SurfOfSphere(dblNum1)
>             dblAreaVol = VolOfSphere(dblNum1)

>         Case "Triangle"
>             dblPerimSurf = PerimOfTriangle(dblNum1, dblNum2, dblNum3)
>             dblAreaVol = AreaOfTriangle(dblNum1, dblNum3, dblNum3)

>         Case "Block"
>             dblPerimSurf = SurfOfBlock(dblNum1, dblNum2, dblNum3)
>             dblAreaVol = VolOfBlock(dblNum1, dblNum2, dblNum3)

>         Case "Prism"
>             dblPerimSurf = SurfOfPrism(dblNum1, dblNum2, dblNum3,
dblNum4)
>             dblAreaVol = VolOfPrism(dblNum1, dblNum2, dblNum3,
dblNum4)

>     End Select

>     'Display the results

>     lblAreaVal = FormatNumber(dblAreaVol, 5, vbTrue, vbFalse,
vbUseDefault)
>     lblPerimVal = FormatNumber(dblPerimSurf, 5, vbTrue, vbFalse,
> vbUseDefault)

> End Sub

> Here's the context that gives the compile error:

> Private Sub lstShapes_Click()

>     HideInputAreas

>     Select Case lstShapes.List(lstShapes.ListIndex)

>         Case "Circle"
>             lblDim(0).Caption = "Radius"
>             lblDim(0).Visible = True
>             txtDim(0).Visible = True
>             lblPerim.Caption = "Perimeter = "
>             lblArea.Caption = "Area = "
>             chkDispPerim.Caption = "Display Perimeter?"
>             chkDispArea.Caption = "Display Area?"

>         Case "Rectangle"
>             lblDim(0).Caption = "Length"
>             lblDim(0).Visible = True
>             txtDim(0).Visible = True
>             lblDim(1).Caption = "Width"
>             lblDim(1).Visible = True
>             txtDim(1).Visible = True
>             lblPerim.Caption = "Perimeter = "
>             lblArea.Caption = "Area = "
>             chkDispPerim.Caption = "Display Perimeter?"
>             chkDispArea.Caption = "Display Area?"

>         Case "Cylinder"
>             lblDim(0).Caption = "Radius"
>             lblDim(0).Visible = True
>             txtDim(0).Visible = True
>             lblDim(1).Caption = "Height"
>             lblDim(1).Visible = True
>             txtDim(1).Visible = True
>             lblPerim.Caption = "Surface Area = "
>             lblArea.Caption = "Volume = "
>             chkDispPerim.Caption = "Display Surface Area?"
>             chkDispArea.Caption = "Display Volume?"

>         Case "Cone"
>             lblDim(0).Caption = "Radius"
>             lblDim(0).Visible = True
>             txtDim(0).Visible = True
>             lblDim(1).Caption = "Height"
>             lblDim(1).Visible = True
>             txtDim(1).Visible = True
>             lblPerim.Caption = "Surface Area = "
>             lblArea.Caption = "Volume = "
>             chkDispPerim.Caption = "Display Surface Area?"
>             chkDispArea.Caption = "Display Volume?"

>         Case "Sphere"
>             lblDim(0).Caption = "Radius"
>             lblDim(0).Visible = True
>             txtDim(0).Visible = True
>             lblPerim.Caption = "Surface Area = "
>             lblArea.Caption = "Volume = "
>             chkDispPerim.Caption = "Display Surface Area?"
>             chkDispArea.Caption = "Display Volume?"

>         Case "Prism"
>             lblDim(0).Caption = "Side 1"
>             lblDim(0).Visible = True
>             txtDim(0).Visible = True
>             lblDim(1).Caption = "Side 2"
>             lblDim(1).Visible = True
>             txtDim(1).Visible = True
>             lblDim(2).Caption = "Side 3"
>             lblDim(2).Visible = True
>             txtDim(2).Visible = True
>             lblDim(3).Caption = "Height"
>             lblDim(3).Visible = True
>             txtDim(3).Visible = True
>             lblPerim.Caption = "Surface Area = "
>             lblArea.Caption = "Volume = "
>             chkDispPerim.Caption = "Display Surface Area?"
>             chkDispArea.Caption = "Display Volume?"

>         Case "Triangle"
>             lblDim(0).Caption = "Side 1"
>             lblDim(0).Visible = True
>             txtDim(0).Visible = True
>             lblDim(1).Caption = "Side 2"
>             lblDim(1).Visible = True
>             txtDim(1).Visible = True
>             lblDim(2).Caption = "Side 3"
>             lblDim(2).Visible = True
>             txtDim(2).Visible = True
>             lblPerim.Caption = "Perimeter = "
>             lblArea.Caption = "Area = "
>             chkDispPerim.Caption = "Display Perimeter?"
>             chkDispArea.Caption = "Display Area?"

>         Case "Block"
>             lblDim(0).Caption = "Length"
>             lblDim(0).Visible = True
>             txtDim(0).Visible = True
>             lblDim(1).Caption = "Width"
>             lblDim(1).Visible = True
>             txtDim(1).Visible = True
>             lblDim(2).Caption = "Height"
>             lblDim(2).Visible = True
>             txtDim(2).Visible = True
>             lblPerim.Caption = "Surface Area = "
>             lblArea.Caption = "Volume = "
>             chkDispPerim.Caption = "Display Surface Area?"
>             chkDispArea.Caption = "Display Volume?"
>     End Select

>     txtDim(0).SetFocus  '<<<<<<================= Here's the code again

> End Sub



Wed, 17 Aug 2005 10:05:03 GMT  
 "Invalid procedure call..." on "txtDim(0).SetFocus"

Quote:

>> A control has to be visible, and enabled to receive focus....

> But that's surely not something the compiler can pick up?

Absolutely.. My bad.  It's a *run* time error.

Simeon

--
The address in the header *is* actually replyable.
If replying, use mail or post here.  Please, not both

If you're not outraged, you're not paying attention



Thu, 18 Aug 2005 14:32:27 GMT  
 "Invalid procedure call..." on "txtDim(0).SetFocus"

Quote:



>> Didn't see this in your code, but I get the same error when my object that
>> is getting focus is set .Enabled = False

>> May be something to look at...
> Thanks for the tip... I'll try it out.

Adding setting .Enabled to true just before the offending line of code
didn't fix anything.

<sigh>

Simeon
--
The address in the header *is* actually replyable.
If replying, use mail or post here.  Please, not both

If you're not outraged, you're not paying attention



Thu, 18 Aug 2005 14:31:58 GMT  
 "Invalid procedure call..." on "txtDim(0).SetFocus"

Quote:


>> > A control has to be visible, and enabled to receive focus....

>> Each case under the select clause has one of these:

>>                 txtDim(0).Visible = True

> But it may be that none of the Cases are executed, for instance,
> if the ListIndex was -1, none of the cases would be used.

The listindex is set to 0 (zero) explicitly as part of the formload event.

Simeon

--
The address in the header *is* actually replyable.
If replying, use mail or post here.  Please, not both

If you're not outraged, you're not paying attention



Thu, 18 Aug 2005 14:33:19 GMT  
 "Invalid procedure call..." on "txtDim(0).SetFocus"

Quote:

> Are you getting this error when executing your code in the Form_Load
> event?

Yup....

The code is happening in the ListBox_Click which is getting invoked from
the Form_Load when I explicitly set the listindex to zero.

I'm guessing that the form isn't actually visible yet, so I can't set
focus anywhere.  Is there anyway to work around this?

Simeon



Thu, 18 Aug 2005 14:42:03 GMT  
 "Invalid procedure call..." on "txtDim(0).SetFocus"

Quote:

> > Are you getting this error when executing your code in the Form_Load
> > event?

> Yup....

> The code is happening in the ListBox_Click which is getting invoked
from
> the Form_Load when I explicitly set the listindex to zero.

> I'm guessing that the form isn't actually visible yet, so I can't set
> focus anywhere.  Is there anyway to work around this?

Basically, that is the problem. You could use the Activate event
instead, but if you have multiple forms that you can bounce back and
forth between, this code will be executed every time your user returns
to start-up form. A way around this problem is to define a project-wide
global Boolean variable as a flag for whether the Activate event is
running for the first time or not. When I need to do this, I use the
variable name Initializing. I set it to True in the form's Load event.
In the Activate event, I might use something like this

     If Initializing Then
       ListBox.SetFocus
       ' other code to be executed at load time only
     End If
     Initializing = False
     .....
     .....

Another way around this is to use a splash screen as your start-up form.
Run a Timer on it to make sure it shows some minimal amount of time and
Load the first (main) form from there. That way its Activate event will
only be called once for the program.

Rick - MVP



Thu, 18 Aug 2005 15:14:13 GMT  
 
 [ 19 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Run-time error "5": Invalid procedure call

2. "Invalid Procedure Call"

3. *"*-.,._,.-*"* I"LL TRADE VISUAL C++ FOR VBASIC *"*-.,_,.-*"*

4. Call procedure on "On Click" event

5. GetObject("","InternetExplorer.Application") fails in Excel VBA

6. Passing "State" Into Called Procedures

7. SysCmd 603, "path","path"

8. Disabling "BACK"/"FORWARD" buttons

9. Loop print "VARIABLE", "VARIABLE"

10. DLL or something like "#"#ยค#"!"#

11. Disabling "BACK"/"FORWARD" buttons

12. CreateObject("Excel","//server"), MsgBox output

 

 
Powered by phpBB® Forum Software