From: Catharinus on
On 21 apr, 15:14, dwy <d...(a)discussions.microsoft.com> wrote:
> "Catharinus" wrote:
> > On 21 apr, 13:48, Catharinus <csvanderw...(a)planet.nl> wrote:
> > > On 21 apr, 12:45, "David Youngblood" <d...(a)flash.net> wrote:
>
> > > > "Catharinus" <csvanderw...(a)planet.nl> wrote...
> > > > > Hello to you all
>
> > > > > is it possible to programmatically add a maskedbox to a form at
> > > > > runtime?
>
> > > > Assuming the Masked Edit control library is referenced in the project,
>
> > > >     With Controls.Add("MSMask.MaskEdBox", "MaskEdBox1")
> > > >         .Move 100, 100, 1200, 350
> > > >         .Mask = "(###)-###-####"
> > > >         .Visible = True
> > > >         .SetFocus
> > > >     End With
>
> > > thnxs
>
> > > but I still get errors. For example the Mask-property
> > > maybe I should try better
> > > thanks for now
>
> > > Catharinus
>
> > I thought I should do it this way, because I want to use the mb
> > everywhere in the module:
> > when I use the code below, I get an error in the last line: type
> > mismatch
> > Private WithEvents mb As MaskEdBox
> > Private Sub Form_Load()
>
> >     Licenses.Add ("MSMASK.Maskedbox")
> >     Set mb = Nothing
> >     Set mb = Me.Controls.Add("MSMask.MaskEdBox", "MaskEdBox1")
> > end sub
>
> If you need events, why not add the control at design-time. I do not know of
> a way to add events at run-time, so what advantage is there to add the contol
> at run-time.
>
> That said, copied from a working project. Control was added to the project
> and "Remove information about unused ActiveX Controls" was unchecked in the
> project properties.
>
> Private WithEvents mb As MaskEdBox
>
> Private Sub Form_Load()
>     Set mb = Nothing
>     Set mb = Me.Controls.Add("MSMask.MaskEdBox", "MaskEdBox1")
>     With mb
>         .Move 100, 100, 1200, 350
>         .Mask = "(###)-###-####"
>         .Visible = True
>     End With
>     Me.Show
>     mb.SetFocus
> End Sub
>
> Private Sub mb_Change()
>     Debug.Print "MaskEdBox1.Change " & mb.Text
> End Sub- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -

I still get the error messag: type mismatch.
and vb also talks about a license-error, that can be solved with this
line of code
Licenses.Add ("MSMASK.Maskedbox")

I want to use the maskedbox this way, because I use it in a class
that can be called from any form that I want to use. Which is easier
than
alway add it at designtime
From: MikeD on


"Catharinus" <csvanderwerf(a)planet.nl> wrote in message
news:2e882cfe-ec6c-4e0f-8791-76468bb15911(a)c21g2000yqk.googlegroups.com...
>
> I still get the error messag: type mismatch.
> and vb also talks about a license-error, that can be solved with this
> line of code
> Licenses.Add ("MSMASK.Maskedbox")

It's not necessary to add to the Licenses collection IF you've added the
control to the Toolbox. Also, open up Project Properties. Go to the Make
tab. Make sure that "Remove information about unused ActiveX Controls" is
NOT checked. What this option does, when checked, is remove information
(including license information) if a control is not sited on a form (or
usercontrol) that is part of the project. In fact, I just tried your code
from your previous post and got this error message when attempting to add to
the Licenses collection: "The control 'MSMASK.Maskedbox' cannot be added to
the Licenses collection, because it is already referenced by the project.
It is not necessary to add controls that are referenced by the project." I
got that error regardless of whether the Remove information option was
checked or unchecked. On the line of code which adds to the Controls
collection, I got this error if that option was checked:
"'MSMask.MaskEdBox' cannot be added because it is referenced but not in use
by any items in the project. To correct this, uncheck 'Remove information
about unused ActiveX Controls' in Project Options." Doing as instructed
solved that error just like VB said. As to why you're getting a type
mismatch, I haven't a clue. Your code worked for me (well, after skipping
the line to add to the Licenses collection) with the Masked Edit Box added
to the toolbox (which it would HAVE to be in order to declare a variable of
type MaskEdBox).

