VB form focus

I'm working on modifying the SW portion of an existing in-house VB program (that I didn't write) to put the selected SW properties into config-specific locations. I am trying to determine if the user has clicked out of the program and changed the current SW configuration.

My thought was to use the GotFocus event of the form, so that anytime it received the focus, I would compare the current config name in SW to a stored value. If they differ, the user changed configs some time.

My problem is that the form, for some reason, doesn't see the focus. If I change the "focus" watch to a control on the form, it sees it, but if the user has the cursor in a box on the form, goes out to change the config, and the comes back to the form and doesn't change to another box on the form, then none of the controls on the form see a GotFocus event.

Any thoughts out there?

WT

Reply to
Wayne Tiffany
Loading thread data ...

There is a config change event for both models and assemblies if you watch these events you can handle them appropriately. on your form at the top add Public WithEvents thisAssy as Sldworks.AssemblyDoc Public WithEvents thisPart as Sldworks.PartDoc then you can see what events can be watched with the two drop downs at the top of the module.

Corey

config-specific

Reply to
Corey Scheich

Ok, time for the not-understanding hat to be put on.

I went to the top of the form code and pasted in the 2 lines as you had them. Did I interpret your email too literally? So here's what's now at the top:

Option Explicit Public WithEvents thisAssy As SldWorks.AssemblyDoc Public WithEvents thisPart As SldWorks.PartDoc

Dim SWapp As Object ' SolidWorks Application Object Dim Part As Object ' Part Object Dim SwConfig As SldWorks.Configuration Dim ConfigName, ConfigDesc, ConfigLength, ConfigNameStore As String

I didn't get any compile errors or anything, but I don't see where to go from there. Sorry, please more help.

WT

Reply to
Wayne Tiffany

Try using this approach...

Private Sub Form_GotFocus( )

Reply to
David

That's what I tried by replacing "Form" with the name of my form, and the form never would see the event. Thanks.

WT

Reply to
Wayne Tiffany

I e-mailed this to you Wayne with a screen shot to better clarify

The drop down on the left of the module is a list of declarations and subs in that list you would select in this case swAssy since this is a declaration with events you get a list of the available events on the right dropdown menue. In this case we want ActiveConfigChangePostNotify this will be envoked after the configuration has been changed. If you need to do something before the configuration actually changes but after the user dicided to change you use ActiveConfigChangeNotify. An event labled simply Notify always should happen before SW actually does anything. An event labled PostNotify always should happen only after SW has finished doing it. As you can see the first function is

Private Function swAssy_ActiveConfigChangePostNotify() As Long

ActvDoc.ViewZoomtofit2

End Function

It will zoom to fit after the configuration has been changed. If you are allowing the user to interface with SW you may want to use the ActiveModelDocChangeNotify also, that is the second function there, because if they switch models you may run into problems. If you need something more I would be glad to help. Using events adds a whole new level to an application have fun with it.

Regards,

Reply to
Corey Scheich

Oh yeah You can watch events only in a class module that is either the SolidWorks.ThisLibrary or a user form. As Rocheey said in a post today

"A form module is a (type of) class module, and only class modules can recieve events."

Reply to
Corey Scheich

Got it - thanks guys. My mistake was not recognizing that I needed to replace my Dim Part as... statement with the Public WithEvents Part as... one. Now, when I go out & change the config and then come back in, it triggers.

Dang, I hate being on the asking end because it's frustrating to struggle with something.

WT

Reply to
Wayne Tiffany

Wonderful.

It teaches us patience, unfortunately. =^)

Corey

Reply to
Corey Scheich

Dim ConfigName, ConfigDesc, ConfigLength, ConfigNameStore As String

By the way did you know that the above line only creates ConfigNameStore explicitly as a string the rest are variants.

To have them all be strings explicitly it would have to be

Dim ConfigName As String, ConfigDesc As String, ConfigLength As String _ , ConfigNameStore As String

regards Corey

Reply to
Corey Scheich

Funny you should mention that. I was getting a ByRef argument type mismatch because of that. Didn't it used to be that way??? How about in Access?

WT

Reply to
Wayne Tiffany

I think it has been that way for a while. Open Access or Excell and in the VB help search for "writing declaration statements" It states exactly this in there.

Corey

Reply to
Corey Scheich

sorry look up "declaring variables" I have been screwing up posts alot lately, I mustn't be getting enough sleep, my daughter has 6 teeth coming in.

Corey

ConfigNameStore

Reply to
Corey Scheich

My bad... I meant ......

Private Sub object_Activate( )

Reply to
David

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.