Macros and Programming


CardboxForumsMacros and Programming > "Returning value from extrenal VBScript"

Returning value from extrenal VBScript

How to get the data back from an external VBScript

Posted By Post


7-Feb-2015 17:51

I couldn't get a macro to run For..loops, so I transfered the data to an external file. That runs fine via CMD, and MsgBox showed the file data I was expecting ... but I can't get that data back into the main script. The external script has its data in a variable called "FileName"

Back in main program, I tried:
data=Run("C:\Users\Chris Brown\Desktop\PhotoBooth\ClearPrint.vbs")

MsgBox("D" & data) 'D and F simply show if result was Data variable of FileName variable
MsgBox("F" & FileName)

and even ..
Function InPics()
InPics=Run( ...)
End Function

MsgBox (InPics)

Here are the two scripts in case I've made a "boo-boo" somewhere else!

Option Explicit
dim x,out,FileOut,FileName,recs,data,key
x=InputBox("Enter SIM" &VbCrLf& "When using a barcode scanner," &VbCrLf& "this window may close automatically" &VbCrLf& "If not, press the ""OK"" key" &VbCrLf &"Press ""Cancel"" to quit" &VbCrLf &VbCrLf & "You can also enter SIM number manually")
if x="" then Halt

Set recs=Database.AllRecords
Set recs=recs.Select("SIM",x)

If IsObject(recs) Then
ActiveWindow.Select "SIM",x
End If
InputBox "Waiting ..." &VbCrLf&VbCrLf& "DO NOT PRESS OK" &VbCrLf&"until photographer is ready for next student","Ready For Next Student", String(20,"*")&" NO NEED TO ENTER ANYTHING HERE"&String(20,"*"),500,500
Function InPics()
Run("C:\Users\Chris Brown\Desktop\PhotoBooth\ClearPrint.vbs")
End Function

MsgBox("D" & InPics)
MsgBox("F" & FileName)
Set key=ActiveRecord.Fields("KEY")
Replace data,"*",key
MsgBox (data)

Set out = CreateObject("Scripting.FileSystemObject")
Set FileOut = out.OpenTextFile(FileName, 8, true)
Set FileOut = nothing
Set out = nothing

Option Explicit
Dim fso,folder,my_img,f,fName,Ext,FileName
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder("C:\Users\Chris Brown\Desktop\PhotoBooth\Prints")' This is correct path if Run from Cardbox
'Set folder = fso.GetFolder("Prints")' This is correct path if run from CMD and CD-ed to folder
Set my_img=folder.Files

  For Each f in my_img
  FileName=FileName & fName &"."& Ext &"*," &VbCrLf
' fso.DeleteFile(f)


What's happening:
x waits for a barcode entry, (or in my case a pasted number) It then searches database for that key, and changes record. It then displays a prompt which waits. (Don't want to carry out the next stage whilst photos are being saved to "Prints" folder)

When the photographer's finished, (and prints made from "Prints" folder), the prompt is clicked, and the external script then gets the filenames of the photos printed from folder - which it saves in the format "filename.jpg, *" - then empties the folder (and returns FileName) to script again.

The main script then changes the "*" to the "key" found in that database record before writing it out to the text file something like "filname1.jpg,1007" "filename2.jpg,1007" etc

But it's getting that data back from external script that's proving the bug!!


7-Feb-2015 19:16

Write it by the external script to a file or use the clipboard for reading it


7-Feb-2015 19:17

... suddently I thought "What about passing "key" variable to external program, and running the second half of the program there, (ie create the string directly, and write the file out). But now - HOW DO I PICK UP THE DATA SENT TO THE EXTERNAL SCRIPT??


7-Feb-2015 19:20

Write it? I know JS script has "document.writeln", so something similar? (Something to research now I've got a hint) Did wonder about copy / paste, but seems to be excessively complicated for the simple task in hand


7-Feb-2015 19:35

Just tried fso.Write FileName. It came back with Object Required
[string xxx.jpg,*
(with the two lines due to the linefeed


8-Feb-2015 10:17

Solved it! Found that Cardbox can only send one set of variables to external script, and the latter is picked up by part of the Wscript. So here's what I've got:

Set data=ActiveRecord.Fields("KEY")
Set id=ActiveRecord.Fields("RECORD")
data=data &"|" &id

Run "C:\Users\Chris Brown\Desktop\PhotoBooth\ClearPrint.vbs", data

** If I try to send (....vbs", data id) it throws an error

And in the second script:
indata = Wscript.Arguments.Item(0)
myArray = Split(indata, "|")


This might help someone else. Oh, I also found you cannot use a macro to pick up data from a Merge field. So I had to insert a dummy field, set it to 1 square wide, and set background/font to white. Still shows as little yellow triangle on main page, but small point.


8-Feb-2015 11:20

A merge field does not exit in Cardbox. Please read the manual before you write about things which are perhaps not possible ;-)


8-Feb-2015 19:01

Sorry, Bert. I think we were at cross-purposes here. I had set up a merge block to contain {Photo_URL}/{Record} but when I tried to get the macro to read the data from the {Record} part, it couldn't do it. So I had to change the design of page slightly to put a RECORD field onto the page itself, hidden as described, and then the macro was able to find the data.

Suppose it stands to reason really. The merge is only showing data whereas the field is showing data relating to that particular record.

© 2010 Cardbox Software Limited   Home