Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

VB6 - passage de UserControl en parametre a une procédure

5 réponses
Avatar
carole
Dans un projet VB6, Je désire passer en paramètre à une procédure globale,
un objet UserControl.



Je passe déjà des objets feuilles en paramètres à des procédures, mais je
n'ai pas trouve comment faire dans le cas d'un objet UserControl



merci de vos reponses

5 réponses

Avatar
Zoury
Salut Carole! :O)

Tu n'as qu'à typé le paramètre avec le Nom du contrôle. Tu peux aussi le
passé As Control mais ce sera plus lent et tu n'auras pas l'intellisense..

'***
' MyControl est le nom du UserControl
Private Sub MySub(ByRef ctl As MyControl)
End Sub
'***

--
Cordialement
Yanick Lefebvre - MVP pour Visual Basic
http://faq.vb.free.fr/?rubrique=0 - http://www.mvps.org/vbnet/
http://www.mentalis.org/agnet/apiguide.shtml - http://www.mztools.com/
"carole" wrote in message
news:eOg$
Dans un projet VB6, Je désire passer en paramètre à une procédure globale,
un objet UserControl.



Je passe déjà des objets feuilles en paramètres à des procédures, mais je
n'ai pas trouve comment faire dans le cas d'un objet UserControl



merci de vos reponses








Avatar
carole
non ca ne marche pas, j'ai essaye


"Zoury" wrote in message
news:
Salut Carole! :O)

Tu n'as qu'à typé le paramètre avec le Nom du contrôle. Tu peux aussi le
passé As Control mais ce sera plus lent et tu n'auras pas l'intellisense..

'***
' MyControl est le nom du UserControl
Private Sub MySub(ByRef ctl As MyControl)
End Sub
'***

--
Cordialement
Yanick Lefebvre - MVP pour Visual Basic
http://faq.vb.free.fr/?rubrique=0 - http://www.mvps.org/vbnet/
http://www.mentalis.org/agnet/apiguide.shtml - http://www.mztools.com/
"carole" wrote in message
news:eOg$
> Dans un projet VB6, Je désire passer en paramètre à une procédure


globale,
> un objet UserControl.
>
>
>
> Je passe déjà des objets feuilles en paramètres à des procédures, mais


je
> n'ai pas trouve comment faire dans le cas d'un objet UserControl
>
>
>
> merci de vos reponses
>
>
>
>
>
>




Avatar
Zoury
peut-on voir ton code?
tu obtiens une erreur?

' voici un exemple qui fonctionne ici..
' 1 projet ActiveX Exe
' 1 Form
' 1 projet ActiveX Control
' 1 UserControl
'
' projet ActiveX Exe
'***
' Form1 - Form
' 1 MyControl
Option Explicit

Private Sub DoStuff(ByRef ctl As MyControl)
Debug.Print ctl.CryptedText
End Sub

Private Sub MyControl1_Click()
Call DoStuff(MyControl1)
End Sub
'***
'
' projet ActiveX Control
'***
' MyControl - UserControl
' 1 CommandButton
Option Explicit

Private m_sCryptedText As String
Public Event Click()

Private Sub Command1_Click()
RaiseEvent Click
End Sub

Private Sub UserControl_Initialize()
Call DoStuff(Me)
End Sub

Private Sub UserControl_Resize()
Call Command1.Move(0, 0, UserControl.ScaleWidth, UserControl.Height)
End Sub

Public Property Get CryptedText() As String
CryptedText = m_sCryptedText
End Property

Public Property Let Text(ByRef sText As String)
m_sCryptedText = Chr$(Asc(sText) Xor 5)
End Property

Private Sub DoStuff(ByRef ctl As MyControl)
ctl.Text = "a"
End Sub
'***

dans les 2 projets la fonction DoStuff() reçoit le controle en paramètre et
ce dernier est bien typé

--
Cordialement
Yanick Lefebvre - MVP pour Visual Basic
http://faq.vb.free.fr/?rubrique=0 - http://www.mvps.org/vbnet/
http://www.mentalis.org/agnet/apiguide.shtml - http://www.mztools.com/
Avatar
carole
voila mon code
la procedure globale :

public Sub Couleur_UserControl(Usr As UserControl)
On Error GoTo error_color
' code .....
end sub

et l'appel a la procédure depuis un usercontrol :

Private Sub UserControl_Initialize()
Couleurs_UserControl ucl_EICC
End Sub

ucl_eicc est le nom du control : j'obtiens une erreur de compil, si je met
"usercontrol" ala place j'ai une erreur aussi.

pour un objet form ca fonctionne tres bien :

Public Sub Couleur_Feuille(Feuille As Form)
' code
end sub

appel depuis une feuille :

Private Sub Form_Load()
Couleur_Feuille Me
end sub




"Zoury" wrote in message
news:%
peut-on voir ton code?
tu obtiens une erreur?

' voici un exemple qui fonctionne ici..
' 1 projet ActiveX Exe
' 1 Form
' 1 projet ActiveX Control
' 1 UserControl
'
' projet ActiveX Exe
'***
' Form1 - Form
' 1 MyControl
Option Explicit

Private Sub DoStuff(ByRef ctl As MyControl)
Debug.Print ctl.CryptedText
End Sub

Private Sub MyControl1_Click()
Call DoStuff(MyControl1)
End Sub
'***
'
' projet ActiveX Control
'***
' MyControl - UserControl
' 1 CommandButton
Option Explicit

Private m_sCryptedText As String
Public Event Click()

Private Sub Command1_Click()
RaiseEvent Click
End Sub

Private Sub UserControl_Initialize()
Call DoStuff(Me)
End Sub

Private Sub UserControl_Resize()
Call Command1.Move(0, 0, UserControl.ScaleWidth, UserControl.Height)
End Sub

Public Property Get CryptedText() As String
CryptedText = m_sCryptedText
End Property

Public Property Let Text(ByRef sText As String)
m_sCryptedText = Chr$(Asc(sText) Xor 5)
End Property

Private Sub DoStuff(ByRef ctl As MyControl)
ctl.Text = "a"
End Sub
'***

dans les 2 projets la fonction DoStuff() reçoit le controle en paramètre e


t
ce dernier est bien typé

--
Cordialement
Yanick Lefebvre - MVP pour Visual Basic
http://faq.vb.free.fr/?rubrique=0 - http://www.mvps.org/vbnet/
http://www.mentalis.org/agnet/apiguide.shtml - http://www.mztools.com/




Avatar
Zoury
et ça, ça marche?

public Sub Couleur_UserControl(Usr As ucl_EICC)
On Error GoTo error_color
' code .....
end sub

Private Sub UserControl_Initialize()
Couleurs_UserControl Me
End Sub


--
Cordialement
Yanick Lefebvre - MVP pour Visual Basic
http://faq.vb.free.fr/?rubrique=0 - http://www.mvps.org/vbnet/
http://www.mentalis.org/agnet/apiguide.shtml - http://www.mztools.com/