Vasilis Dimitrakas
asked on
How can I find the smallest number between variables?
I have 4 variables which they contain some values.
I have already convert them in numbers with CDbl.
So I have something like that:
How can I find the smallest number between var1, var2, var3 and var4?
I have already convert them in numbers with CDbl.
So I have something like that:
var1=CDbl(str1)
var2=CDbl(str2)
var3=CDbl(str3)
var4=CDbl(str4)
How can I find the smallest number between var1, var2, var3 and var4?
result = WorksheetFunction.Min(var1 , var2, var3, var4)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Vasilis, I'm not complaining about you choosing Scott's answer, you win some and you lose some, but I'm just wondering why you chose it since my one-line code does what you asked for,
ASKER
@Martin Liss
Dear Martin,
Thank you for you interest in my question.
Obviously, I don’t have any reason choosing the other answer. The only reason is that I am not familiar at all with the “WorksheetFunction.Min” and with the first look it seams that is for Excel sums. The other solution, was more familiar to me for using it in my classic asp web page.
Thank you once again.
Dear Martin,
Thank you for you interest in my question.
Obviously, I don’t have any reason choosing the other answer. The only reason is that I am not familiar at all with the “WorksheetFunction.Min” and with the first look it seams that is for Excel sums. The other solution, was more familiar to me for using it in my classic asp web page.
Thank you once again.
Thanks for the explanation.
Martin,
Your solution is for Excel-vba. This is for vbscript which is not the same thing. However, there is a similar function called LBound which will return the lowest item in an array just as Ubound will return the highest.
If you have your data in an array instead of the way it is presented, you could use Lbound.
https://www.w3schools.com/asp/func_lbound.asp
https://www.w3schools.com/asp/func_array.asp
Arrays are not always easy to work with in vbscript/asp but in this case, getting the smallest number in an array using LBound could be a good choice and would be similar to Excel VBA
Your solution is for Excel-vba. This is for vbscript which is not the same thing. However, there is a similar function called LBound which will return the lowest item in an array just as Ubound will return the highest.
If you have your data in an array instead of the way it is presented, you could use Lbound.
var1=CDbl(str1)
var2=CDbl(str2)
var3=CDbl(str3)
var4=CDbl(str4)
MyArray = (var1,var2,var3,var4)
SmallestNumber = LBound(MyArray)
https://www.w3schools.com/asp/func_lbound.asp
https://www.w3schools.com/asp/func_array.asp
Arrays are not always easy to work with in vbscript/asp but in this case, getting the smallest number in an array using LBound could be a good choice and would be similar to Excel VBA
result = WorksheetFunction.Min(var1, var2, var3, var4)
Thanks Scott. Im sure your aware that LBound is also available in VBA, but in VBA SmallestNumber = LBound(MyArray) would just return the Index of the lower bound of the MyArray.