Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General 2 / December 2004



Tip: Looking for answers? Try searching our database.

Weird VB error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mirror Spock - 23 Dec 2004 21:11 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.