Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass VB Checkbox value to VBScript

Status
Not open for further replies.

bneese

Technical User
Nov 16, 2003
20
US
I am writing a VB form that is called from a vb script to display login info for our domain login script. I am able to pass variables to the VB app from my vbscript, but I want to pass the values to my vbscript from the VB. Basically I have a check box on the VB app that I want to read from the vbscript and tell the vbscript to pause or stop.
 
That is a good suggestion. I wonder what the speed is like... I went to the link but I couldn't see any sample scripts. Can you email me some of them? I would like to take a look. Thanks for the info
 
bneese,

Here is a sample FORM that I've actually used to assist someone with doing a Backup. Keep in mind, that this is only the portion that sets up the form.
Code Segment:
Code:
Sub Create_Form1(sCaption)

Dim oLWF
Set oLWF = WScript.CreateObject("wshLWForm.ucLWF", "oLWF_")

' create the form 'window'... 
oLWF.CreateForm 150, 150, 350, 325, CStr(sCaption) 

' add controls to the form 'window'... 
'   (these controls were added by the Form Designer)... 
oLWF.AddLabel 79,10, 190,10, "+---------------------------------------------------------+"
oLWF.AddLabel 80,20, 190,15, "|  R K O M   B a c k u p   O p t i o n s  |"
oLWF.AddLabel 79,30, 190,10, "+---------------------------------------------------------+"

oLWF.AddLabel 10,40, 330,10, "---------------------------------------------------------------------------------------------------------"

oLWF.AddLabel 25,50, 90,15, "Day"
oLWF.AddLabel 155,50, 90,15, "Month"
oLWF.AddLabel 295,50, 90,15, "Year"

oLWF.AddLabel 10,60, 330,10, "---------------------------------------------------------------------------------------------------------"

oLWF.AddoptBtn 10,80, 90,15, "Monday"
oLWF.AddoptBtn 10,100, 90,15, "Tuesday"
oLWF.AddoptBtn 10,120, 90,15, "Wednesday"
oLWF.AddoptBtn 10,140, 90,15, "Thursday"
oLWF.AddoptBtn 10,160, 90,15, "Friday"
oLWF.AddoptBtn 10,180, 90,15, "Saturday"
oLWF.AddoptBtn 10,200, 90,15, "Sunday"
oLWF.AddoptBtn 10,220, 90,15, "Emergency"

oLWF.AddoptBtn 100,100, 90,15, "January"
oLWF.AddoptBtn 100,120, 90,15, "February"
oLWF.AddoptBtn 100,140, 90,15, "March"
oLWF.AddoptBtn 100,160, 90,15, "April"
oLWF.AddoptBtn 100,180, 90,15, "May"
oLWF.AddoptBtn 100,200, 90,15, "June"

oLWF.AddoptBtn 120,240, 150,15, "QUIT (No Backup)"

oLWF.AddoptBtn 190,100, 90,15, "July"
oLWF.AddoptBtn 190,120, 90,15, "August"
oLWF.AddoptBtn 190,140, 90,15, "September"
oLWF.AddoptBtn 190,160, 90,15, "October"
oLWF.AddoptBtn 190,180, 90,15, "November"
oLWF.AddoptBtn 190,200, 90,15, "December"

oLWF.AddoptBtn 280,80, 90,15, "2004"
oLWF.AddoptBtn 280,100, 90,15, "2005"
oLWF.AddoptBtn 280,120, 90,15, "2006"
oLWF.AddoptBtn 280,140, 90,15, "2007"
oLWF.AddoptBtn 280,160, 90,15, "2008"
oLWF.AddoptBtn 280,180, 90,15, "2009"
oLWF.AddoptBtn 280,200, 90,15, "2010"
oLWF.AddoptBtn 280,220, 90,15, "2011"

oLWF.AddcmdBtn 95,265, 160,25, "Continue..."

Dim oForm : Set oForm = oLWF.frmDialog  ' get ref to "form object"

