Source language: Translate to:

Run VBscript functions from external file

Questions and information about using VBScript and JavaScript in NeoBook functions

Moderator: Neosoft Support

Run VBscript functions from external file

Postby ebear » Sun Apr 12, 2015 7:05 am

Hello All,

I would like to know if there is a possibility to execute VBScript functions from an external file, something like is done with Neobook scripts with the hpwPlayAction plugin?
My idea is that if there are changes needed in the script this can be done without changing the main application.

Or some thing like this, the example below doesn't work and is only from NB actions:

Code: Select all
SetVar "[ScriptToExecute]" "AlertBox [#34]Hello[#34] [#34]Hello[#34]"
Call "[Action]" "[ScriptToExecute]"


and the function will be:

Code: Select all
{NeoBook Function}
Version=5,80
Param=[%1]|Text|Action:
{End}
.The variable below contains the script
[%1]





Best regards,

Eric
http://www.lunarsoftware.eu - Lunar Software ERP database Development. Manufacturing processes, Document management, QMS, Stock management. Standalone solutions or connected to Helios Orange and other ERP systems.
User avatar
ebear
 
Posts: 270
Joined: Wed Jan 18, 2012 3:12 am
Location: Vrchlabi - Czech republic

Re: Run VBscript functions from external file

Postby dec » Sun Apr 12, 2015 7:17 am

Hello there,

I don't know about VBScript, and hopefully you can get what you wanted, Eric. I just want to mention here my npPasc plugin, which add scripting capabilities to NeoBook (also the hability to execute code from files, units, strings, etc.) using the venerable Pascal language. Sorry if I can't help at this time in the VBScript part... :oops:
.
Enhance your NeoBook applications!
.
58 plugins, 1131 actions and 233 samples
.
NeoPlugins website: www.neoplugins.com
.
User avatar
dec
 
Posts: 1663
Joined: Wed Nov 16, 2005 12:48 am
Location: Spain

Re: Run VBscript functions from external file

Postby ebear » Sun Apr 12, 2015 7:28 am

Hello David,

My idea is mainly to export data to Excel sheets. Before I archived this with using Excel as a Database but this gave a lot of problems.
Now I started to do the same with VBScript this gives a lot of advantages and it is a lot quicker. Fore example see below.
But I would like to have the possibility to change the scripts without changing the main application.
Of cause I know and have your "Great" npPasc plugin and using this, and exactly as the npPasc plugin I would like to do the same with VBScript and maybe JavaScript.

Thanks David for your reaction.

Regards,

Eric


Code: Select all
{NeoBook Function}
Version=5,80
Language=VBScript
Param=[srccsvfile]|Text|Source file
Param=[tgtxlsfile]|Text|Output XLS file
Param=[template]|Text|Template file
Param=[tpath]|Text|Template path
{End}
On Error Resume Next ' Turn on the error handling flag
Set objExcel = GetObject(,"Excel.Application")
If Err.Number = 429 Then  '> 0
  Set objExcel = CreateObject("Excel.Application")
End If

objExcel.Visible = false
objExcel.displayalerts=false

Set objWorkbook = objExcel.Workbooks.Open("[tpath][template]")
Set objWorksheet = objWorkbook.Worksheets(1)

objExcel.Range("B2").Select
objExcel.ActiveCell.FormulaR1C1 = publication.nbGetVar( "[Fis.CoreIn.CustomerName]" )

objExcel.Range("B3").Select
objExcel.ActiveCell.FormulaR1C1 = publication.nbGetVar( "[Fis.CoreIn.CustomerNo]" )
Selection.NumberFormat = "@"

objExcel.Range("B4").Select
objExcel.ActiveCell.FormulaR1C1 = publication.nbGetVar( "[Fis.CoreIn.RID]" )
Selection.NumberFormat = "@"

objExcel.Range("B6").Select
objExcel.ActiveCell.FormulaR1C1 = publication.nbGetVar( "[Fis.CoreIn.DateIn]" )

