Source language: Translate to:

Javascript / VBScript variables

Post your suggestions for future versions of NeoBook

Moderator: Neosoft Support

Javascript / VBScript variables

Postby dpayer » Mon Feb 13, 2012 1:29 pm

I don't know if this is possible inside NB or not.

I have trouble getting the syntax right on scripts that I want to add as functions. Example: It appears that the javascript nbsetvar command uses a slightly different syntax in javascript than in vbscript.

Would it be possible to show inside the debug window the variables generated in VBScript or Javascript in a NB function and the values they have? It is hard to trouble shoot these issues the way you can directly in NB. In JScript you can use a MsgBox for javascript but that doesn't work if you don't run your script in an IE browser object.

I am thinking of something like this:
Image

You may need to force the way the variables are declared and returned to the publication but at least we could keep track of whether things are working or not.

Thanks for listening.
User avatar
dpayer
 
Posts: 1384
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Postby hlmonok3dz » Mon Feb 13, 2012 7:14 pm

JavaScript and VBScript are actually executed by Windows outside of NeoBook, so I'm not sure it's even possible for us to keep track variables that exist in that realm. You can always place a message box within a function if you want to display the contents of specific variables.
hlmonok3dz
 
Posts: 31
Joined: Fri Mar 10, 2006 10:02 pm

Postby dpayer » Tue Feb 14, 2012 7:30 am

NeoSoft Support 1 wrote:JavaScript and VBScript are actually executed by Windows outside of NeoBook, so I'm not sure it's even possible for us to keep track variables that exist in that realm. You can always place a message box within a function if you want to display the contents of specific variables.


Understood.

I am running into problems using a message box in JScript/Javascript in NB. It doesn't seem to work the same as in VBScript.

I posted in the script section of this forum on a project:
http://www.neosoftware.com/forum/viewto ... 4#11205014

I can't get the .sort function in JScript to work. If I attempt to use a jscript alertbox (equivalent of msgbox in vbscript, I think) to display the variable - or anything - using this function code:
Code: Select all

var textlist=nbGetVar( "textlist" );
var textarray=new Array(textlist);


sortedArray = textarray.sort();
reversesort = sortedArray.reverse();

alert("this is a test");

nbSetVar ( "textlist3", textarray );
nbSetVar ( "reversesort", reversesort );


I get the following error:

Image

Does JScript require the presence of the browser object in order to be utilized? Also, the .sort function of JScript/Javascript doesn't seem to work right (see the other thread).

David P
User avatar
dpayer
 
Posts: 1384
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Postby Tony Kroos » Tue Feb 14, 2012 7:40 am

do not use alert, it won't work in this case. When we talk about functions, there is no JavaScript but JScript. It's a different things.

try this

Code: Select all
var MsgBox=new ActiveXObject("wscript.shell")
MsgBox.Popup ("It works!")
Tony Kroos
 
Posts: 402
Joined: Thu Oct 15, 2009 3:43 pm

Postby Tony Kroos » Tue Feb 14, 2012 7:49 am

all javascript (and vbscript) examples found on internet must be revised and rewritten for use in neobook.
Tony Kroos
 
Posts: 402
Joined: Thu Oct 15, 2009 3:43 pm

Postby dpayer » Tue Feb 14, 2012 8:54 am

Tony Kroos wrote:all javascript (and vbscript) examples found on internet must be revised and rewritten for use in neobook.


Tony, your sample above did generate an 'alert' box.

I spent a couple hours on this. So I feel I need some help understanding better
1) differences between JScript and JavaScript
2) particulars of using JScript in NB (I know square brackets are an issue as NB interprets them as a NB variable)
3) any known limitations of using scripts in NB.

David P
User avatar
dpayer
 
Posts: 1384
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Postby Luiz Alfredo » Tue Feb 14, 2012 9:45 am

Try this:

Dim counter
counter = 42
Debug.Write "The value of counter is " & counter

To run this example, you must have a script debugger installed and the script must run in debug mode.

To enable script debugging in Internet Explorer

1.
On the Tools menu, click Internet Options.

2.
In the Internet Options dialog box, click the Advanced tab.

3.
In the Browsing category, clear the Disable script debugging check box.

4.
Click OK.

5.
Exit and restart Internet Explorer.

Also take a look here:

http://www.robvanderwoude.com/vbstech_debugging.php

Here you will find many techniques and scripts:

http://www.robvanderwoude.com/vbstech.php

Do not know if this can help.
L.A.G.M.
Luiz Alfredo
 
Posts: 195
Joined: Thu Apr 19, 2007 6:58 am
Location: Brazil

Postby Tony Kroos » Tue Feb 14, 2012 10:54 am

1) differences between JScript and JavaScript

JScript (and vbscript) is a system script language, part of Windows Script Host (WSH) engine. It produces .js files that can be run (like .vbs) in system environment.
Javascript is a script language too, but intended to use in web (not system) environment and it runs in your internet browser only. Javascript and JScript has similar syntax, but they differ in some code techniques, methods and details. Something that can be run in your browser cannot be run in system and vise versa.
2) particulars of using JScript in NB (I know square brackets are an issue as NB interprets them as a NB variable)
there are some other things. For ex. some time ago I wrote about using WScript object and it's methods (sleep, quit) here and since then I've noticed a lot of such things and restrictions. now I prefer writing scripts for nb functions from scratch and refuse a "net-found" samples...
Tony Kroos
 
Posts: 402
Joined: Thu Oct 15, 2009 3:43 pm

Postby Gaev » Tue Feb 14, 2012 2:19 pm

DavidP:

Here is a strategy to help debug JScript functions Called from your NeoBook pubs.

1) on a page that is normally hidden from the User's View, create a Container (called JVars).

2) WIthin this Container, create five or six Text objects ... with content set to variables Jvar1 to JVar5.

3) Any time you have a ...
Code: Select all
Call "someJScriptFunction"
... command, insert a ...
Code: Select all
GoSub "ShowDebugVars"
... command just before it.

4) For the SubRoutine ...
Code: Select all
SetVar "[jVar1]" ""
SetVar "[jVar2]" ""
SetVar "[jVar3]" ""
SetVar "[jVar4]" ""
SetVar "[jVar5]" ""
CustomWindow "JVars" "-1" "-1" "Jvars" "DialogBox"
Return


5) In your JScript, in order to see the value of any (javascript) variable, add a command like ...
Code: Select all
nbSetVar('jVar4',sortedList);


When you don't need the Debugging facility, just comment out the GoSub "ShowDebugVars" line in your pub.

After that, all you need to do is copy the Container object and the SubRoutine code into each Pub you build.
Last edited by Gaev on Wed Feb 15, 2012 5:22 am, edited 2 times in total.
User avatar
Gaev
 
Posts: 3737
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby Tony Kroos » Tue Feb 14, 2012 8:19 pm

so you suggest to assign the "script-variables" to "nb-variables" with nbSetVar and display their values ​​in the pub. Well, it's also a good way to solve the problem.
Tony Kroos
 
Posts: 402
Joined: Thu Oct 15, 2009 3:43 pm


Return to NeoBook Suggestions

Who is online

Users browsing this forum: No registered users and 2 guests

cron