Avatar of Vasilis Dimitrakas
Vasilis Dimitrakas
Flag for Greece 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:

var1=CDbl(str1)
var2=CDbl(str2)
var3=CDbl(str3)
var4=CDbl(str4)

Open in new window


How can I find the smallest number between var1, var2, var3 and var4?
ASPVB Script

Avatar of undefined
Last Comment
Martin Liss

8/22/2022 - Mon
Martin Liss

result = WorksheetFunction.Min(var1, var2, var3, var4)
ASKER CERTIFIED SOLUTION
Scott Fell

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Martin Liss

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,
Vasilis Dimitrakas

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.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Martin Liss

Thanks for the explanation.
Scott Fell

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.

var1=CDbl(str1)
var2=CDbl(str2)
var3=CDbl(str3)
var4=CDbl(str4)

MyArray = (var1,var2,var3,var4)
SmallestNumber = LBound(MyArray)

Open in new window


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)

Open in new window

Martin Liss

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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.