Zum Hauptinhalt gehen

Suche

Suche

Find Largest Value From 10

Kommentare

4 Kommentare

  • Avatar
    Legacy Poster

    I'm a VB rookie myself, I looked through the wizard functions in the VB builder and didn't see anything like Max() that would do what you are looking for.  What I can say is that by using the If and Else if statements I can see why you are getting results that are wrong.  Essentially what is happening is that after it finds the first value that is greater it jumps out of your Else if loop, this is programically how the function works.

     

    Someone may have a better idea but I would create a variable to hold a value and compare each value with the next value and store it in the variable if it is larger using If Than funcitons.  These will run only if the if statement is true and will not have the same issue as the else if.

    0
  • Avatar
    Legacy Poster

    I have worked out why it wasn't showing the correct value as one of the substring inputs had an error in it which meant it could have been a string.

    I've converted all the substrings using CDbl after correcting the error and the result is now correct, just clunky!

    No longer any urgency to this but it would be nice to get an VB expert opinion on improving the script.

    0
  • Avatar
    Permanently deleted user

    In "functions and subs" declare a Max function like this:

     

    function Max(a,b) 
        Max = a 
        If b > a then Max = b 
    end function 
    

    Then use it like this:

     

    Value = Max(Saving1, Max(Saving2, Max(Saving3, Saving4)))
    

    This takes the max of 4 values but you should be able to see the pattern to extend it to as many values as you want.

     

    This will be much easier to maintain.

    0
  • Avatar
    Legacy Poster

    Great, thanks for the solution.

    0

Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.