Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.basic.visual.misc > #2138 > unrolled thread

Win8 & VB6

Started byGS <gs@somewhere.net>
First post2014-08-28 17:55 -0400
Last post2014-08-29 07:55 -0400
Articles 12 — 3 participants

Back to article view | Back to comp.lang.basic.visual.misc


Contents

  Win8 & VB6 GS <gs@somewhere.net> - 2014-08-28 17:55 -0400
    Re: Win8 & VB6 john@jeasonNoSpam.cix.co.uk (John K.Eason) - 2014-08-28 23:58 +0100
      Re: Win8 & VB6 GS <gs@somewhere.net> - 2014-08-28 20:46 -0400
        Re: Win8 & VB6 GS <gs@somewhere.net> - 2014-08-28 20:49 -0400
      Re: Win8 & VB6 GS <gs@somewhere.net> - 2014-08-28 20:58 -0400
        Re: Win8 & VB6 john@jeasonNoSpam.cix.co.uk (John K.Eason) - 2014-08-29 12:16 +0100
          Re: Win8 & VB6 GS <gs@somewhere.net> - 2014-08-29 07:42 -0400
    Re: Win8 & VB6 ObiWan <obiwan@mvps.org> - 2014-08-29 09:53 +0200
      Re: Win8 & VB6 GS <gs@somewhere.net> - 2014-08-29 05:37 -0400
        Re: Win8 & VB6 GS <gs@somewhere.net> - 2014-08-29 05:44 -0400
        Re: Win8 & VB6 ObiWan <obiwan@mvps.org> - 2014-08-29 12:59 +0200
          Re: Win8 & VB6 GS <gs@somewhere.net> - 2014-08-29 07:55 -0400

#2138 — Win8 & VB6