objExcel.Range("B7").Select
objExcel.ActiveCell.FormulaR1C1 = publication.nbGetVar( "[Fis.CoreIn.DateReady]" )

objExcel.Range("B8").Select
objExcel.ActiveCell.FormulaR1C1 = publication.nbGetVar( "[Fis.CoreIn.ID]" )
Selection.NumberFormat = "@"

objExcel.Range("F3").Select
objExcel.ActiveCell.FormulaR1C1 = publication.nbGetVar( "[Fis.CoreIn.Qty]" )

objExcel.Range("G3").Select
objExcel.ActiveCell.FormulaR1C1 = publication.nbGetVar( "[Fis.CoreIn.QtyType]" )

objExcel.Range("F4").Select
objExcel.ActiveCell.FormulaR1C1 = publication.nbGetVar( "[Fis.CoreIn.Weight]" )

objExcel.Range("E6").Select
objExcel.ActiveCell.FormulaR1C1 = publication.nbGetVar( "[Fis.CoreIn.Note]" )

objExcel.Application.Run "[template]!InsertExport"

objWorksheet.SaveAs "[tgtxlsfile]", 56

objExcel.Quit()
Set objWorksheet = Nothing
Set objWorkbook = Nothing
Set ObjExcel = Nothing
http://www.lunarsoftware.eu - Lunar Software ERP database Development. Manufacturing processes, Document management, QMS, Stock management. Standalone solutions or connected to Helios Orange and other ERP systems.
User avatar
ebear
 
Posts: 270
Joined: Wed Jan 18, 2012 3:12 am
Location: Vrchlabi - Czech republic

Re: Run VBscript functions from external file

Postby Gaev » Sun Apr 12, 2015 7:48 am

Eric:

I would like to know if there is a possibility to execute VBScript functions from an external file, something like is done with Neobook scripts with the hpwPlayAction plugin?
My idea is that if there are changes needed in the script this can be done without changing the main application.

The trick to making a Call command execute a predefined script from an external file at run time 9i.e. not have it automatically embedded inside your .exe file) ... is to do something like this ...
Code: Select all
SetVar "[externalCallFile]" "![PubDir]myExternalFunction"
Call "[externalCallFile]" "param1" "[var ForParam2]"

... since NeoBook does not know the value of the variable [externalCallFile] at compile time, it does NOT embed your function file (called myExternalFunction in my example above) ... when you distribute your .exe file, make sure that this file (on your Functions folder) is copied to the user's folder containing the .exe file.

Warning - this method of performing function Calls can present a security issue ... not only can a savvy user read the commands, he might even be able to make undesirable changes !!!
User avatar
Gaev
 
Posts: 3734
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Run VBscript functions from external file

Postby ebear » Sun Apr 12, 2015 7:53 am

Hello Gaev,

This something that I didn't know and could be also usable, maybe it would work with encryption.
Any Ideas to do the same when the script as text is saved in a database :)

Regards,

Eric
http://www.lunarsoftware.eu - Lunar Software ERP database Development. Manufacturing processes, Document management, QMS, Stock management. Standalone solutions or connected to Helios Orange and other ERP systems.
User avatar
ebear
 
Posts: 270
Joined: Wed Jan 18, 2012 3:12 am
Location: Vrchlabi - Czech republic

Re: Run VBscript functions from external file

Postby ebear » Sun Apr 12, 2015 7:58 am

Gaev:

The below i tested and works great, again learned something thanks.

Eric

Gaev wrote:Eric:

I would like to know if there is a possibility to execute VBScript functions from an external file, something like is done with Neobook scripts with the hpwPlayAction plugin?
My idea is that if there are changes needed in the script this can be done without changing the main application.

The trick to making a Call command execute a predefined script from an external file at run time 9i.e. not have it automatically embedded inside your .exe file) ... is to do something like this ...
Code: Select all
SetVar "[externalCallFile]" "![PubDir]myExternalFunction"
Call "[externalCallFile]" "param1" "[var ForParam2]"

