PC Review


Reply
Thread Tools Rate Thread

Can I pass value from VB form to VBS?

 
 
D.P. Roberts
Guest
Posts: n/a
 
      22nd Mar 2005
I have 3 vbscripts and a vb form with radio buttons corresponding to each
script. The form's only purpose is to provide a nice GUI for the user to
decide which of the 3 scripts to run. Now, because the scripts are mostly
identical to one another, I'd really like to combine them into one script.
But I can't for the life of me figure out how to pass a radio button value
from a vb form to the script so the appropriate portion of the script is
executed based on which radio button was selected. Basically I need the
script to do something like this:

RBselection = <the radio button selected on the vb form>

Select Case RBselection
Case RadioButton1
varSelection = 1
Case RadioButton2
varSelection = 2
Case RadioButton3
varSelection = 3

If I could somehow do this, then I could use the varSelection value to run
the necessary parts of the script. Anyone know if this is possible?

Thanks in advance...



 
Reply With Quote
 
 
 
 
Dmitriy Antonov
Guest
Posts: n/a
 
      22nd Mar 2005
As I understand you are talking about WScript.
There is collection of command-line arguments in WScript object (which is
global object there and you don't need to declare it)

Then from your VB application you can call vbs like:

'this is code in VB to call vbs
Dim sComStr As String
'vbs file is just an argument of script engine (wscript.exe)
'you might need to "play" with paths to files
sComStr = "wscript.exe " & "test.vbs " & RBselection 'add argument
according to your radio-button selection
ChDir App.Path 'set current folder to that, where vbs file and
wscript.exe are located (I put them together into vb's project folder for
simplicity)
Shell sComStr 'note Shell command doesn't like paths with spaces - there
are ways around

For testing I've created the following small script (in my case it is
test.vbs)

dim varTest
If WScript.Arguments.Count then varTest=WScript.Arguments(0)
msgbox "Argument " & varTest


As a result, when I call this script with some value of RBselection, then
msgbox with this value is shown

Hope, this is what you need. If you still need to read VB's data from within
vbs, then your VB must be built as ActiveX component and then you can expose
its public interface to vbs via late binding.

Dmitriy,
MCSD.







"D.P. Roberts" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have 3 vbscripts and a vb form with radio buttons corresponding to each
>script. The form's only purpose is to provide a nice GUI for the user to
>decide which of the 3 scripts to run. Now, because the scripts are mostly
>identical to one another, I'd really like to combine them into one script.
>But I can't for the life of me figure out how to pass a radio button value
>from a vb form to the script so the appropriate portion of the script is
>executed based on which radio button was selected. Basically I need the
>script to do something like this:
>
> RBselection = <the radio button selected on the vb form>
>
> Select Case RBselection
> Case RadioButton1
> varSelection = 1
> Case RadioButton2
> varSelection = 2
> Case RadioButton3
> varSelection = 3
>
> If I could somehow do this, then I could use the varSelection value to run
> the necessary parts of the script. Anyone know if this is possible?
>
> Thanks in advance...
>
>
>



 
Reply With Quote
 
Jeff Johnson [MVP: VB]
Guest
Posts: n/a
 
      22nd Mar 2005

"D.P. Roberts" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

>I have 3 vbscripts and a vb form with radio buttons corresponding to each
>script.


Is this a VB.NET question or a "classic" VB (6 or earlier) question? Because
you have crossposted between .NET (*.dotnet.*) and non-.NET (*.vb.*) groups.
Pick one.


 
Reply With Quote
 
Andrew D. Newbould
Guest
Posts: n/a
 
      7th Apr 2005
In message <(E-Mail Removed)>, D.P. Roberts
<(E-Mail Removed)> writes
>I have 3 vbscripts and a vb form with radio buttons corresponding to each
>script. The form's only purpose is to provide a nice GUI for the user to
>decide which of the 3 scripts to run. Now, because the scripts are mostly
>identical to one another, I'd really like to combine them into one script.
>But I can't for the life of me figure out how to pass a radio button value
>from a vb form to the script so the appropriate portion of the script is
>executed based on which radio button was selected. Basically I need the
>script to do something like this:
>
>RBselection = <the radio button selected on the vb form>
>
>Select Case RBselection
> Case RadioButton1
> varSelection = 1
> Case RadioButton2
> varSelection = 2
> Case RadioButton3
> varSelection = 3
>
>If I could somehow do this, then I could use the varSelection value to run
>the necessary parts of the script. Anyone know if this is possible?
>
>Thanks in advance...
>
>
>


Rather than Shell out to execute the vbs scripts why not add the
ScriptControl to you VB6 program.

You can then load the script into it and use the AddObject method to
pass your variables into it. The safer way would be to define a small
dummy class containing the data you wish to pass, dim a local object to
that class and then use AddObject to pass the local object.

You then only have to put your existing code into a sub or function so
you can call it from VB. Worst case you could combine all three scripts
into one using three functions and use VB to call the one required.
Easy.

--
Andrew D. Newbould E-Mail: (E-Mail Removed)

ZAD Software Systems Web : www.zadsoft.com
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pass data from access form to intranet web based form matt campbell via AccessMonster.com Microsoft Access Form Coding 0 7th May 2006 04:25 PM
Command to pass Unbound Value on Form to Filter Sub Form Query orbojeff Microsoft Access Form Coding 0 21st Nov 2005 11:25 AM
Pass Input Text Field From 1 Form to Secondary Form =?Utf-8?B?Um9iZXJ0IE51c3ogQCBEUFM=?= Microsoft Access Forms 1 14th Dec 2004 03:16 PM
Is it possible to open the VBA form with a link in a sheet and to pass variable from a cell to the VBA form? Daniel Microsoft Excel Programming 1 29th Aug 2004 01:20 PM
How to pass values from Child form to parent form with Modeless Chandru Microsoft C# .NET 2 5th Dec 2003 10:31 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:25 PM.