oForm.OptBtn(15).Value = True  ' pre-select "QUIT (No Backup)"

oLWF.ShowForm  ' show the form (Modally)

For i = 1 to oForm.optBtn.Count - 1
	if oForm.optBtn(i).Value  then  
			sResult = oForm.optBtn(i).Caption
			SourcePath = "C:\RKom"
			Select Case oForm.optBtn(i).Caption
				Case "Monday"
					BackupType = "MON"
				Case "Tuesday"
					BackupType = "TUE"
				Case "Wednesday"
					BackupType = "WED"
				Case "Thursday"
					BackupType = "THU"
				Case "Friday"
					BackupType = "FRI"
				Case "Saturday"
					BackupType = "SAT"
				Case "Sunday"
					BackupType = "SUN"
				Case "Emergency"
					BackupType = "EMG"
				Case "January"
					BackupType = "JAN"
				Case "February"
					BackupType = "FEB"
				Case "March"
					BackupType = "MAR"
				Case "April"
					BackupType = "APR"
				Case "May"
					BackupType = "MAY"
				Case "June"
					BackupType = "JUN"
				Case "July"
					BackupType = "JUL"
				Case "August"
					BackupType = "AUG"
				Case "September"
					BackupType = "SEP"
				Case "October"
					BackupType = "OCT"
				Case "November"
					BackupType = "NOV"
				Case "December"
					BackupType = "DEC"
				Case "2004"
					BackupType = "2004"
				Case "2005"
					BackupType = "2005"
				Case "2006"
					BackupType = "2006"
				Case "2007"
					BackupType = "2007"
				Case "2008"
					BackupType = "2008"
				Case "2009"
					BackupType = "2009"
				Case "2010"
					BackupType = "2010"
				Case "2011"
					BackupType = "2011"
				Case ""
					BackupType = "NONE"
			End Select
			sResult = PrintOption
		else
	end if
Next  ' i

' finished with adding form's controls, so return... 
End Sub
Now, this form does not do Check Boxes, but to do check boxes, all you have to do is change the 'AddOptBtn' with 'AddChkBox'.
There are some sample scripts on that site that you can download and look at, however, they sometimes seem confusing, as I did not write them.
I'll look for some more code and post it here later.

-SWarrior
 
Thanks for the post. What I am actually looking for is the VBSCRIPT that would be able to read form check box.
 
Hello bneese!

I've written a FAQ on passing and returning values between scripts. Some of the same principles should apply for VB.

faq329-5755

Good luck!
 
bneese,

Check Box ?? Check box would be either on or off / true or false. If that is what you need, then you'll assign a variable accordingly.....

Based on the code above, use something like this instead:
Code:
---CODE SNIP---
oLWF.AddCtrl "chkBox", 15,20, 100,20, "Office 2000 Std"
oLWF.AddCtrl "chkBox", 15,40, 100,20, "Office 2000 Pro" oLWF.AddCtrl "chkBox", 15,60, 120,20, "JavaRuntime 1.4.2"
---CODE SNIP---


---CODE SNIP---
Dim sResult 
For i = 1 to oForm.chkBox.Count - 1
 if oForm.chkBox(i).Value  then  
  Select Case oForm.chkBox(i).Caption
   Case "Office 2000 Std"
    rc=wshshell.run("cmd /c ""\\" & Server1 & "\public01$\O2Ksr1STD\Setup.exe""",1,True)
   Case "Office 2000 Pro"
    rc=wshshell.run("cmd /c ""\\" & Server1 & "\public01$\O2Ksr1PRO\Setup.exe""",1,True)
    if msgbox("Click 'YES' to Install Office 2000 Pro Disk #2"& VbCrLf &"or 'NO' to Cancel.", vbYesNo + vbDefaultButton1 + vbQuestion + VbMsgBoxSetForeground, "Install Office 2000 Pro Disk #2") = vbYes Then
     rc=wshshell.run("cmd /c ""\\" & Server1 & "\public01$\O2Ksr1PRO\Disk2\Setup.exe""",1,True)
    end if
   Case "JavaRuntime 1.4.2"
    rc=wshshell.run("cmd /c ""\\" & Server8 & "\domain-admins\Software\Java\j2re-1_4_2_04-windows-i586-p.exe""",1,True)
   End Select
  else
 end if
