+ Reply to Thread
Results 1 to 8 of 8

Parsing a string into numeric values

  1. #1
    Registered User
    Join Date
    03-07-2004
    Location
    St. John's, NFLD
    Posts
    11

    Parsing a string into numeric values

    Hi,

    Its been a long while since I've done much with excel/VBA. I'm wondering if anybody could help point me in the right direction.

    The user enters a series of numeric values (comma seperated) into a text box called txtmeasures on a form.

    These values are all stored as a string in a variable called 'txtval'.

    I want to be able to take each individual value stored in that string and compare it to a range.

    The range is pre-determined based on a previous selection from a dropdown box.

    The range can appear as any of the three scenarios below:

    > X

    < X

    X < Y < Z

    Where X and Y and Z are integers


    A calculation is then carried out based on the following:

    X = [Sum only those values that fall within the specified range] / [Sum all entered values]

    My real issue comes from parsing those values stored in 'txtval' and figuring out how to store and compare them to the range and thus obtaining the result of my calculation.

    If I can get any help that would be greatly appreciated.

    Thank you!
    Last edited by Excel-erate2004; 06-25-2007 at 07:46 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    X < Y < X
    That one is not possible.

    The Split function will parse the comma delimited string into substrings, which you can coerce to numeric values using CDbl() or similar function. Then you can perform whatever calculations are appropriate using a Case statement. If you clarify your question, I or someone else will help.

  3. #3
    Registered User
    Join Date
    03-07-2004
    Location
    St. John's, NFLD
    Posts
    11
    To clarify:

    For example: txtval (string) will store the following values:

    1, 2, 3, 4 = txtval

    My range is anything greater than or equal to 2 or less than or equal to 4.

    Therefore, my calculation would be as follows:

    X = [Sum those numbers that fall within the range] / [sum of all numbers]

    X = 2 + 3 + 4 / 10

    X = 9/10

    X = 0.9

    So I guess my question is how do I take txval and 'break' it back into individual numbers that I can use in my calculations.

  4. #4
    Registered User
    Join Date
    03-07-2004
    Location
    St. John's, NFLD
    Posts
    11
    My fault I caused some confusion when describing the range as

    X<Y< X

    It should be X<Y<Z.

    Thank you

  5. #5
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    How about creating a function to do the calculation, and working from there.

    In the code below, I've dummied up a string with comma separated values. the function takes that string, a lower number and an upper number and returns the result.

    Please Login or Register  to view this content.
    Hope that gets you going.


    rylo

  6. #6
    Registered User
    Join Date
    03-07-2004
    Location
    St. John's, NFLD
    Posts
    11
    Thanks Rylo, I'll give that a try later today and get back to you.

    Cheers!

  7. #7
    Registered User
    Join Date
    03-07-2004
    Location
    St. John's, NFLD
    Posts
    11
    I was able to get a variation of your code working, thank you for your help! No I just have to try and shake this rust off!

    Cheers!

  8. #8
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Care to share your final working solution with the forum???


    rylo

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1