FromGS <gs@somewhere.net>
Date2014-08-28 17:55 -0400
SubjectWin8 & VB6
Message-ID<lto8fv$jna$1@dont-email.me>
I have a situation where the following code for a Form raises an error 
(#5: Invalid procedure call or argument) running under Win8, but on XP 
to Win7 it works fine...

Private Sub Form_Load()
  With Me
    .Caption = gsAPP_NAME ': .Icon = fAbout.Icon
    .btnRegisterApp(LicenseReg.Validate).Enabled = _
      (Me.txtLicenseKey <> "")
    On Error Resume Next: .txtLicenseKey.SetFocus
  End With
End Sub

..where changing as follows works without error...

Private Sub Form_Load()
  With Me
    .Caption = gsAPP_NAME ': .Icon = fAbout.Icon
    .btnRegisterApp(LicenseReg.Validate).Enabled = _
      (Me.txtLicenseKey <> "")
    On Error Resume Next: Me.txtLicenseKey.SetFocus
  End With
End Sub

Does anyone have any idea why \win8 throws an error?

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [next] | [standalone]


#2139

Fromjohn@jeasonNoSpam.cix.co.uk (John K.Eason)
Date2014-08-28 23:58 +0100
Message-ID<memo.20140828235855.2256C@jeason.cix.co.uk>
In reply to#2138
In article <lto8fv$jna$1@dont-email.me>, gs@somewhere.net (GS) wrote:

> *From:* GS <gs@somewhere.net>
> *Date:* Thu, 28 Aug 2014 17:55:08 -0400
> 
> I have a situation where the following code for a Form raises an 
> error (#5: Invalid procedure call or argument) running under Win8, 
> but on XP to Win7 it works fine...
> 
> Private Sub Form_Load()
>   With Me
>     .Caption = gsAPP_NAME ': .Icon = fAbout.Icon
>     .btnRegisterApp(LicenseReg.Validate).Enabled = _
>       (Me.txtLicenseKey <> "")
>     On Error Resume Next: .txtLicenseKey.SetFocus
>   End With
> End Sub
> 
> ..where changing as follows works without error...
> 
> Private Sub Form_Load()
>   With Me
>     .Caption = gsAPP_NAME ': .Icon = fAbout.Icon
>     .btnRegisterApp(LicenseReg.Validate).Enabled = _
>       (Me.txtLicenseKey <> "")
>     On Error Resume Next: Me.txtLicenseKey.SetFocus
>   End With
> End Sub
> 
> Does anyone have any idea why \win8 throws an error?

I'm quite surprised it works at all TBH. Trying to SetFocus to a control in
Form_Load causes an error because the control isn't fully loaded until it's visible.
If I have to SetFocus to a control when the form is loaded, I do it in the
Form_Activate event.
 Have a look at the "Form_Load vs. Form_Activate" setion of this web page:
http://www.vb6.us/tutorials/understanding-forms-vb6-tutorial

Regards
       John (john@jeasonNoSpam.cix.co.uk) Remove the obvious to reply...

[toc] | [prev] | [next] | [standalone]


#2140

FromGS <gs@somewhere.net>
Date2014-08-28 20:46 -0400
Message-ID<ltoih7$e6c$1@dont-email.me>
In reply to#2139
> I'm quite surprised it works at all TBH. Trying to SetFocus to a 
> control in
> Form_Load causes an error because the control isn't fully loaded 
> until it's visible.
> If I have to SetFocus to a control when the form is loaded, I do it 
> in the
> Form_Activate event.
>  Have a look at the "Form_Load vs. Form_Activate" setion of this web 
> page:
> http://www.vb6.us/tutorials/understanding-forms-vb6-tutorial
>
> Regards
>        John (john@jeasonNoSpam.cix.co.uk) Remove the obvious to 
> reply...

Hi John,
That makes sense! I'll look at switching that around so I can remove 
the OERN. The only reason this code is 'as is' was to make it portabe 
between VB6 and VBA. Using the _Activate event may upset the focus set 
to other controls based on user interaction. It might be better to move 
this into the caller right after .Show, then!

I appreciate your input...

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#2141

FromGS <gs@somewhere.net>
Date2014-08-28 20:49 -0400
Message-ID<ltoim6$eum$1@dont-email.me>
In reply to#2140
Oops.., typo!

> That makes sense! I'll look at switching that around so I can remove 

  the OERN. The only reason this code is 'as is' was to make it 
portable

> between VB6 and VBA. Using the _Activate event may upset the focus 
> set to other controls based on user interaction. It might be better 
> to move this into the caller right after .Show, then!

Also, VBA uses an _Initialize event and SetFocus works just fine!

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#2142

FromGS <gs@somewhere.net>
Date2014-08-28 20:58 -0400
Message-ID<ltoj7q$hjb$1@dont-email.me>
In reply to#2139
Bingo! Form_Activate gets it done much better!
Big thanks...

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#2147

Fromjohn@jeasonNoSpam.cix.co.uk (John K.Eason)
Date2014-08-29 12:16 +0100
Message-ID<memo.20140829121625.4960A@jeason.cix.co.uk>
In reply to#2142
In article <ltoj7q$hjb$1@dont-email.me>, gs@somewhere.net (GS) wrote:

> Bingo! Form_Activate gets it done much better!
> Big thanks...

As both the article and obiwan say, don't forget a 'form loading' semaphore or you
could end up with unexpected results!

Regards
       John (john@jeasonNoSpam.cix.co.uk) Remove the obvious to reply...

[toc] | [prev] | [next] | [standalone]


#2148

FromGS <gs@somewhere.net>
Date2014-08-29 07:42 -0400
Message-ID<ltpp04$7hp$1@dont-email.me>
In reply to#2147
> In article <ltoj7q$hjb$1@dont-email.me>, gs@somewhere.net (GS) wrote:
>
>> Bingo! Form_Activate gets it done much better!
>> Big thanks...
>
> As both the article and obiwan say, don't forget a 'form loading' 
> semaphore or you could end up with unexpected results!
>
> Regards
>        John (john@jeasonNoSpam.cix.co.uk) Remove the obvious to 
> reply...

Yes.., I agree! Thanks again for contributing further to my learning 
process.

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#2143

FromObiWan <obiwan@mvps.org>
Date2014-08-29 09:53 +0200
Message-ID<20140829095319.000000c1@albasani.net>
In reply to#2138
:: On Thu, 28 Aug 2014 17:55:08 -0400
:: (comp.lang.basic.visual.misc,microsoft.public.vb.general.discussion)
:: <lto8fv$jna$1@dont-email.me>
:: GS <gs@somewhere.net> wrote:

> Does anyone have any idea why \win8 throws an error?

when the load event fires, you aren't guaranteed that all the controls
on the form have already been drawn and in some cases the setfocus
throws an error so it's common practice moving the "setfocus" into the
"Activate" event; to avoid repeating the setfocus over and over just
add a static boolean variable and use it as a semaphore; for example

Sub Form_Activate()
  Static bFirstTime As Boolean

  If Not bFirstTime Then
    bFirstTime = True
    txtLicenseKey.SetFocus
  End If
End Sub




[toc] | [prev] | [next] | [standalone]


#2144

FromGS <gs@somewhere.net>
Date2014-08-29 05:37 -0400
Message-ID<ltphka$n69$1@dont-email.me>
In reply to#2143
>>> On Thu, 28 Aug 2014 17:55:08 -0400
>>> (comp.lang.basic.visual.misc,microsoft.public.vb.general.discussion)
>>> <lto8fv$jna$1@dont-email.me>
>>> GS <gs@somewhere.net> wrote:
>
>> Does anyone have any idea why \win8 throws an error?
>
> when the load event fires, you aren't guaranteed that all the 
> controls on the form have already been drawn and in some cases the 
> setfocus throws an error so it's common practice moving the 
> "setfocus" into the "Activate" event; to avoid repeating the setfocus 
> over and over just add a static boolean variable and use it as a 
> semaphore; for example
>
> Sub Form_Activate()
>   Static bFirstTime As Boolean
>
>   If Not bFirstTime Then
>     bFirstTime = True
>     txtLicenseKey.SetFocus
>   End If
> End Sub

Thank you.., that's a great idea! As it happens, the code is about 10 
years old but the Form has been revised from a multi-use component to a 
dedicated one. That means my concern for repeating SetFocus in this 
case is now mute.

When the Form was multi-use I was managing 'pages' using frame controls 
and a 'ShowPage' routine. Each 'page' was used in a specific 'AppMode' 
state which was checked each time the form was loaded. (No 
multi-instancing)

I use the same code and form design in my VBA projects and so is why 
the OERN statement persisted. VBA uses an _Initialize event (instead of 
_Load) and so behaves differently in that SetFocus works without error. 
Now that I have recently made identical frm components for both VB6/VBA 
projects, I can update the component code specific to each. Both still 
use the same .bas component and so are named the same in either project 
environment.

Initially, both VB6/VBA projects used the same component for app 
startup where my VBA projects use a VB6.exe 'frontloader' to load the 
VBA project into an automated instance of MSO Excel. In the VB6 apps 
the user could always enter a LicenseKey at runtime (when LicenseStatus 
= TrialVer) as well as during startup. The VBA apps (inconveniently) 
could only do this during startup (via the frontloader) until recently 
when I added a MSO Userform duplicate of the VB6 Form. Both use the 
presence of a value stored in the 'app.ini' file to determine license 
'state'; a blank value sets LicenseStatus to 0 (TrialVer), and a 
non-blank value sets to 1 (Licensed). The ini file gets read at startup 
in InitGlobals(), and so this now happens twice with VBA projects. Both 
can reset this during runtime so next startup knows how to configure 
the workspace to hide the 'Register...' menuitem used to display the 
frm component. The VBA project does not check if it's licensed or not 
because the only way it runs is if its frontloader determines a valid 
LicenseStatus (ie: NOT 'Expired')

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#2145

FromGS <gs@somewhere.net>
Date2014-08-29 05:44 -0400
Message-ID<ltpi1k$q88$1@dont-email.me>
In reply to#2144
I posted incorrect values for the LicenseStatus...

  Expired=0
  TrialVer=1
  Licensed=2

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#2146

FromObiWan <obiwan@mvps.org>
Date2014-08-29 12:59 +0200
Message-ID<20140829125948.00000dd7@albasani.net>
In reply to#2144
:: On Fri, 29 Aug 2014 05:37:10 -0400
:: (comp.lang.basic.visual.misc,microsoft.public.vb.general.discussion)
:: <ltphka$n69$1@dont-email.me>
:: GS <gs@somewhere.net> wrote:

> > it as a semaphore; for example
> >
> > Sub Form_Activate()
> >   Static bFirstTime As Boolean
> >
> >   If Not bFirstTime Then
> >     bFirstTime = True
> >     txtLicenseKey.SetFocus
> >   End If
> > End Sub
> 
> Thank you.., that's a great idea! As it happens, the code is about 10 
> years old but the Form has been revised from a multi-use component to

just in case, change the code this way

Sub Form_Activate()
  Static bInitFlag As Boolean

  ' enter only once
  If bInitFlag Then Exit Sub
  bInitFlag = True

  ' add here your one time code
  txtLicenseKey.SetFocus
  '....more code....
End Sub


not that the other code is wrong, but I think the above is cleaner and
avoids wrapping the "one time" code inside the "if" block :)

[toc] | [prev] | [next] | [standalone]


#2149

FromGS <gs@somewhere.net>
Date2014-08-29 07:55 -0400
Message-ID<ltppn7$cjt$1@dont-email.me>
In reply to#2146
>>> On Fri, 29 Aug 2014 05:37:10 -0400
>>> (comp.lang.basic.visual.misc,microsoft.public.vb.general.discussion)
>>> <ltphka$n69$1@dont-email.me>
>>> GS <gs@somewhere.net> wrote:
>
>>> it as a semaphore; for example
>>> 
>>> Sub Form_Activate()
>>>   Static bFirstTime As Boolean
>>> 
>>>   If Not bFirstTime Then
>>>     bFirstTime = True
>>>     txtLicenseKey.SetFocus
>>>   End If
>>> End Sub
>> 
>> Thank you.., that's a great idea! As it happens, the code is about 
>> 10  years old but the Form has been revised from a multi-use 
>> component to
>
> just in case, change the code this way
>
> Sub Form_Activate()
>   Static bInitFlag As Boolean
>
>   ' enter only once
>   If bInitFlag Then Exit Sub
>   bInitFlag = True
>
>   ' add here your one time code
>   txtLicenseKey.SetFocus
>   '....more code....
> End Sub
>
>
> not that the other code is wrong, but I think the above is cleaner 
> and avoids wrapping the "one time" code inside the "if" block :)

Either example still evals an If...Then so I'm going to say that 
'cleaner' to me means the 1st example because it more concisely does 
the job!<g>... This example is better (IMO) where the code that follows 
the check is lengthy, in which case I prefer to exit early.

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.basic.visual.misc


csiph-web