Is there no min() function in ebasic?

60 views
Skip to first unread message

Chris

unread,
Jul 10, 2012, 6:57:23 AM7/10/12
to e-p...@googlegroups.com
I realize I must be overlooking something, but I cannot find the minimum function.  If I just want the smaller of two variables, do I really have to construct an if statement for that?

I realize that I can also put them in a summation object and use summation.min; or I could put them in an array and sort it; but surely the min() function must exist, right?

Michiel Sovijarvi-Spape

unread,
Jul 10, 2012, 8:41:01 AM7/10/12
to e-p...@googlegroups.com

Hi,

Like you, I thought, that is pretty odd, but you seem correct anyway. Nonetheless, there's an argument to be made against packing all sorts of superfluous operations in a programming language (like VBA), if you're not using them and are easily able to add them yourself. So, just add to your user script:

 

Function min(inx As Variant, iny As Variant) As Variant

      If inx < iny Then min = inx Else min = iny     

End Function

 

Now, writing

TextDisplay1.Text = min(5,3)

for example, will show "3". Rock on, no?

Best,

Mich

--
You received this message because you are subscribed to the Google Groups "E-Prime" group.
To view this discussion on the web visit https://groups.google.com/d/msg/e-prime/-/vVI7xbobw3YJ.
To post to this group, send email to e-p...@googlegroups.com.
To unsubscribe from this group, send email to e-prime+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/e-prime?hl=en.

Christopher Chatham

unread,
Jul 10, 2012, 9:01:32 AM7/10/12
to e-p...@googlegroups.com
Yes, rock on!

I wasn't aware that we could implement functions of this kind. Thank you very much.
-Chris

David McFarlane

unread,
Jul 10, 2012, 10:09:25 AM7/10/12
to e-p...@googlegroups.com
And here is a variant using the under-appreciated IIf() function (see
that topic in the E-Basic Help facility):

Function min( inx As Variant, iny As Variant ) As Variant
min = IIf( (inx < iny), inx, iny )
End Function

-----
David McFarlane
E-Prime training
online: http://psychology.msu.edu/Workshops_Courses/eprime.aspx
Twitter: @EPrimeMaster (twitter.com/EPrimeMaster)

Michiel Sovijarvi-Spape

unread,
Jul 10, 2012, 10:23:40 AM7/10/12
to e-p...@googlegroups.com

Hi,

It can be really quite useful to clean up some code, especially if you write a lot of these long statements. I also use it a lot for the code-intensive parts i reuse between experiments, such as making random noise masks with some canvas-code because, quite often, I am really just too lazy to look up exactly how one goes about doing these things.

Cheers,

Mich

Michiel Sovijarvi-Spape

unread,
Jul 10, 2012, 10:55:42 AM7/10/12
to e-p...@googlegroups.com
Hi,
Wow, almost brings a C elegance to VB :) I benchmarked the functions, yours
is .3 microsecond shorter, though the difference is not statistically
significant. Good to know, For Science.
Best,
Michiel
Reply all
Reply to author
Forward
0 new messages