Consulting

Results 1 to 3 of 3

Thread: Getting a 0 When Dividing

  1. #1

    Getting a 0 When Dividing

    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!


    [VBA]
    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
    Next

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

    ......
    [/VBA]

    Thank you!

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •