OVH Cloud OVH Cloud

VBScript et formulaires VB

3 réponses
Avatar
nick
Bonjour,

Est-il possible de charger un formulaire VB (.frm) en
VBScript ?
Si oui, j'aurais besoin de l'instruction permettant de le
faire.

PAr avance, Merci

3 réponses

Avatar
Zoury
Salut Nick!

pas directement... tu peux cependant te compiler une dll contenant le formulaire
et une classe d'accès et y accéder à partir du script VBS.

Exemple :

Dans un project de type ActiveX DLL :

- Ajoute un formulaire au projet
- Ouvre le menu [Project/Project1 Properties] et change le [Project Name] pour
InputBox
- Colle les parties de suivantes au endroit prévues :
'***
' Form1
' 2 CommandButtons
' 1 TextBox
' 1 Label
Option Explicit

Private m_sTitle As String
Private m_sPrompt As String
Private m_sDefault As String
Private m_sValue As String
Private m_rm As eReturnMode

Public Enum eReturnMode
rmCancel = 0
rmOk = 1
End Enum

Private Sub Command1_Click()
m_sValue = Text1.Text
m_rm = rmOk
Me.Hide
End Sub

Private Sub Command2_Click()
m_rm = rmCancel
Me.Hide
End Sub

Private Sub Form_Load()

Me.Move Me.Left, Me.Top, 4800, 1875
Command2.Move 2280, 960, 1095, 375
Text1.Move 120, 600, 4455, 285
Command1.Move 3480, 960, 1095, 375
Label1.Move 120, 240, 4455, 255

Me.Caption = m_sTitle
Label1.Caption = m_sPrompt
Command1.Caption = "&Ok"
Command2.Caption = "&Cancel"
Text1.Text = m_sDefault

Command1.TabIndex = 0
Command2.TabIndex = 0
Text1.TabIndex = 0

End Sub

Property Get Value() As String
Value = m_sValue
End Property

Property Let Title(ByRef sTitle As String)
m_sTitle = sTitle
End Property

Property Let Prompt(ByRef sPrompt As String)
m_sPrompt = sPrompt
End Property

Property Let Default(ByRef sDefault As String)
m_sDefault = sDefault
End Property

Property Get ReturnMode() As eReturnMode
ReturnMode = m_rm
End Property

Private Sub Text1_GotFocus()
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End Sub

'---

' CInputBox
Option Explicit

Public Function GetInput _
( _
ByRef sTitle As String, _
ByRef sPrompt As String, _
ByRef sDefault As String, _
Optional ByRef bModal As Boolean = True _
) As String

Form1.Title = sTitle
Form1.Prompt = sPrompt
Form1.Default = sDefault
If bModal Then
Form1.Show vbModal
Else
Form1.Show
End If
GetInput = Form1.Value

End Function
'***
- Compile le projet.

Dans un fichier htm :

- Ajoute le code suivant
'***
<html>
<body>
<script type="text/vbscript">
Option Explicit

dim ib
Set ib = CreateObject("InputBox.CInputBox")

