Page 2 of 2 <12
Topic Options
#139729 - 2005-05-20 03:36 PM Re: Where is my logic wrong
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
What I want to do is sort the first main set of array's by the entry contained in the combobox's.

With this function, I am able to sort by the first combobox, but cannot fathom how to add the logic to do all three of them at the same time.



Code:

Function Filter()
$Flag = "True"
$Count = 0
$Count2 = 0

For Each $Server In $C
If $ServSort.Text = $Server
ReDIM Preserve $D1[$Count]
ReDIM Preserve $T1[$Count]
ReDIM Preserve $E1[$Count]
ReDIM Preserve $C1[$count]
ReDIM Preserve $TE1[$Count]
ReDIM Preserve $BY1[$count]
$D1[$Count] = $D[$Count2]
$T1[$Count] = $T[$Count2]
$E1[$Count] = $E[$Count2]
$C1[$Count] = $C[$Count2]
$TE1[$Count] = $TE[$Count2]
$By1[$Count] = $BY[$Count2]
$count = $count + 1

EndIf
$Count2 = $Count2 + 1
Next
$Count = $Count + 1
Update2 ()
EndFunction




What I need to do is look at each of the three variables coming from the combobox.text and compare them to the main set of array's.

If $ServSort.Text = "None" do not compare else If $Servsort.Text = $Server then compare
And If $ReportSort.Text = "None" do not compare else if $ReportSort.Text = $BY then compare
And If $ErrorSort.Text = "None" do not compare else if $ErrorSort.Text = $E then compare

I would like to do this in a single function so that at any time they click on one of the combobox entries will do the sort based on all of the criteria found within the three combobox's.

Does this make any sense?
_________________________
Today is the tomorrow you worried about yesterday.

Top
#139730 - 2005-05-20 03:58 PM Re: Where is my logic wrong
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

Does this make any sense?




Some, but if I replace "sort" with "filter" it makes a lot more.

I'm assuming that you do mean filter, rather than sort?

If so then it is quite easy. Something like this:

Code:
; Default action is to include item
$iIncludeThis=1
; If there is a server filter and server name does not match then exclude it
If $ServSort.Text<>"None" AND $ServSort.Text<>$Server $iIncludeThis=0 EndIf
; If there is a reported by filter and reported by name does not match then exclude it
If $ReportSort.Text<>"None" AND $ReportSort.Text<>$BY $iIncludeThis=0 EndIf
; If there is an error by filter and error does not match then exclude it
If $ErrorSort.Text<>"None" AND $ErrorSort.Text<>$E $iIncludeThis=0 EndIf

; Still interested?
If $iIncludeThis
; Add to the array here...
EndIf


Top
#139731 - 2005-05-20 05:15 PM Re: Where is my logic wrong
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
I think I get it. Let me piece it together into my UDF and see what the outcome is.

Thanks.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#139732 - 2005-05-20 06:29 PM Re: Where is my logic wrong
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
This is what I did, and it does not work.

Code:

Function Filter()

$iIncludeThis=1
$Flag = "True"
$Count = 0
For $count2 = 0 To UBound($c)
$Comp = $C[$count2]
$Re = $BY[$count2]
$Err = $E[$Count2]
If $ServSort.Text<>"None" AND $ServSort.Text<>$Comp $iIncludeThis=0 EndIf
If $ReportSort.Text<>"None" AND $ReportSort.Text<>$Rep $iIncludeThis=0 EndIf
If $ErrorSort.Text<>"None" AND $ErrorSort.Text<>$ERR $iIncludeThis=0 EndIf
If $iIncludeThis
ReDIM Preserve $D1[$Count]
ReDIM Preserve $T1[$Count]
ReDIM Preserve $E1[$Count]
ReDIM Preserve $C1[$count]
ReDIM Preserve $TE1[$Count]
ReDIM Preserve $BY1[$count]
$D1[$Count] = $D[$Count2]
$T1[$Count] = $T[$Count2]
$E1[$Count] = $E[$Count2]
$C1[$Count] = $C[$Count2]
$TE1[$Count] = $TE[$Count2]
$By1[$Count] = $BY[$Count2]
$count = $count + 1
EndIf

