Hello,
I'm experiencing a strange problem in vb 6.0. I set up a form with
two command buttons in a control array and the form_load code is as
follows:
Private Sub Form_Load()
Command1(1).SetFocus
End Sub
What's odd is that when I run this, I get the error:
Run-time error '5'
Invalid procedure call or argument
Now, I know I've done this before and did not get this error. Is
there some reason why VB decided to barf on this? I can't think of
anything.
Thanks,
* Robinson
AustinMN - 23 Dec 2004 21:26 GMT
> Hello,
>
[quoted text clipped - 13 lines]
> there some reason why VB decided to barf on this? I can't think of
> anything.
There are a handful of reasons this might not work, all having to do with
whether Command1(1) can get the focus.
If the form is not visible, neither it nor it's controls can have the focus.
Try Me.Visible=True before the .SetFocus.
Because you did this in the Form_Load event, Command1(1) may not be loaded
yet. Put DoEvents before .SetFocus.
Command1(1) is may not be visible or not enabled. Check those.
Austin

Signature
You programmed with 1s and 0s? We only had 0s!
There are no X characters in my address
John Simpson - 23 Dec 2004 22:05 GMT
> Hello,
>
[quoted text clipped - 3 lines]
>
> Private Sub Form_Load()
< --------------------------------------------------- me.show
> Command1(1).SetFocus
> End Sub
[quoted text clipped - 9 lines]
> Thanks,
> * Robinson
Lee Weiner - 23 Dec 2004 22:41 GMT
>Hello,
>
[quoted text clipped - 13 lines]
>there some reason why VB decided to barf on this? I can't think of
>anything.
No, you didn't do this before, at least, not exactly like this. Controls on
forms don't fully exist until Form_Load ends, so you can't call methods on
them. There are two ways to handle it. Either move your SetFocus statement
to the Form_Activate event, or call Me.Show in Form_Load to force the
completion of the form, then call SetFocus.
Lee Weiner
lee AT leeweiner DOT org
Randy Birch - 24 Dec 2004 00:45 GMT
: so you can't call methods on them
Not exactly.

Signature
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
Jan Hyde - 24 Dec 2004 08:47 GMT
Mirror Spock <robins80@msu.edu>'s wild thoughts were
released on Thu, 23 Dec 2004 16:11:33 -0500 bearing the
following fruit:
>Hello,
>
[quoted text clipped - 16 lines]
>Thanks,
>* Robinson
Who o why o why o why arn't you relying on the tabindex of
your controls?
Jan Hyde (VB MVP)

Signature
BACHELOR: A man who never makes the same mistake once.
[Abolish the TV License - http://www.tvlicensing.biz/]
AustinMN - 24 Dec 2004 16:16 GMT
<snippage>
> Who o why o why o why arn't you relying on the tabindex of
> your controls?
Maybe, just maybe, the program starts under different circumstances (Start
menu vs double click an associated file, for example) that requires
different initial focus.
Austin
Jan Hyde - 29 Dec 2004 09:03 GMT
"AustinMN" <Austin260@comcast.net>'s wild thoughts were
released on Fri, 24 Dec 2004 10:16:13 -0600 bearing the
following fruit:
><snippage>
>
[quoted text clipped - 4 lines]
>menu vs double click an associated file, for example) that requires
>different initial focus.
Huh? An application does not know how it was started.
Jan Hyde (VB MVP)

Signature
Protuberance: Small insects that are fond of potatoes. (Gary Hallock)
[Abolish the TV License - http://www.tvlicensing.biz/]
AustinMN - 29 Dec 2004 23:44 GMT
> "AustinMN" <Austin260@comcast.net>'s wild thoughts were
> released on Fri, 24 Dec 2004 10:16:13 -0600 bearing the
[quoted text clipped - 10 lines]
>
> Huh? An application does not know how it was started.
Chuckle.
Austin

Signature
You programmed with 1s and 0s? We only had 0s!
There are no X characters in my address
popovloud@yahoo.com.au - 26 Dec 2004 11:01 GMT
Try the Form_Activate event. Your control is not visible and able to
take focus until its container is loaded ie Form. Bit of a pain because
of the side effects, leave that to you though. Damn this new Google
interface,
Dave