View Full Version : Getting a 0 When Dividing

03-30-2011, 01:31 PM
Hello all! First post! =]

So I wrote up a VBA macro that takes in two strings and returns a percentage of how identical the strings are. I have the code written out but for some reason, every time I attempt to divide my two numbers I get back a 0. Using two sample strings, I used MsgBox to print out the numbers my code is trying to divide with and they return 6 and 10 respectively. This should return me .60, but it just keeps returning 0.

I declared the two variables as Doubles. I tried to use "/" instead of "\". I even tried using CDbl() three times to (re)convert the two numbers and the result. I posted a snippet of the code that I believed to be relevant below. It would be great if you could assist me!

Dim splitString As Variant
Dim regionMatches As Double
Dim dec As Double
Dim arraySize As Double


regionMatches = 0

For Each part In splitString
If InStr(1, string2, part) Then
regionMatches = regionMatches + 1
End If

arraySize = UBound(splitString)
dec = regionsMatches / arraySize
MsgBox(dec) 'PRINTS OUT 0


Thank you!

03-30-2011, 02:21 PM
Welcome to VBAX
I think we need to see a whole sub. What is Part?, Splitstring?
You can post a workbook with sample data using Manage Attachments in the Go Advanced reply section

03-30-2011, 03:06 PM
Sorry, I am now at home and do not have the sample data with me. splitString is an array that contains the "parts" of my string that I used the function Split() to create. Is this enough information? Thanks for the quick reply!