OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Thread Tools Search this Thread Display Modes
Old 22-06-2017, 03:33
aakkaarr aakkaarr is offline
Senior Member
Join Date: Jan 2009
Posts: 164
Default how to find maximum value of multiple variables

how to find maximum value of multiple variables
variables x1, x2, x3, x4, x5........xN

how to find the maximum in above variables
Reply With Quote
Old 22-06-2017, 08:39
shark shark is offline
Senior Member
Join Date: Aug 2010
Location: Russia, Belgorod
Posts: 146

There are two ways to solve the problem. First - use arrays instead of regular variables. Instead x1 = 5, x2 = 3, x3 = 10 etc. use Ar(1) = 5, Ar(2) = 3, Ar(3) = 10. Then the maximum value can be calculated as follows:
Max = 0
For i = 1 to 3
    If Ar(i) > Max Then Max = Ar(i)
MsgBox "Maximum value is " & Max
Second way - use function with ParamArray:

Private Function Max(ParamArray ar())
Dim z%, Mx%
    Mx = 0
    For z = 0 To UBound(ar)
        If ar(z) > Mx Then Mx = ar(z)
    Max = Mx
End Function
Then the maximum value among the other variables can be calculated by calling one function
Dim x1%, x2%, x3%, x4%
    x1 = 10: x2 = 5: x3 = 20: x4 = 15
    MsgBox "Maximum value is " & Max(x1, x2, x3, x4)
Reply With Quote

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the maximum Page size in x5 aakkaarr CorelDRAW/Corel DESIGNER VBA 2 28-12-2010 17:34
Find/Replace Text in Multiple Open Documents jfelder Macros/Add-ons 6 20-01-2009 13:20
Is there a maximum file size for CorelDRAW? jahmer General 4 10-07-2008 17:04
Global Variables ddonnahoe CorelDRAW/Corel DESIGNER VBA 3 08-08-2005 17:10
Reset All Variables ddonnahoe Code Critique 0 06-01-2005 08:16

All times are GMT -5. The time now is 04:50.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com