Source language: Translate to:

Sample using nbgetvar - nbssetvar in a VB script

Questions and information about using VBScript and JavaScript in NeoBook functions

Moderator: Neosoft Support

Sample using nbgetvar - nbssetvar in a VB script

Postby dpayer » Fri Oct 31, 2008 2:56 pm

With tips from others (Beno & Gaev) I have begun to grock using VB scripts in NB. I like it that I don't have to write things to disk and then parse them after reading the file. I can simply grab the info from the script.

I also learned how to populate a NB Array from a loop in a VB script and it is demonstrated in this sample.

With Gaev's advice, I created a NB function and name it "folderlist" (it is a VB function)

Code: Select all
dim VarStr
dim CNTR
dim SelectedD
SelectedD = publication.nbGetVar( "[SelectedD]" )
CNTR = 1
Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubfolders FSO.GetFolder(SelectedD)
Sub ShowSubFolders(Folder)
    For Each Subfolder in Folder.SubFolders
        SPF = Subfolder.Path
     VarStr = "[results" & CNTR & "]"
   
   publication.nbSetVar VarStr, SPF
    CNTR = CNTR+1
    Next
   
End Sub


The [SelectedD] variable is set from the folder select action of the button.

The CNTR vb variable is a counter for the loop. I don't see that VB script has a function like NB that shows what position in the loop you are at, you have to create that.

The VarStr vb variable is the way you write the variable array for NB. You have to create a string composed of the necessary parts for the nbsetvar command which usually uses:

publication.nbsetvar "[results]", data

with each loop the quoted nb variable changes
[results1]
[results2]
[results3]
etc...


Here is a sample pub. Save the following code as a file with the .pub extension. Be sure to create the FUNCTION in NB and name it as mentioned. Note: this demo does not refresh properly or check for errors if you don't select a folder. It is for demonstration purposes only.


Code: Select all
NBW Publication Source File
(C)1993-2008 NeoSoft Corp.
Title=VBScript usage  #1
Author=David Payer
Language=US
NeoBookVer=5.60
ScreenColors=16777216
ScreenWidth=400
ScreenHeight=200
BkndColor=0
ScreenAutoSize=Yes
LinkColor=16711680
WindowStyle=0
WindowOrder=0
WindowPos=0
WindowProps=31
BiDiMode=0
UseUpdateTimer=Yes
ReturnTime=60
ShapeTransColor=536870912
CompileType=0
MediaType=0
FilesIncluded=1
FontsIncluded=2
CopyExternalFiles=No
SetupMedia=3
SetupInstDir=C:\MyProgram
SetupTitle=Setup
SetupColors=16711680|0|65535
VersionMajor=1
VersionMinor=0
VersionRelease=0
VersionBuild=0
CustomFontName=Arial
CustomFontSize=9
CustomFontStyle=0
CustomCharset=1
CacheSize=30
ExtractOp=132
L_OK=OK
L_CANCEL=Cancel
L_YES=Yes
L_NO=No
L_CLOSE=Close
L_ERRORTITLE=Error
L_FINDTITLE=Find
L_FINDPROMPT=Find &What
L_FINDFIRST=&Find First
L_FINDNEXT=Find &Next
L_FINDERROR=Search text not found.
L_PWORDTITLE=Password required
L_PWORDMSG=Before continuing, you must first|enter the correct password.
L_PWORDPROMPT=&Password:
L_PWORDERROR=That's not the right password!
L_MEDIAERROR=In order to play this type of file you must install|the appropriate multimedia hardware and/or|software.
L_INTERNETERROR=Unable to locate Internet Browser software.
L_ABORTFUNCTION=Do you want to cancel this function?
L_EXTRACTERROR=This file could not be extracted and cannot be played.
L_INSTDIRPROMPT=Please enter the drive and directory where you would like this program to be installed. To accept the default drive and directory, simply press Enter.
L_INSTFOLDERPROMPT=Do you wish to create a program folder?
L_INSTRUNPROMPT=Do you want to run
L_INSTDISKPROMPT=Please insert disk #
L_INSTDISKERROR=That's not the correct disk, try again.
L_INSTGENERROR=The installation has terminated.
L_INSTEXITPROMPT=Do you really want to cancel the installation?
L_INSTWINTITLE=Setup
L_INSTPROGTITLE=Extracting Files...
L_SENDEMAIL=Sending Mail...
L_MAILSERVER=Please enter the name of your outgoing email server:
L_COPY=Copy to Clipboard
L_SELECTALL=Select All
L_DONWLOADFILE=Downloading: %s
L_PLEASEWAIT=Please wait...
TrayMenuBegin
MenuName=TrayOpen
MenuText=Open
MenuState=3
MenuKey=0
MenuAction=SetVar "[WindowState]" "Normal"
MenuName=TrayExit
MenuText=Exit
MenuState=3
MenuKey=0
MenuAction=Exit "" ""
MenuEnd
MasterPage
NewPage=New Page
PageStyle=0
PageColor=16777215
PageGradient1=16711680
PageGradient2=255
PageGradientDir=1
WallpaperStyle=0
ObjectType=3
Name=PushButton1
X=10
Y=7
W=90
H=47
Anchor=0
Text=Select
Align=2
ImageStyle=0
BevelWidth=1
ObjAction=FolderBox "Select a Folder:" "[SelectedD]"¶¶SetVar "[results]" ""¶Call "folderlist"¶GetArrayInfo "[results]" "[first]" "[last]" "[number]"¶¶SetVar "[Dlist]" ""¶Loop "1" "[number]" "[loopcntr]"¶SetVar "[Dlist]" "[Dlist][results[loopcntr]][#13]"¶EndLoop¶RefreshObject "ComboBox1"
LineColor=0
LineWidth=1
LineStyle=0
FillColor=15724527
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=2
ObjectType=11
Name=ComboBox1
X=106
Y=7
W=288
H=26
Anchor=0
Text=[Dlist]
VarName=[selecteddir]
VarType=0
XPTheme=Yes
ObjAction=AlertBox "test" "You chose :|[selecteddir]"
LineColor=0
LineWidth=1
LineStyle=0
FillColor=15724527
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=3
User avatar
dpayer
 
Posts: 1383
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Postby Neosoft Support » Mon Nov 03, 2008 5:16 pm

Very cool. Thank you for sharing it with us!
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5603
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA


Return to NeoBook Functions - VBScript & JavaScript

Who is online

Users browsing this forum: No registered users and 0 guests