Some useful Scripting Functions

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Some useful Scripting Functions

Some useful Scripting Functions

by Peke » Sat Jan 31, 2009 8:13 am

Here are few interesting functions.

Date to UTC Time:

Code: Select all

Function ConvertToUTC(strDate,iOffset)
On Error Resume Next
strUTC=Right(Year(strDate),2)&Pad(Month(strDate),2,"0",True) &_
 Pad(Day(strDate),2,"0",True) & Pad(Hour(strDate),2,"0",True) &_
 Pad(Minute(strDate),2,"0",True) & Pad(Second(strDate),2,"0",True)
'ConvertToUTC=DateAdd("h",strUTC,iOffSet)
ConvertToUTC=strUTC
End Function
Random Number Generator:

Code: Select all

Function GetRand(iLower,iUpper)
  Randomize
  GetRand=Int((iUpper - iLower + 1) * Rnd + iLower)
End Function
Get OS Version String:

Code: Select all

Function GetOS(strComputer)
Dim objWMI

Set objWMI=GetObject("winmgmts://" & strComputer).InstancesOf("win32_operatingsystem")

For Each OS In objWMI
  GetOS=OS.Caption
Next

End Function
Correcting String Case:

Code: Select all

Function ProperCase(strText)

strVal=UCase(Left(strText,1)) 

For x=2 To Len(strText)
    strTemp=Mid(strText,x,1)
    if Asc(strTemp) >= 65 And Asc(strTemp) <= 90 Then
        strVal=strVal & Lcase(strTemp)
    Else
        strVal=strVal & strTemp
    End If
Next

ProperCase=strVal
End Function
I've given these functions to all new and old scripters.

If you have any interesting function that you find others could use feel free to post.

WARNING: No Script Functions Requests HERE Please!

Top