Next
$Count = 0
Update2 ()

EndFunction



My belief is that I will have to run 3 "subroutines" within the function referencing the prior array each time. Do you concur...

I.E.

ServSort Array filtered from Main Array
ReportSort Array filtered from ServSort Array
ErrorSort Array filtered from ReportSort Array

This would then give me my final array that I would then display in UPDATE2()

Like this...
Code:

$iIncludeThis=1
$Flag = "True"
$Count = 0
For $count2 = 0 To UBound($c)
$Comp = $C[$count2]
$Re = $BY[$count2]
$Err = $E[$Count2]
If $ServSort.Text<>"None" AND $ServSort.Text<>$Comp $iIncludeThis=0 EndIf


If $iIncludeThis
ReDIM Preserve $D1[$Count]
ReDIM Preserve $T1[$Count]
ReDIM Preserve $E1[$Count]
ReDIM Preserve $C1[$count]
ReDIM Preserve $TE1[$Count]
ReDIM Preserve $BY1[$count]
$D1[$Count] = $D[$Count2]
$T1[$Count] = $T[$Count2]
$E1[$Count] = $E[$Count2]
$C1[$Count] = $C[$Count2]
$TE1[$Count] = $TE[$Count2]
$By1[$Count] = $BY[$Count2]
$count = $count + 1
EndIf

Next
$Count = 0
For $count2 = 0 To UBound($c1)
$Comp = $C1[$count2]
$Re = $BY1[$count2]
$Err = $E1[$Count2]
If $ReportSort.Text<>"None" AND $ReportSort.Text<>$Rep $iIncludeThis=0 EndIf
If $iIncludeThis
ReDIM Preserve $D2[$Count]
ReDIM Preserve $T2[$Count]
ReDIM Preserve $E2[$Count]
ReDIM Preserve $C2[$count]
ReDIM Preserve $TE2[$Count]
ReDIM Preserve $BY2[$count]
$D2[$Count] = $D1[$Count2]
$T2[$Count] = $T1[$Count2]
$E2[$Count] = $E1[$Count2]
$C2[$Count] = $C1[$Count2]
$TE2[$Count] = $TE1[$Count2]
$By2[$Count] = $BY1[$Count2]
$count = $count + 1
EndIf

Next

$Count = 0
For $count2 = 0 To UBound($c1)
$Comp = $C2[$count2]
$Re = $BY2[$count2]
$Err = $E2[$Count2]
If $ErrorSort.Text<>"None" AND $ErrorSort.Text<>$ERR $iIncludeThis=0 EndIf
If $iIncludeThis
ReDIM Preserve $D3[$Count]
ReDIM Preserve $T3[$Count]
ReDIM Preserve $E3[$Count]
ReDIM Preserve $C3[$count]
ReDIM Preserve $TE3[$Count]
ReDIM Preserve $BY3[$count]
$D3[$Count] = $D2[$Count2]
$T3[$Count] = $T2[$Count2]
$E3[$Count] = $E2[$Count2]
$C3[$Count] = $C2[$Count2]
$TE3[$Count] = $TE2[$Count2]
$By3[$Count] = $BY2[$Count2]
$count = $count + 1
EndIf

Next


Update2 ()

EndFunction




I believe I would have to add some code to account for the "none" to populate the array's with all entries so as to follow the flow all the way through.



Edited by Gargoyle (2005-05-20 07:03 PM)
_________________________
Today is the tomorrow you worried about yesterday.

Top
#139733 - 2005-05-20 11:41 PM Re: Where is my logic wrong
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Help....

Here is what I came up with finally...
Code:

Function Filter()
CLS
$Flag = "True"
$Count = 0
For $count2 = 0 To UBound($c)
$iIncludeThis=0
$Comp = $C[$count2]
If $ServSort.Text = "None" OR $ServSort.Text = $Comp $iIncludeThis=1 EndIf
If $iIncludeThis = 1