>
> I want to use the maskedbox this way, because I use it in a class
> that can be called from any form that I want to use. Which is easier
> than
> alway add it at designtime

Not really. There are limitations when adding controls at runtime. Why
can't your class simply have a property to which you assign a reference to
the Masked Edit Box (or you could use a method and pass the reference, same
result in the long run) and the class can then use that reference? That's
why I do with a class module I wrote which adds functionality to a ListView
control. Much better than trying to add the control at runtime to a form's
Controls collection.

IMO, the dynamic control addition feature that was new to VB6 was only
"half-baked". It's an interesting and potentially useful functionality, but
MS just didn't quite get it right. Which makes it mostly worthless.

--
Mike


From: Catharinus on
On 21 apr, 23:24, "MikeD" <nob...(a)nowhere.edu> wrote:
> "Catharinus" <csvanderw...(a)planet.nl> wrote in message
>
> news:2e882cfe-ec6c-4e0f-8791-76468bb15911(a)c21g2000yqk.googlegroups.com...
>
>
>
> > I still get the error messag: type mismatch.
> > and vb also talks about a license-error, that can be solved with this
> > line of code
> > Licenses.Add ("MSMASK.Maskedbox")
>
> It's not necessary to add to the Licenses collection IF you've added the
> control to the Toolbox. Also, open up Project Properties.  Go to the Make
> tab.  Make sure that "Remove information about unused ActiveX Controls" is
> NOT checked. What this option does, when checked, is remove information
> (including license information) if a control is not sited on a form (or
> usercontrol) that is part of the project.  In fact, I just tried your code
> from your previous post and got this error message when attempting to add to
> the Licenses collection:  "The control 'MSMASK.Maskedbox' cannot be added to
> the Licenses collection, because it is already referenced by the project.
> It is not necessary to add controls that are referenced by the project." I
> got that error regardless of whether the Remove information option was
> checked or unchecked. On the line of code which adds to the Controls
> collection, I got this error if that option was checked:
> "'MSMask.MaskEdBox' cannot be added because it is referenced but not in use
> by any items in the project.  To correct this, uncheck 'Remove information
> about unused ActiveX Controls' in Project Options."  Doing as instructed
> solved that error just like VB said. As to why you're getting a type
> mismatch, I haven't a clue. Your code worked for me (well, after skipping
> the line to add to the Licenses collection) with the Masked Edit Box added
> to the toolbox (which it would HAVE to be in order to declare a variable of
> type MaskEdBox).
>
>
>
> > I want to use the maskedbox this way, because I use it in a class
> > that can be called from any form that I want to use. Which is easier
> > than
> > alway add it at designtime
>
> Not really.  There are limitations when adding controls at runtime.  Why
> can't your class simply have a property to which you assign a reference to
> the Masked Edit Box (or you could use a method and pass the reference, same
> result in the long run) and the class can then use that reference? That's
> why I do with a class module I wrote which adds functionality to a ListView
> control. Much better than trying to add the control at runtime to a form's
> Controls collection.
>
> IMO, the dynamic control addition feature that was new to VB6 was only
> "half-baked". It's an interesting and potentially useful functionality, but
> MS just didn't quite get it right.  Which makes it mostly worthless.
>
> --
> Mike

Thanks Mike for your suggestions. Could you give an example of what
you suggested
in the for last paragraph: a reference to the MaskedBOx?

