VB form focus

Discussion in 'SolidWorks' started by Wayne Tiffany, Jul 12, 2004.

  1. 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
     
    Wayne Tiffany, Jul 12, 2004
    #1
  2. 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
     
    Corey Scheich, Jul 12, 2004
    #2
  3. 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
     
    Wayne Tiffany, Jul 12, 2004
    #3
  4. Wayne Tiffany

    David Guest

    Try using this approach...

    Private Sub Form_GotFocus( )
     
    David, Jul 13, 2004
    #4
  5. That's what I tried by replacing "Form" with the name of my form, and the
    form never would see the event. Thanks.

    WT
     
    Wayne Tiffany, Jul 13, 2004
    #5
  6. 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,

    Corey Scheich
     
    Corey Scheich, Jul 13, 2004
    #6
  7. 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."
     
    Corey Scheich, Jul 13, 2004
    #7
  8. 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
     
    Wayne Tiffany, Jul 13, 2004
    #8
  9. It teaches us patience, unfortunately. =^)

    Corey
     
    Corey Scheich, Jul 13, 2004
    #9
  10. 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
     
    Corey Scheich, Jul 13, 2004
    #10
  11. 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
     
    Wayne Tiffany, Jul 13, 2004
    #11
  12. 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
     
    Corey Scheich, Jul 13, 2004
    #12
  13. 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
     
    Corey Scheich, Jul 13, 2004
    #13
  14. Wayne Tiffany

    David Guest

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

    Private Sub object_Activate( )
     
    David, Jul 13, 2004
    #14
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.