ReDIM Preserve $D1[$Count]
ReDIM Preserve $T1[$Count]
ReDIM Preserve $E1[$Count]
ReDIM Preserve $C1[$count]
ReDIM Preserve $TE1[$Count]
ReDIM Preserve $BY1[$count]
$D1[$Count] = $D[$Count2]
$T1[$Count] = $T[$Count2]
$E1[$Count] = $E[$Count2]
$C1[$Count] = $C[$Count2]
$TE1[$Count] = $TE[$Count2]
$By1[$Count] = $BY[$Count2]
$count = $count + 1


EndIf
Next

$Count = 0
For $count2 = 0 To UBound($c1)
$iIncludeThis=0
$Rep = $BY1[$count2]
If $ReportSort.Text = "None" OR $ReportSort.Text = $Rep $iIncludeThis=1 EndIf
If $iIncludeThis = 1

ReDIM Preserve $D2[$Count]
ReDIM Preserve $T2[$Count]
ReDIM Preserve $E2[$Count]
ReDIM Preserve $C2[$count]
ReDIM Preserve $TE2[$Count]
ReDIM Preserve $BY2[$count]
$D2[$Count] = $D1[$Count2]
$T2[$Count] = $T1[$Count2]
$E2[$Count] = $E1[$Count2]
$C2[$Count] = $C1[$Count2]
$TE2[$Count] = $TE1[$Count2]
$By2[$Count] = $BY1[$Count2]
$count = $count + 1


EndIf

Next

$Count = 0
For $count2 = 0 To UBound($c2)
$iIncludeThis=0
$Err = $E2[$Count2]
If $ErrorSort.Text = "None" OR $ErrorSort.Text = $ERR $iIncludeThis=1 EndIf

If $iIncludeThis = 1

ReDIM Preserve $D3[$Count]
ReDIM Preserve $T3[$Count]
ReDIM Preserve $E3[$Count]
ReDIM Preserve $C3[$count]
ReDIM Preserve $TE3[$Count]
ReDIM Preserve $BY3[$count]
$D3[$Count] = $D2[$Count2]
$T3[$Count] = $T2[$Count2]
$E3[$Count] = $E2[$Count2]
$C3[$Count] = $C2[$Count2]
$TE3[$Count] = $TE2[$Count2]
$By3[$Count] = $BY2[$Count2]
$count = $count + 1


EndIf

Next

$Count = 0
Update2 ()

EndFunction



The first one works great I get my array's just like one would expect.

However when it goes to the second one it does the $count = 0 and then goes to the next $Count = 0 and then exits the function.

I can not see why it is doing this. Why will it not run the second or third instance of the filtering?
_________________________
Today is the tomorrow you worried about yesterday.

Top
#139734 - 2005-05-21 09:24 AM Re: Where is my logic wrong
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Code:
Do you concur...Code:


No. You set $iIncludeThis true in the wrong place - it will only be true once for the entire filter.

You need to set it for each entry that you will compare:
Code:
Function Filter()


$Flag = "True"
$Count = 0
For $count2 = 0 To UBound($c)
$Comp = $C[$count2]
$Re = $BY[$count2]
$Err = $E[$Count2]
$iIncludeThis=1
If $ServSort.Text<>"None" AND $ServSort.Text<>$Comp $iIncludeThis=0 EndIf
If $ReportSort.Text<>"None" AND $ReportSort.Text<>$Rep $iIncludeThis=0 EndIf
If $ErrorSort.Text<>"None" AND $ErrorSort.Text<>$ERR $iIncludeThis=0 EndIf
If $iIncludeThis
ReDIM Preserve $D1[$Count]
ReDIM Preserve $T1[$Count]
ReDIM Preserve $E1[$Count]
ReDIM Preserve $C1[$count]
ReDIM Preserve $TE1[$Count]
ReDIM Preserve $BY1[$count]
$D1[$Count] = $D[$Count2]
$T1[$Count] = $T[$Count2]
$E1[$Count] = $E[$Count2]
$C1[$Count] = $C[$Count2]
$TE1[$Count] = $TE[$Count2]
$By1[$Count] = $BY[$Count2]
$count = $count + 1
EndIf

