0

I'm working with two related VBscripts right now. The first file calls the second file to perform tasks.

In the second file, I'm constructing several address to create new folders and copy files over. However, the "year" value is hard-coded. Thus I have to manually update it whenever an error in the dates occurs when I run the first file.

For the first file I have, I update the "year" value every week, so that the code is always up to date, but not the second file.

I'm trying to fix the second file by changing the year value to a variable, which will update itself whenever I change the "year" value in the first file.

The part I'm not sure about is how to open the first file within the second file and extract that "year" value in the first file. OR using the first file to open and edit the "year" value in the second file.

  • I can't fully picture what you're doing, but is there an option to pass the year as a parameter to a function in the second VBScript file? A function setYear(iYear) sure would be handy for updating a global variable in the second file. – BrettFromLA Jan 30 '14 at 21:31
  • @user3254878 how do you call the second script from first? – Kul-Tigin Jan 30 '14 at 21:53
  • @Kul-Tigin Vice Versa. Calling first script from second would work too. That's the thing I'm confused about...Is there any way to do this? The information I need to run the second file lies in the first file. – user3254878 Jan 30 '14 at 21:56
  • Well, I wrote an answer. Hope it helps. – Kul-Tigin Jan 30 '14 at 22:03
  • @BrettFromLA I'm fairly new with VBscript and VBA. In the first file, I used Const YearValue= "2014" and in the second file when I'm trying to set up the file path, I just used the hardcoded value, for e.g 2013. – user3254878 Jan 30 '14 at 22:03
  • @Kul-Tigin Great! I'll check it out tomorrow. Thanks! – user3254878 Jan 30 '14 at 22:08
  • 3
    You definitely do not want to change the source code of one script with the other script. Remove hard-coded values and use call-time parameters instead. – Tomalak Jan 30 '14 at 22:08
  • Are you sure there is no programmatic way to work out the year value so you don't need to keep updating the first file manually? – Damien Jan 30 '14 at 23:53
  • @Damien unfortunately the first file must be updated manually :/ – user3254878 Jan 31 '14 at 14:47

1 Answers1

3

If I understood correctly, using named arguments will work.

'First Script
Dim VarYear
    VarYear = "2014"

Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
    WshShell.Run "second.vbs /passedyear:" & VarYear


'Second Script
Dim PassedYear
    PassedYear = WScript.Arguments.Named("passedyear")

MsgBox PassedYear
Kul-Tigin
  • 16,728
  • 1
  • 35
  • 64
  • Forgot to say, at the end of my first file, i have IncludeFile "secondfile.congif". Would that be any help? – user3254878 Jan 31 '14 at 15:43
  • @user3254878 Since VBScript has no any include functionality, you must be using a special solution that everyone could not know it. In order to understand each other better, why don't you add both scripts here? Mysteries only raise new questions. – Kul-Tigin Jan 31 '14 at 15:59