... since NeoBook does not know the value of the variable [externalCallFile] at compile time, it does NOT embed your function file (called myExternalFunction in my example above) ... when you distribute your .exe file, make sure that this file (on your Functions folder) is copied to the user's folder containing the .exe file.

Warning - this method of performing function Calls can present a security issue ... not only can a savvy user read the commands, he might even be able to make undesirable changes !!!
http://www.lunarsoftware.eu - Lunar Software ERP database Development. Manufacturing processes, Document management, QMS, Stock management. Standalone solutions or connected to Helios Orange and other ERP systems.
User avatar
ebear
 
Posts: 270
Joined: Wed Jan 18, 2012 3:12 am
Location: Vrchlabi - Czech republic

Re: Run VBscript functions from external file

Postby Gaev » Sun Apr 12, 2015 8:31 am

Eric:

I saw your previous post after I posted my previous mine.

This something that I didn't know and could be also usable, maybe it would work with encryption.

There is no built-in encryption as far as I know.

You could build a scheme for yourself ...

a) encrypt the NeoBook generated Function file

b) deliver it with your .exe

c) before calling this external file, read into memory, decrypt it, save it to the Temp folder and Call the file in the Temp folder

Any Ideas to do the same when the script as text is saved in a database :)

I thought of that ... but in your case, you want the flexibility to update the script on an ongoing basis ... so you would have to ...

a) have a simple NeoBook program at your end to copy the contents of the (NeoBook generated) Function file into a "password protected and encrypted" Access Database

b) have the user ...

- save the database file in a specified folder in his machine
- click a button in your Application that will copy the contents from this received Database to the main Database

c) and any time you need to Call this Function, you can copy it to a file in the user's Temp folder ... and Call it from there

Note: If the "Database of External Scripts" is not large (shouldn't be) ... you could just send the entire (updated) Database to the user ... and have him replace the existing one.


Note that with either scenario, ... the content of the function file HAS to be unencrypted at time of execution by NeoBook ... so. still possible for user to read its contents ... you might consider giving the unencrypted file (in the Temp folder) a random name each time ... and erase it soon after execution ... to make it that much more difficult for the user to read its contents.



Separately, if your script can be run inside an HTML document, you might consider something like this ...

a) store all your vb Function script content in a "password protected, encrypted" Access Database

b) at startup ...

- BrowserLoadFromStr to load a "stub of an HTML document" in a WebBrowser object (hidden from user view)

- copy content of each script to a separate NeoBook variable

c) when needed, do ...
Code: Select all
BrowserExecScript "WebBrowser99" "[appropriateVariableHere]" "VBScript"
User avatar
Gaev
 
Posts: 3734
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Run VBscript functions from external file

Postby ebear » Mon Apr 13, 2015 5:56 pm

Hello Gaev,

I have now, mainly because of your great support, things running. I didn't had time to start with the Database storage of the functions but the idea is there:

1. The storage database will be MySQL.
2. My idea is to store the functions as a file in a Blob field, encryption will not be needed I think in this case
3. As I already am working on a admin tool for the application and I will also build in a system to manage the scripts. extract from BLOB > Edit > and Save back to the BLOB.
4. User will, as you suggested, extract the function to his Temp Dir at time of use, and I will erase the function after use.
The functions are only small text files so performance shouldn't be a problem.

I'm glad you came up with the idea how to use the functions as an external file, because I think that's the way to go with this. I'm already thinking about more possibilities with this. Further for, as you remember, my "Modular Application" concept brings this also more flexibility.

Gaev thanks a lot for you support.

Regards,

Eric
http://www.lunarsoftware.eu - Lunar Software ERP database Development. Manufacturing processes, Document management, QMS, Stock management. Standalone solutions or connected to Helios Orange and other ERP systems.
User avatar
ebear
 
Posts: 270
Joined: Wed Jan 18, 2012 3:12 am
Location: Vrchlabi - Czech republic


Return to NeoBook Functions - VBScript & JavaScript

Who is online

Users browsing this forum: No registered users and 1 guest