Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Some Handy VBScript Functions

General

Some Handy VBScript Functions

by  browolf  Posted    (Edited  )
Dateadd
=======
Add or subtract a period of time from a given date. Period of time includes year, week, day, month, hour, minute, second.
e.g.
newdate = dateadd("m",2,"10-Jan-95")
where m = timeperiod
2 = how many timeperiods
newdate would be + 2 months ie 10-Mar-95
-2 would be 2 months previously

Datediff
========
Calculate differance between two dates. Result can be positive or negative. Good for determining if date is before/after another date.

if datediff("d",date1,date2) > 0 then
date2 is after date1
end if


Instr
=====
Find the presence of a string within another string. E.g. If you want to find a string in a file you can use this function within a loop and check everyline.
linestr = myfile.readline
if instr(linestr, "string we want") then
do something
end if


Split
=====
split a string into an array, by a delimiter. e.g. you can split lines from a CSV file by the ','
e.g. line in a file reads "thisvalue = 10"
linestr=myfile.readline
myarray = split(linestr, "=")
valuewewant = myarray(1)
remember arrays start at zero

Ubound
======
the size of an array. if want to cycle thru an array and you dont know how big it is
then u can do
for i = 0 to ubound(array)
myvalue = array(i)
.....
next
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top