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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tough Question, what's wrong with this code? 1

Status
Not open for further replies.

Aladdin420

Programmer
Jan 5, 2001
33
US
Hey guys, this question may be a toughy, at least to me it is. I am trying to copy one file, "Machine.lst", to one folder, "information". Simple, right? Wrong!!
I want to copy the file, but I want the file to first go through a script, "SmartCopy.prg". This script copies a file to a folder. It is built to accept two arguments, the source of the file, "fc_source", and the destination, "fc_target".

Here's the code:

Dim objSC, blah, sCCSserver, sMachine, Copier, oFSo
Set oFSo = CreateObject("Scripting.FileSystemObject")
Set objSC = CreateObject("MSScriptControl.ScriptControl")
Set oShell = CreateObject("Wscript.Shell")
objSC.Language = "VBScript"


blah1 = "Function Load(fc_source, fc_target)"& vbNewLine & "Load = c:\project\SmartCopy.prg"

blah1 = blah1 & ": End Function"

objSC.AddCode blah1

Wscript.Echo objSC.Run("Load", "c:\Machine.LST", "c:\information\")

It doesn't work!! Here's the error it spits out:
"Micorosoft VBScript compilation error: Expected statment"
I'm open to "ALL" suggestions.
Thanks everyone

 
Sorry John, but that didn't work!
Thanx for ur efforts
 
If I'm reading this correctly, your "Load" function isn't actually doing anything, but just passing back something you could have set in a variable.

I'm not seeing where your "SmartCopy.prg" is actually being called for execution.

Perhaps you could clue us in on the code in SmartCopy.prg.

I also agree with the post by John on the "newline" into the Function, and scrapping the ":". If my post was helpful, please Mark it below. Thanks! - Al
 

Maybe this will help:

blah = "Function ManyArgs(a, b, c, d)"& vbNewLine &" ManyArgs = a * b + c - d"
blah = blah & "End Function"
objSC.AddCode blah
Wscript.Echo objSC.Run("ManyArgs", 1, 2, 3, 4)

Now this works. I'm trying to mimic it's structure in my "Load" function.


Okay, here's the inside of the "SmartCopy.prg" file. These are the beginning lines of code that accept the first and second parameters, "fc_source" and "fc_target".

'------- Variables
$fc_source$ = "$param[1]$"
$fc_target$ = "$param[2]$"

After these two parameters are given the rest of the lines of the script should kick off.

Please let me know if anything...

Thanx again
 
Your current function will actually end up looking like this:

Function Load(fc_source, fc_target)
Load = c:\project\SmartCopy.prg: End Function

I'd say you need to make it look like this:

Function Load(fc_source, fc_target)
Load = "c:\project\SmartCopy.prg " & fc_source & " " & fc_target
End Function

This will pass the parameters "fc_source" and "fc_target" to your SmartCopy.prg like this once it's run:

c:\project\SmartCopy.prg c:\Machine.LST c:\information
To accomplish this, do the following:

blah1 = "Function Load(fc_source, fc_target)" & vbNewLine
blah1 = blah1 & "Load = ""c:\project\SmartCopy.prg "" & fc_source & "" "" & fc_target"
blah1 = blah1 & vbNewLine & "End Function"

Once you do this, however, all that's going to happen is that you'll end up with a Wscript.Echo with the following text in it:

c:\project\SmartCopy.prg c:\Machine.LST c:\information
If you want to actually run that command, you should do the following:

oShell.Run(objSC.Run("Load", "c:\Machine.LST", "c:\information\"))


If you have any problems / questions - message back. If my post was helpful, please Mark it below. Thanks! - Al
 
Hey Al, the script looks great.

blah1 = "Function Load(fc_source, fc_target)"& vbNewLine
blah1 = blah1 & "Load = ""c:\project\vbs.stuff\SmartCopy.prg"" & fc_source & "" "" & fc_target"
blah1 = blah1 & vbNewLine & "End Function"

objSC.AddCode blah1

oShell.Run(objSC.Run("Load", "c:\Test\testfile.txt", "c:\project\TestFolder\"))

The compiler runs through the entire code until this last line:

oShell.Run(objSC.Run("Load", "c:\Test\testfile.txt", "c:\project\TestFolder\"))

The error it spits out is:
"The system can not find the file specified"

Now I have double checked, and "SmartCopy.prg" is in the correct folder, and so is "testfile.txt".
What do you think buddy?
 
Hey guy - you're missing a space.

This line:

blah1 = blah1 & "Load = ""c:\project\vbs.stuff\SmartCopy.prg"" & fc_source & "" "" & fc_target"

Should look like this:

blah1 = blah1 & "Load = ""c:\project\vbs.stuff\SmartCopy.prg "" & fc_source & "" "" & fc_target"


Notice - the space after "SmartCopy.prg" and before the "". You were outputting the following to be run by the operating system:

c:\project\vbs.stuff\SmartCopy.prgc:\Test\testfile.txt c:\project\TestFolder If my post was helpful, please Mark it below. Thanks! - Al
 
You were right. The script now executes without any errors. You've got my vote bud.

One small problem. I don't think we are running the "SmartCopy.prg" file correctly. U c, when the script runs, it spits out the "SmartCopy.prg" file in notepad, on the screen. There's no actual execution of this file. Therefore "testfile.txt" is not copied to the "TestFolder".
Because if SmartCopy.prg was to run, the parameters should've been noticed.

The beginning lines of SmartCopy.prg script:

------- Variables
$fc_source$ = "$param[1]$"
$fc_target$ = "$param[2]$"

Is there some special way to specfically run ".prg" files?
I'm not quiet sure.
 
SmartCopy.prg:

sub main

------- Variables
$fc_source$ = "$param[1]$"
$fc_target$ = "$param[2]$"

These are the first few lines in that file. Maybe calling the "sub main" function in our script could kick it off?

 
Well, is there any other code in SmartCopy.prg other than:

$fc_source$ = "$param[1]$"
$fc_target$ = "$param[2]$"

????

What exactly is SmartCopy.prg supposed to do, and why are you passing outside of VBScript to that program, why not just do what you need within VBScript? If my post was helpful, please Mark it below. Thanks! - Al
 
SmartCopy.prg is a script that has to be used, it's part of my project.

I think I may have one last ace up my sleeve. The prg file will not just execute with the run command in VBScript. VBScript will have to call another program, which in return will run this .prg file. I have an idea and will try it. Will let u know what happens.

And thanx a lot for ur help dude, I needed it. You deserved the vote.

laters
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top