# Now for Code and a Rant

So, what exactly is with VBScript and its useless implementation? Why can't I have integers larger than 32Bit, or more to the point, why can't they be 64bit at LEAST?!

So, I know that some people are going to ask why I am using VBScript at all. VBScript happens to make a lot of sense simply for the way it can be used to interact with Active Directory on Domain Controllers, and the simplicity of making WMI calls. Plus, VBScript is so easy to start using and has a lot more immediate use than programming, and a wider feature set than Batch.

So I come to start developing a script that is checking for changes in drive sizes of Dynamic Disks and possible changes to the configuration of Extents within Partitions, and I can't compare two numbers returned from WMI or the DiskExt.exe program (do a search on the net, the most USEFUL thing I found in regards to disk extents for Dynamic Disks).

So I basically had to write my own string math functions (Addition and subtraction).

So here is that code, available for those who want it, those who need it, and those who are interested in it.

So, I know that some people are going to ask why I am using VBScript at all. VBScript happens to make a lot of sense simply for the way it can be used to interact with Active Directory on Domain Controllers, and the simplicity of making WMI calls. Plus, VBScript is so easy to start using and has a lot more immediate use than programming, and a wider feature set than Batch.

So I come to start developing a script that is checking for changes in drive sizes of Dynamic Disks and possible changes to the configuration of Extents within Partitions, and I can't compare two numbers returned from WMI or the DiskExt.exe program (do a search on the net, the most USEFUL thing I found in regards to disk extents for Dynamic Disks).

So I basically had to write my own string math functions (Addition and subtraction).

So here is that code, available for those who want it, those who need it, and those who are interested in it.

Function StringAddition(num1in,num2in)

' Cleanup

num1 = Trim(num1in)

num2 = Trim(num2in)

if num1 = "" and num2 = "" then

WScript.Quit

elseif num1 = "" then

StringAddition = num2

elseif num2 = "" then

StringAddition = num1

end if

if Asc(Mid(num1,Len(num1),1)) = 13 then

num1 = Mid(num1,1,Len(num1)-1)

end if

if Asc(Mid(num2,Len(num2),1)) = 13 then

num2 = Mid(num2,1,Len(num2)-1)

end if

if Asc(Mid(num1,Len(num1),1)) = 10 then

num1 = Mid(num1,1,Len(num1)-1)

end if

if Asc(Mid(num2,Len(num2),1)) = 10 then

num2 = Mid(num2,1,Len(num2)-1)

end if

if Asc(Mid(num1,Len(num1),1)) = 13 then

num1 = Mid(num1,1,Len(num1)-1)

end if

if Asc(Mid(num2,Len(num2),1)) = 13 then

num2 = Mid(num2,1,Len(num2)-1)

end if

if num1 = "" and num2 = "" then

WScript.Quit

elseif num1 = "" then

StringAddition = num2

elseif num2 = "" then

StringAddition = num1

end if

'fix an errar

if Len(num2) > len(num1) then

num1 = "0" & num1

end if

if Len(num1) > len(num2) then

num2 = "0" & num2

end if

j = 1

p = Int(Right(num1,j))

q = Int(Right(num2,j))

result = p+q

carry = Int(result) \ 10

result = Int(Int(result) mod 10)

if Carry <> 0 then

num1 = StringAddition(Mid(num1,1,Len(num1)-1), carry) & result

end if

if Len(num1) > 1 Then

StringAddition = TrimLeadingZeros(StringAddition(Mid(num1,1,Len(num1)-1),Mid(num2,1,Len(num2)-1)) & result)

else

StringAddition = TrimLeadingZeros(carry & result)

end if

End Function

Function StringSubtraction(num1in,num2in)

' Cleanup

num1 = Trim(num1in)

num2 = Trim(num2in)

if num1 = "" and num2 = "" then

WScript.Quit

elseif num1 = "" then

StringSubtraction = num2

Exit Function

elseif num2 = "" then

StringSubtraction = num1

Exit Function

end if

'the following fixes newlines in the input

if Asc(Mid(num1,Len(num1),1)) = 13 then

num1 = Mid(num1,1,Len(num1)-1)

end if

if Asc(Mid(num2,Len(num2),1)) = 13 then

num2 = Mid(num2,1,Len(num2)-1)

end if

if Asc(Mid(num1,Len(num1),1)) = 10 then

num1 = Mid(num1,1,Len(num1)-1)

end if

if Asc(Mid(num2,Len(num2),1)) = 10 then

num2 = Mid(num2,1,Len(num2)-1)

end if

if Asc(Mid(num1,Len(num1),1)) = 13 then

num1 = Mid(num1,1,Len(num1)-1)

end if

if Asc(Mid(num2,Len(num2),1)) = 13 then

num2 = Mid(num2,1,Len(num2)-1)

end if

if num1 = "" and num2 = "" then

WScript.Quit

elseif num1 = "" then

StringSubtraction = num2

ExitFunction

elseif num2 = "" then

StringSubtraction = num1

ExitFunction

end if

If Mid(num1,1,1) = "-" and Mid(num2,1,1) = "-" Then

StringSubtraction = StringSubtraction(Mid(num2,2,Len(num2)-1),Mid(num1,2,Len(num1)-1))

Exit Function

ElseIf Mid(num1,1,1) = "-" Then

StringSubtraction = "-" & StringAddition(num2,Mid(num1,2,Len(num1)-1))

Exit Function

Elseif Mid(num2,1,1) = "-" Then

StringSubtraction = StringAddition(Mid(num2,2,Len(num2)-1),num1)

Exit Function

End If

wib = WhichIsBigger(num1,num2)

if wib = 2 then

StringSubtraction = "-" & StringSubtraction(num2,num1)

Exit Function

end if

'fix an errar

if Len(num2) > len(num1) then

num1 = "0" & num1

end if

if Len(num1) > len(num2) then

num2 = "0" & num2

end if

j = 1

p = Int(Right(num1,j))

q = Int(Right(num2,j))

result = p-q

if (result < 0) then 'and (wib <> 2) then

carry = 1

result = result + 10

end if

result = Int(Int(result) mod 10)

if Carry <> 0 then

num1 = StringSubtraction(Mid(num1,1,Len(num1)-1), Abs(carry)) & Abs(result)

end if

if Len(num1) > 1 Then

StringSubtraction = TrimLeadingZeros(StringSubtraction(Mid(num1,1,Len(num1)-1),Mid(num2,1,Len(num2)-1)) & Abs(result))

else

StringSubtraction = TrimLeadingZeros(Abs(carry) & Abs(result))

end if

End Function

' Works out which integer (stored as a string) is larger

' this is used because the large numbers we are using are not capable of being stored

' in conventional VBScript Data Types

Function WhichIsBigger(num1, num2)

WhichIsBigger = 0

if Len(num1) > Len(num2) then

WhichIsBigger = 1

elseif Len(num2) > Len(num1) then

WhichIsBigger = 2

else

for i = 1 to Len(num1)

if (Int ( Mid (num1, i, 1) ) > Int ( Mid (num2, i, 1) ) ) then

WhichIsBigger = 1

i = Len(num1)+1

elseif (Int ( Mid (num2, i, 1) ) > Int ( Mid (num1, i, 1) ) ) then

WhichIsBigger = 2

i = Len(num1)+1

end if

next

end if

End Function

0

Sign in to follow this

Followers
0

## 2 Comments

## Recommended Comments

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account## Sign in

Already have an account? Sign in here.

Sign In Now