Global/Public/Universal variables

M

Matthew Dyer

I have a question regarding the available scope of variables. I
understand that you can make variables function/routine specific,
module specific, project specific, etc. But here's my issue,

Currenly I am using a shell function to call a batch file which points
to an avaya cms script (coded in vb script, not sure if relevant or
not.

How would I go about setting a variable at the beginning of my VBA
module which can be utilized in the CMS Script? Are there additional
details you guys would need to help?
 
J

James Ravenswood

I have a question regarding the available scope of variables. I
understand that you can make variables function/routine specific,
module specific, project specific, etc. But here's my issue,

Currenly I am using a shell function to call a batch file which points
to an avaya cms script (coded in vb script, not sure if relevant or
not.

How would I go about setting a variable at the beginning of my VBA
module which can be utilized in the CMS Script? Are there additional
details you guys would need to help?

If your script can get to a cell's contents, have the VBA Dim the
variable to the proper level of scope, then have the VBA initialize
the variable, then have the VBA coding place the value in some cell's
contents for the script to retrieve.
 
R

Rick Rothstein

I have a question regarding the available scope of variables. I
understand that you can make variables function/routine specific,
module specific, project specific, etc. But here's my issue,

Currenly I am using a shell function to call a batch file which points
to an avaya cms script (coded in vb script, not sure if relevant or
not.

How would I go about setting a variable at the beginning of my VBA
module which can be utilized in the CMS Script? Are there additional
details you guys would need to help?

Your Shell'ed out batch code, and the script file it calls, will be running
under a different command processor than your Excel program, so I don't
think you can have the script read into any global variables you create in
Excel. However, you should be able to modify your batch file to accept a
command argument and pass that on to the VBScript program... then you could
simply pass the "global variable's value" to the batch file on the command
line that you specify for the Shell command. The idea is untested, but I
don't see why it wouldn't work.

Rick Rothstein (MVP - Excel)
 
M

Matthew Dyer

Your Shell'ed out batch code, and the script file it calls, will be running
under a different command processor than your Excel program, so I don't
think you can have the script read into any global variables you create in
Excel. However, you should be able to modify your batch file to accept a
command argument and pass that on to the VBScript program... then you could
simply pass the "global variable's value" to the batch file on the command
line that you specify for the Shell command. The idea is untested, but I
don't see why it wouldn't work.

Rick Rothstein (MVP - Excel)

' Your Shell'ed out batch code, and the script file it calls, will be
running
' under a different command processor than your Excel program, so I
don't
' think you can have the script read into any global variables you
create in
' Excel.

This is where I was leaning as to why trying to declare global/public
variables was not working.

' However, you should be able to modify your batch file to accept a
' command argument and pass that on to the VBScript program... then
you could
' simply pass the "global variable's value" to the batch file on the
command
' line that you specify for the Shell command. The idea is untested,
but I
' don't see why it wouldn't work.

Since I am limited in my programming experience, I'm going to have to
research how to do this. I believe I understand what this blurb means
though. This was the process I was looking for to bridge the gap from
Excel to the other command. If you could provide additional help as to
how this might look i'd be eternally greatfull.
 
M

Matthew Dyer

' Your Shell'ed out batch code, and the script file it calls, will be
running
' under a different command processor than your Excel program, so I
don't
' think you can have the script read into any global variables you
create in
' Excel.

This is where I was leaning as to why trying to declare global/public
variables was not working.

' However, you should be able to modify your batch file to accept a
' command argument and pass that on to the VBScript program... then
you could
' simply pass the "global variable's value" to the batch file on the
command
' line that you specify for the Shell command. The idea is untested,
but I
' don't see why it wouldn't work.

Since I am limited in my programming experience, I'm going to have to
research how to do this. I believe I understand what this blurb means
though. This was the process I was looking for to bridge the gap from
Excel to the other command. If you could provide additional help as to
how this might look i'd be eternally greatfull.- Hide quoted text -

- Show quoted text -

so i'm still coming up with nothing with bridging variables from my
vba command into the script process, so here's my new plan of attack.
i'm going to set my variables up in the vba code and write them to a
txt file. then in the vbscript i will open and read the txt files to
get those variables. not the most efficient method i imagine, but
until i can convert the entire vbscript into vba code and run
exclusively out of excel this will work...
 
I

isabelle

hi Matthew,

if you use vba excel and if the lifetime of the variable must not exceed the lifetime of the session
you could use a hidden name to stock this value

http://xcell05.free.fr/pages/prog/hnamespace.htm

the principle is the following:

unlike the names of workbooks or spreadsheets, this method allows you to create variables undetectable by the user,
which are not part of the Names collection, are attached to any workbook,
and whose value is preserved during the whole the current Excel session.
these features allow you to use these names as environment variables, accessible by any macro, regardless of the open workbooks.


Sub Create_a_Hidden_Name()
'or change value
aName = "Test1"
aValue = 654321
Application.ExecuteExcel4Macro "SET.NAME(""" & aName & """,""" & aValue & """)"
End Sub

Sub check_value_of_Hidden_Name()
MsgBox Application.ExecuteExcel4Macro("Test1")
End Sub

Sub Delete_hidden_name()
Application.ExecuteExcel4Macro "SET.NAME(""Test1"")"
End Sub
 
M

Matthew Dyer

Isabelle,
Thank you for the reccomendation,
Unfortunately the hidden name variable cannot be read by the Avaya CMS
VBScript. I think this is due to what Rick had mentioned earlier about
the different codes being run in seperate processes.

Writing to the txt file worked like a charm.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top