cla721 Member Licensed User Longtime User Dec 14, 2011 #1 I need an idea for a code to the following question: A = 75 B = 1000 C = 25 D = 55 Wich one (A, B, C or D) is lowest...? Best regards Claus
I need an idea for a code to the following question: A = 75 B = 1000 C = 25 D = 55 Wich one (A, B, C or D) is lowest...? Best regards Claus
M mjcoon Well-Known Member Licensed User Dec 14, 2011 #2 cla721 said: I need an idea for a code to the following question: A = 75 B = 1000 C = 25 D = 55 Wich one (A, B, C or D) is lowest...? Best regards Claus Click to expand... Easy: answer is "C"! Code: Copy lowest = A lowName = "A" If lowest > B Then lowest = B lowName = "B" End If Repeat "If ..." for however many more variables... HTH, Mike.
cla721 said: I need an idea for a code to the following question: A = 75 B = 1000 C = 25 D = 55 Wich one (A, B, C or D) is lowest...? Best regards Claus Click to expand... Easy: answer is "C"! Code: Copy lowest = A lowName = "A" If lowest > B Then lowest = B lowName = "B" End If Repeat "If ..." for however many more variables... HTH, Mike.
klaus Expert Licensed User Longtime User Dec 15, 2011 #4 You could also use: Code: Copy lowest = Min(A, B) lowest = Min(lowest, C) lowest = Min(lowest, D) Best regards.
You could also use: Code: Copy lowest = Min(A, B) lowest = Min(lowest, C) lowest = Min(lowest, D) Best regards.
M mjcoon Well-Known Member Licensed User Dec 15, 2011 #5 klaus said: You could also use: Code: Copy lowest = Min(A, B) lowest = Min(lowest, C) lowest = Min(lowest, D) Best regards. Click to expand... That illustrates the need to specify the problem fully: do we merely have to determine the lowest value, or also which one (A|B|C|D) it was? Mike.
klaus said: You could also use: Code: Copy lowest = Min(A, B) lowest = Min(lowest, C) lowest = Min(lowest, D) Best regards. Click to expand... That illustrates the need to specify the problem fully: do we merely have to determine the lowest value, or also which one (A|B|C|D) it was? Mike.
warwound Expert Licensed User Longtime User Dec 17, 2011 #6 If it's not required to find which variable has the lowest value - it is instead just the lowest value which is required then... Add all values to a List and use the List Sort method. That way you could easily get both the lowest value and the highest value if required. Martin.
If it's not required to find which variable has the lowest value - it is instead just the lowest value which is required then... Add all values to a List and use the List Sort method. That way you could easily get both the lowest value and the highest value if required. Martin.
M mjcoon Well-Known Member Licensed User Dec 17, 2011 #7 warwound said: If it's not required to find which variable has the lowest value - it is instead just the lowest value which is required then... Add all values to a List and use the List Sort method. That way you could easily get both the lowest value and the highest value if required. Martin. Click to expand... Also true, but that illustrates the different hidden criteria behind coding. It would require writing more lines of code, the real intention would not be so obvious (because the sorted list is in fact not needed) and would take much more execution time (because sorting is not linear with the number of items being sorted). On the other hand, if the list being sorted was of a value-key pair, the key could be used to tag each value with the identity of the originating variable. Thus the identity of the highest and lowest values would then be available... Mike.
warwound said: If it's not required to find which variable has the lowest value - it is instead just the lowest value which is required then... Add all values to a List and use the List Sort method. That way you could easily get both the lowest value and the highest value if required. Martin. Click to expand... Also true, but that illustrates the different hidden criteria behind coding. It would require writing more lines of code, the real intention would not be so obvious (because the sorted list is in fact not needed) and would take much more execution time (because sorting is not linear with the number of items being sorted). On the other hand, if the list being sorted was of a value-key pair, the key could be used to tag each value with the identity of the originating variable. Thus the identity of the highest and lowest values would then be available... Mike.