Highlight a phrase and click this icon to search it on Swyx-Forum   Highlight a phrase and click this icon to search it within the Swyx Knowledgebase   Highlight a phrase and click this icon to search it using Goolge   Highlight a phrase and click this icon to search it using Wikipedia

 

Highlight a phrase and click this icon to search it on Swyx-Forum   Highlight a phrase and click this icon to search it within the Swyx Knowledgebase   Highlight a phrase and click this icon to search it using Goolge   Highlight a phrase and click this icon to search it using Wikipedia

List of Blogs
Search Blogs
Blog Archive

Most recent blog entries

 

Most recent blog entries

 

Jul3

Written by:MarkRussell
03/07/2007 13:52 

Part 1 of a basic explanition on how to modifiy scripts from the Swyx Web site to add a new function. The first part gives a the ability to put night service on or off with a very simple text file. Hopefully the full explanation included will help understand some of the basic build blocks, and an insite of how "lateral thinking" with Swyx problems will give results.
Simple Script 1, Night Service. The idea here is simple, and an often requested feature from end users “ I want a button to switch night service on or off. Not an unreasonable request as just about every phone system ever produced does this. So putting myself in this position how am I going to do this with the tools I have to hand. Well obviously we need a script, and browsing the Swyx knowledge base there is the Check Bank Holiday script. This simple script checks a text file to see if todays date is there, if so it knows it’s a bank holiday. So this should leap out as a basic building block for us to use, a call comes in, we check the contents of a text file then decide what to with it, in our case instead of checking a date we will just look to see if the text says “on” or “off”. So the original script looks like this ' FileOpen iomode ValuesConst fsoForReading   = 1
Const fsoForWriting   = 2
Const fsoForAppending = 8
 ' Bankholiday Filename
Const sBHFilename     = "bankholiday.txt"
 Function IsBankHoliday ( vDate )Dim wsh, fso, file
Dim sDir, sFile, sLine
Dim bReturn, nPos
                 bReturn = False                ' get share path by extracting it from user folder                sDir = PBXUser.DataFolder                nPos = InStrRev(sDir, "\")                sDir = Left(sDir, nPos-1)                nPos = InStrRev(sDir, "\")                sDir = Left(sDir, nPos)                 ' Build file name. Textfile will be located within the global script directory, e.g.                ' --> C:\Program Files\SwyxWare\Share\Data\PhoneClient\Scripts\bankholiday.txt                sFile = "c:\bankholiday\" & sBHFilename                 ' Create FileSystemObejct                Set fso = CreateObject("Scripting.FileSystemObject")                 ' Open text file                Set file = fso.OpenTextFile(sFile, fsoForReading)                 do while (not (file.AtEndOfStream)) and (not bReturn)                                sLine = file.ReadLine                                if IsDate(sLine) then                                                if DateDiff("d", vDate, CDate(sLine)) = 0 then bReturn = True                                end if                loop                file.Close

                Set file = Nothing
                Set fso = Nothing

                IsBankHoliday = bReturn End Function       To simplify, the code for checking night service would be changed to this. ( The lines starting with ‘ are comments, this code can be cut and paste into the start block )

‘ These opening lines will be used in most scripts, they describe to VB how to read or write a file
' FileOpen iomode Values
Const fsoForReading   = 1
Const fsoForWriting   = 2
Const fsoForAppending = 8
‘This line specifies the name of the text file containing the word “on” or “off” and its location
‘More experienced users can use the lines in the bank holiday script to build the location of the
‘File dynamically, in this case we specify the location on the C drive of the server
Const   textFileName = “c:\swyxbits\nightService.txt”‘These lines define the function to be called by the GSEFunction isNightService()‘The following Dim statement names the variables used in the scriptDim fso,bReturn,file,sLine‘The default return value is false ie night service is not onbReturn = False‘This builds the statement VB uses to connect to files
Set fso = CreateObject(“Scripting.FileSystemObject”) ‘Open the night service text file
Set file = fso.OpenTextFile(textFileName, fsoForReading)‘These lines open the text file and reads the first line, if the line says “on” it returns a true
sLine = file.ReadLine
if sLine = “on” then bReturn = True
file.Close‘These lines reset the variables
Set file = Nothing
Set fso = Nothing

isNightService = bReturn
End Function     Ok now we have a script using the same rse as the bankholiday script that can be used for night service on / off.  Using a simple text editor (notepad) we can create this file and change its contents to either on or off. The next step will to be able to write this file without the use of a text editor, and low a behold Tom wrote this script already, its in the knowledge base under enter caller into a text file. We will use this to write the next block. We will then look at some error trapping, and making the script interactive with prompts to turn night service on or off.

 

 

Tags:

 

1 comment(s) so far...

Re: Simple Script 1, Night Service.

Smart idea. I already can imagine how the complete night service solution will look like.

By Martin on  03/07/2007 19:58
Blog Help
Sponsors
UCIT cloud communication
IPIT Ltd
bluvo AG
logic-base GmbH
Atia Communications

 

 

logic-base GmbH
www.logic-base.de
Atia Communications
www.atiacomms.com
UCIT Nordic
www.ucit.no
IPIT Ltd
www.ipit.co.uk
bluvo AG
www.bluvo.de
logic-base GmbH
www.logic-base.de
Atia Communications
www.atiacomms.com
UCIT Nordic
www.ucit.no
IPIT Ltd
www.ipit.co.uk
bluvo AG
www.bluvo.de