thanks
Catharinus
From: Norm Cook on
"Catharinus" <csvanderwerf(a)planet.nl> wrote in message
news:ebebec86-0c8f-4eb2-bb44-1b1504052324(a)s9g2000yqa.googlegroups.com...
On 21 apr, 23:24, "MikeD" <nob...(a)nowhere.edu> wrote:
> "Catharinus" <csvanderw...(a)planet.nl> wrote in message
>
> news:2e882cfe-ec6c-4e0f-8791-76468bb15911(a)c21g2000yqk.googlegroups.com...
>
<Clipped for brevity>
Perhaps something like this (minimal testing):

'class module named cMaskedEdit
Option Explicit
Public Event KeyPress(KeyAscii As Integer)
Private WithEvents MB As MaskedBox
'Your properties, methods
Public Sub SetMB(MaskedBox As MaskedBox)
'could also be a Property Set
Set MB = MaskedBox
End Sub
Public Property Get Mask() As String
Mask = MB.Mask
End Property
Public Property Let Mask(ByVal NewVal As String)
MB.Mask = NewVal
End Property
'etc
'MaskEdBox events
Private Sub MB_Change()
'
End Sub

Private Sub MB_KeyPress(KeyAscii As Integer)
RaiseEvent KeyPress(KeyAscii)
End Sub
'etc

========================================
'Form with a Masked Edit Box
Option Explicit
Private WithEvents oMask As cMaskedEdit
Private Sub Form_Load()
Set oMask = New cMaskedEdit
oMask.SetMB MaskEdBox1
oMask.Mask = "###-###-####"
Debug.Print oMask.Mask
End Sub
Private Sub oMask_KeyPress(KeyAscii As Integer)
'whatever
End Sub


From: Catharinus on
On 22 apr, 14:16, "Norm Cook" <normc...(a)cableone.net> wrote:
> "Catharinus" <csvanderw...(a)planet.nl> wrote in message
>
> news:ebebec86-0c8f-4eb2-bb44-1b1504052324(a)s9g2000yqa.googlegroups.com...
> On 21 apr, 23:24, "MikeD" <nob...(a)nowhere.edu> wrote:> "Catharinus" <csvanderw...(a)planet.nl> wrote in message
>
> >news:2e882cfe-ec6c-4e0f-8791-76468bb15911(a)c21g2000yqk.googlegroups.com....
>
> <Clipped for brevity>
> Perhaps something like this (minimal testing):
>
> 'class module named cMaskedEdit
> Option Explicit
> Public Event KeyPress(KeyAscii As Integer)
> Private WithEvents MB As MaskedBox
> 'Your properties, methods
> Public Sub SetMB(MaskedBox As MaskedBox)
> 'could also be a Property Set
>  Set MB = MaskedBox
> End Sub
> Public Property Get Mask() As String
>  Mask = MB.Mask
> End Property
> Public Property Let Mask(ByVal NewVal As String)
>  MB.Mask = NewVal
> End Property
> 'etc
> 'MaskEdBox events
> Private Sub MB_Change()
> '
> End Sub
>
> Private Sub MB_KeyPress(KeyAscii As Integer)
>  RaiseEvent KeyPress(KeyAscii)
> End Sub
> 'etc
>
> ========================================
> 'Form with a Masked Edit Box
> Option Explicit
> Private WithEvents oMask As cMaskedEdit
> Private Sub Form_Load()
>  Set oMask = New cMaskedEdit
>  oMask.SetMB MaskEdBox1
>  oMask.Mask = "###-###-####"
>  Debug.Print oMask.Mask
> End Sub
> Private Sub oMask_KeyPress(KeyAscii As Integer)
>  'whatever
> End Sub

thanks Norm

I will try to build in this code in my MSHFlexgrid Class. That the
idea: use the maskedbox in a MSHFlexGrid. BTW. I want to us a property
set for th MaskEdbox. Could that be:
Public Property Set MBBox(Maskedbox as Maskedbox)
set MB=maskedbox
end sub
??
Thanks
Catharinus