Next  ' i
---CODE SNIP---

This should give you some insight on the CheckBoxes.

-SWarrior
 
I didn't create something like that until now, but I this this is the way I would do it:

Trigger the vb-Form using wShell.run in vbscript with the wait option set to be able to read out the returncode of the vb-Form.

Create the vb-Form in a way to give information back using returncodes.
Example returnvalue = 0101 1111 (in binary format)
each digit represents a true or false value for a certain option (checkbox?)

Hope this was helpfull

Please tell me if I'm wrong I like to learn from my mistakes...
_____________________________________
Feed a man a fish and feed him for a day.
Teach a man to fish and feed him for a lifetime...
 
If you are looking to do something like that, then you could code it like this:
Code:
Results = 0
' wshLWF - Form Designer Test Form Output...
Dim oLWF  ' as Object
Const sCaption = "On/Off Test" 

  ' instantiate wshLiteWeightForm... 
On Error Resume Next  ' turn on error checking 
Set oLWF = WScript.CreateObject("wshLtWtForm.ucLWF", "oLWF_") 
 if err.number <> 0 then 
   MsgBox("You MUST register wshLWForm ocx before using!!!") 
   WScript.Quit 
 End If 

On Error goto 0  ' resume normal error processing... 

Call Create_Form3(sCaption)	

msgbox("Results " & Results)

WScript.quit


Sub Create_Form3(sCaption)

  ' create the form 'window'... 
  oLWF.CreateForm 50, 50, 525, 350, CStr(sCaption) 

  ' add controls to the form 'window'... 
  '   (these controls were added by the Form Designer)... 
  oLWF.AddCtrl "Label", 125,240, 350,25, "* Require Independent Installs and/or System Reboots"
  oLWF.AddCtrl "Label", 75,300, 400,25, "NOTE: If Prompted choose NO for a Reboot During normal software install."

  oLWF.AddCtrl "Frame", 5,5, 505,225, "Software Install List"		'NT		2K
  oLWF.AddCtrl "chkBox", 15,20, 100,20, "Office 2000 Std"			' 1		1
  oLWF.AddCtrl "chkBox", 15,40, 100,20, "Office 2000 Pro"			' 2		2
  oLWF.AddCtrl "chkBox", 15,60, 120,20, "JavaRuntime 1.4.2"			' 3		3
  oLWF.AddCtrl "chkBox", 15,80, 100,20, "Outlook 2000"				' 4		4
  oLWF.AddCtrl "chkBox", 15,100, 100,20, "Outlook XP"				' 5		5

  oLWF.AddCtrl "cmdBtn", 175,260, 160,25, "Install Selected Software(s)"

Dim oForm : Set oForm = oLWF.frmDialog  ' get ref to "form object"

oLWF.ShowForm  ' show the form (Modally)

' after form is closed, then determine which Ctrl was selected:
Dim sResult 

Results = oForm.chkBox(1).Value & oForm.chkBox(2).Value & oForm.chkBox(3).Value & oForm.chkBox(4).Value & oForm.chkBox(5).Value

' clean up and go home...
Set oForm = nothing  ' don't need this anymore...
Set oLWF = nothing

End Sub

You can also have Check Boxes, Radio buttons, Combo Boxes, Text Boxes, all within the same form. Just keep in mind that the order is top/down for their numerical location.

-SWarrior
 
can you also hide the window bar on top to remove the close button? that is biggest thing I am trying to get rid of.
 
also, is there a way to add a memo box? If I am going to use this as a login script "GUI" then I will not know how much data will be displayed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top