Re: How to run a script based on condition



Thanks Richard for your immediate response. The command you mentioned works
for me.(Wscript.Quit). I am not using any error code, since i used On Error
resume Next at the top of the program.

I have another question, since i am new to regular expressions, i would like
to check if the phone number in AD are in companys standard format.
please help me with the coding.
I am retrieving the phone number from AD and store it in a file after
formating it.
Actually, the format of the phoe numbers in AD are,
(nnn) nnn-nnnn
1-nnn-nnn-nnnn
+1(nnn) nnn-nnnn
nnn-nnn-nnnnxnnnn
(nnn) nnn-nnnnxnnnn
format.
I would like to retrieve the phone number and change to companys format. like,
(nnn) nnn-nnnn
(nnn) nnn-nnnnxnnnn
Where n represents numbers .
The first 3 digits should be numbers within paranthesis and a space and then
three digits and then a hyphen followed by four digits.
If a user has extension, then it should be of (nnn) nnn-nnnnxnnnn.
I would like to check if it is in the companys format, else, change the
format and store it in a file. I tried with the coding,
If (phoneNumber <> "") Then
Dim re
Set re = New RegExp
re.Pattern = "(\d{3})(\d{3})(\d{4})"
If (phoneNumber = re.Pattern) Then
objfile.write "<B><FONT size=2 color=black>Tel:</B><FONT size=2
color=black> " & phoneNumber & " <BR> " & vbCrLf
Else
phoneNumber = re.Replace(offno, "($1) $2-$3")
objfile.write "<B><FONT size=2 color=black>Tel:</B><FONT size=2
color=black> " & phoneNumber & " <BR> " & vbCrLf
End If
Else
Dim offno, offnor
offno=InputBox("Please enter your office phone Number ")
If (offno = re.Pattern) Then
objfile.write "<B><FONT size=2 color=black>Tel:</B><FONT size=2 color=black>
" & offno & " <BR> " & vbCrLf
ELSE
offnor = re.Replace(offno, "($1) $2-$3")
objfile.write "<B><FONT size=2 color=black>Tel:</B><FONT size=2 color=black>
" & offnor & " <BR> " & vbCrLf
END If
END If
Please help me how i can check if it is in correct format or not.
Thanks.


"Richard Mueller [MVP]" wrote:

Gladius wrote:

I would like to run a script based on condition.
I have a program which retrieves information from Active Directory and
store
it in a file. I would like to check if the file exists or not, if exists
then
the rest of the program should not run. It should exit the program, else,
it
should run the program. Actually i have to place the program as a Logon
script. So, the program should run once by checking the file exists or
not.
Dim objFS1
Set objFS1 = CreateObject("Scripting.FileSystemObject")
If (objFS1.FolderExists(FolderLocation)) Then
'If (objFS1.FileExists(HTMFileString)) Then
'Exit
'End If
Else
Call objFS1.CreateFolder(FolderLocation)
End if

What is the command to exit from the program as soon as it detects the
file
exists.

The statement:

Wscript.Quit

will abort the program immediately. You can also pass an error code, but
that is seldom necessary. For example:

Wscript.Quit(3)

passes the error code 3 to the program that called the VBScript, if there is
one. If a batch file launched the VBScript, you could retrieve the error
code with the DOS "errorlevel" statement. Most likely, you should just use
Wscript.Quit.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab web site - http://www.rlmueller.net
--



.



Relevant Pages

  • Re: Error Code -1072885353
    ... The error code doesn't look like anything WMP generated (even when converted to hexadecimal format). ... Error Code -1072885353 - Windows Media Player cannot play thie file. ... verify that you are connected to the network. ...
    (microsoft.public.windowsmedia.player)
  • Re: Wish no 951
    ... to a database of these notices in copy/pasteable text format. ... copy/pasteable text being accessible from a context menu. ... tremendously useful for communications on NGs and help desks. ... the error code number instead of completely suppressing it in favor of ...
    (comp.sys.mac.apps)
  • Re: Parsing one part of an address
    ... 456 Elm St ... 789 Oak Ave # 44 ... not return an error code in column F if the row in column E does not have a “ ...
    (microsoft.public.excel.worksheet.functions)
  • Re: SSO and SAP with kerberos in AIX
    ... libgssapi_krb5.a.2.2: archive (big format) ... collect2: library libgcc_s not found ... 1254-004 The error code from the last command is 1. ...
    (comp.protocols.kerberos)
  • Re: Phone Number format
    ... Ian Davidson wrote: ... > owner phone number in the format nnn-nnnn? ... > number in the world follows the US format... ...
    (microsoft.public.pocketpc)

Loading