array

geregs

I@mac
Local time
Today, 07:26
Joined
Feb 27, 2008
Messages
20
Hi all!
I have 5 variables, and I would like to find the smallest of them and also I would like to found the largest and all the rest sorted by size. I read that the best way to determen that is with array function, but I dont know how? The if function for something like that is too long. Can anyone help?
Thanks in advance!!!:confused:
 
Where / how are you storing the vars? In module vars?
 
yes, in the module of the form.
 
I'd just do a simple function, something linke this:

Public Function MyMax(myVar1, myVar2, myVar3, myVar4, myVar5 As Integer) As Integer

Dim maxInt As Integer
maxInt = v1

If v2 > maxInt Then x maxInt = v2
If v3 > maxInt Then x maxInt = v3
If v4 > maxInt Then x maxInt = v4
If v5 > maxInt Then x maxInt = v5

MyMax = maxInt

End Function
 
My bad:


Public Function MyMax(myVar1, myVar2, myVar3, myVar4, myVar5 As Integer) As Integer

Dim maxInt As Integer
maxInt = myVar1

If myVar2 > maxInt Then x maxInt = myVar2
If myVar3 > maxInt Then x maxInt = myVar3
If myVar4 > maxInt Then x maxInt = myVar4
If myVar5 > maxInt Then x maxInt = myVar5

MyMax = maxInt

End Function
 
This is excellent, but still I didn't finish the thing. I still have to write a big if statement because I need to know the order for the variables. Which one is the min, which one is the almost min, middle one, almost max, and max, The exact order.
 
Stuff them all into an array and perform a bubble sort.
 
Stuff them all into an array and perform a bubble sort.
I do not know how to do that???
i wonder if something like this would work...???
Code:
dim i as integer, j as integer
  dim strTemp as string, sortTemp as string, strResult as string
    dim var() as string
      dim numVars as integer (the upper bound of the "stuff" you are counting)

for i = 0 to numVars - 1
  redim preserve var(i + 1)
    var(i) = Your Value (Variable)
      i = i + 1
next i

while ubound(var)

  strTemp = var(0)
    j = 0

    for i = 1 to ubound(var)
      if strcomp(var(i), strTemp, 0) = 1 then
        strTemp = var(i)
          j = i
      end if
    next i

  sortTemp = sortTemp & strTemp
    strResult = var(j) & var(j + 1)

wend
That's probably pretty close...
 
it's simply way yo solve this problem with Dmin & Dmax (domain aggragate)
 

Users who are viewing this thread

Back
Top Bottom