Next
$Count = 0
Update2 ()

EndFunction


Top
#139735 - 2005-05-23 05:13 PM Re: Where is my logic wrong
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Here is what finally worked for me. Turned out that it was a problem with my not Dimming some variables.

Live and learn

Code:

Function Filter()
DIM $d1, $t1, $e1, $c1, $te1, $by1
DIM $d2, $t2, $e2, $c2, $te2, $by2
$ProgressBar.Visible = "True"
$ProgressBar.Value = 0
$Label15.Text = "Filtering"
$Flag = "True"
$Count = 0
For $count2 = 0 To UBound($c)
If $ProgressBar.Value => 100 $ProgressBar.Value = 0 EndIf
$ProgressBar.PerformStep()
$iIncludeThis=0
$Comp = $C[$count2]
If $ServSort.Text = "None" OR $ServSort.Text = $Comp $iIncludeThis=1 EndIf
If $iIncludeThis = 1

ReDIM Preserve $D1[$Count]
ReDIM Preserve $T1[$Count]
ReDIM Preserve $E1[$Count]
ReDIM Preserve $C1[$count]
ReDIM Preserve $TE1[$Count]
ReDIM Preserve $BY1[$count]
$D1[$Count] = $D[$Count2]
$T1[$Count] = $T[$Count2]
$E1[$Count] = $E[$Count2]
$C1[$Count] = $C[$Count2]
$TE1[$Count] = $TE[$Count2]
$By1[$Count] = $BY[$Count2]
$count = $count + 1

EndIf
Next
$Count = 0
For $count2 = 0 To UBound($C1)
If $ProgressBar.Value => 100 $ProgressBar.Value = 0 EndIf
$ProgressBar.PerformStep()
$iIncludeThis=0
$Rep = $BY1[$count2]
If $ReportSort.Text = "None" OR $ReportSort.Text = $Rep $iIncludeThis=1 EndIf
If $iIncludeThis = 1

ReDIM Preserve $D2[$Count]
ReDIM Preserve $T2[$Count]
ReDIM Preserve $E2[$Count]
ReDIM Preserve $C2[$count]
ReDIM Preserve $TE2[$Count]
ReDIM Preserve $BY2[$count]
$D2[$Count] = $D1[$Count2]
$T2[$Count] = $T1[$Count2]
$E2[$Count] = $E1[$Count2]
$C2[$Count] = $C1[$Count2]
$TE2[$Count] = $TE1[$Count2]
$By2[$Count] = $BY1[$Count2]
$count = $count + 1


EndIf

Next

$Count = 0
For $count2 = 0 To UBound($C2)
If $ProgressBar.Value => 100 $ProgressBar.Value = 0 EndIf
$ProgressBar.PerformStep()
$iIncludeThis=0
$Err = $E2[$Count2]
If $ErrorSort.Text = "None" OR $ErrorSort.Text = $ERR $iIncludeThis=1 EndIf

If $iIncludeThis = 1

ReDIM Preserve $D3[$Count]
ReDIM Preserve $T3[$Count]
ReDIM Preserve $E3[$Count]
ReDIM Preserve $C3[$count]
ReDIM Preserve $TE3[$Count]
ReDIM Preserve $BY3[$count]
$D3[$Count] = $D2[$Count2]
$T3[$Count] = $T2[$Count2]
$E3[$Count] = $E2[$Count2]
$C3[$Count] = $C2[$Count2]
$TE3[$Count] = $TE2[$Count2]
$By3[$Count] = $BY2[$Count2]
$count = $count + 1


EndIf

Next

$Count = 0
Update2 ()
$ProgressBar.Visible = "False"
$Label15.Text = "Filter Criteria"
EndFunction

_________________________
Today is the tomorrow you worried about yesterday.

Top
Page 2 of 2 <12


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 369 anonymous users online.
Newest Members
rrosell, PatrickPinto, Raoul, Timothy, Jojo67
17877 Registered Users

Generated in 0.059 seconds in which 0.026 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org