Call MsgBox(ib.GetInput("Mon InputBox", "Entrez du texte : ", "Entrer du texte
ici", True))

</script>
</body>
</html>
'***
- Sauvegarde et "démarre" le .htm


ps : je vais te joindre le projet dans le message subséquent ;O)

--
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/
"nick" wrote in message
news:086a01c33fc7$e1c12840$
: Bonjour,
:
: Est-il possible de charger un formulaire VB (.frm) en
: VBScript ?
: Si oui, j'aurais besoin de l'instruction permettant de le
: faire.
:
: PAr avance, Merci
Avatar
nick
Bon, c'est pas ce qu'il y a de plus simple.

Merci beaucoup pour tes explications, mais je pense que
je vais simplement apeller une page html sans bordures
pour faire remplacer le form.



-----Message d'origine-----
Voici l'exemple

il faut enregistrer la dll. puor y parvenir tu ouvre la


fenêtre Exécuter et tu
tapes :

regsvr32 "mon_répertoireInputBox.dll"

--
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/
"Zoury" wrote in message
news:
: Salut Nick!
:
: pas directement... tu peux cependant te compiler une


dll contenant le
formulaire
: et une classe d'accès et y accéder à partir du script


VBS.
:
: Exemple :
:
: Dans un project de type ActiveX DLL :
:
: - Ajoute un formulaire au projet
: - Ouvre le menu [Project/Project1 Properties] et


change le [Project Name] pour
: InputBox
: - Colle les parties de suivantes au endroit prévues :
: '***
: ' Form1
: ' 2 CommandButtons
: ' 1 TextBox
: ' 1 Label
: Option Explicit
:
: Private m_sTitle As String
: Private m_sPrompt As String
: Private m_sDefault As String
: Private m_sValue As String
: Private m_rm As eReturnMode
:
: Public Enum eReturnMode
: rmCancel = 0
: rmOk = 1
: End Enum
:
: Private Sub Command1_Click()
: m_sValue = Text1.Text
: m_rm = rmOk
: Me.Hide
: End Sub
:
: Private Sub Command2_Click()
: m_rm = rmCancel
: Me.Hide
: End Sub
:
: Private Sub Form_Load()
:
: Me.Move Me.Left, Me.Top, 4800, 1875
: Command2.Move 2280, 960, 1095, 375
: Text1.Move 120, 600, 4455, 285
: Command1.Move 3480, 960, 1095, 375
: Label1.Move 120, 240, 4455, 255
:
: Me.Caption = m_sTitle
: Label1.Caption = m_sPrompt
: Command1.Caption = "&Ok"
: Command2.Caption = "&Cancel"
: Text1.Text = m_sDefault
:
: Command1.TabIndex = 0
: Command2.TabIndex = 0
: Text1.TabIndex = 0
:
: End Sub
:
: Property Get Value() As String
: Value = m_sValue
: End Property
:
: Property Let Title(ByRef sTitle As String)
: m_sTitle = sTitle
: End Property
:
: Property Let Prompt(ByRef sPrompt As String)
: m_sPrompt = sPrompt
: End Property
:
: Property Let Default(ByRef sDefault As String)
: m_sDefault = sDefault
: End Property
:
: Property Get ReturnMode() As eReturnMode
: ReturnMode = m_rm
: End Property
:
: Private Sub Text1_GotFocus()
: Text1.SelStart = 0
: Text1.SelLength = Len(Text1.Text)
: End Sub
:
: '---
:
: ' CInputBox
: Option Explicit
:
: Public Function GetInput _
: ( _
: ByRef sTitle As String, _
: ByRef sPrompt As String, _
: ByRef sDefault As String, _
: Optional ByRef bModal As Boolean = True _
: ) As String
:
: Form1.Title = sTitle
: Form1.Prompt = sPrompt
: Form1.Default = sDefault
: If bModal Then
: Form1.Show vbModal
: Else
: Form1.Show
: End If
: GetInput = Form1.Value
:
: End Function
: '***
: - Compile le projet.
:
: Dans un fichier htm :
:
: - Ajoute le code suivant
: '***
: <html>
: <body>
: <script type="text/vbscript">
: Option Explicit
:
: dim ib
: Set ib = CreateObject("InputBox.CInputBox")
:
: Call MsgBox(ib.GetInput("Mon InputBox", "Entrez du


texte : ", "Entrer du texte
: ici", True))
:
: </script>
: </body>
: </html>
: '***
: - Sauvegarde et "démarre" le .htm
:
:
: ps : je vais te joindre le projet dans le message


subséquent ;O)
:
: --
: 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/
: "nick" wrote in message
: news:086a01c33fc7$e1c12840$
: : Bonjour,
: :
: : Est-il possible de charger un formulaire VB (.frm) en
: : VBScript ?
: : Si oui, j'aurais besoin de l'instruction permettant


de le
: : faire.
: :
: : PAr avance, Merci
:



Avatar
Zoury
J'ai oublié quelque chose de *très* important. :Oo

: Public Function GetInput _
: ( _
: ByRef sTitle As String, _
: ByRef sPrompt As String, _
: ByRef sDefault As String, _
: Optional ByRef bModal As Boolean = True _
: ) As String
:
: Form1.Title = sTitle
: Form1.Prompt = sPrompt
: Form1.Default = sDefault
: If bModal Then
: Form1.Show vbModal
: Else
: Form1.Show
: End If
: GetInput = Form1.Value


Unload Form1


:
: End Function



aahhh.. là c'est mieux! :O)


--
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/