Jump to content

Recommended Posts

Posted

$RenamedProfName="Renamed"
$SelectedProfile_Name="Original"

If ((Not $RenamedProfName="") And (Not $RenamedProfName=$SelectedProfile_Name)) Then            
        MsgBox(0,"","it worked")
EndIfoÝ÷ ØZèZ¶+§uê쵩ݶ¬².Û!£azk n[ºØ­v¬Ü!z·±«­¢+ØÀÌØíI¹µAɽ9µôÅÕ½ÐíI¹µÅÕ½Ðì(ÀÌØíM±ÑAɽ¥±}9µôÅÕ½Ðí=É¥¥¹°ÅÕ½Ðì()%  ÀÌØíI¹µAɽ9µ±ÐìÐìÅÕ½ÐìÅÕ½Ð줹 ÀÌØíI¹µAɽ9µ±ÐìÐìÀÌØíM±ÑAɽ¥±}9µ¤¤Q¡¸$$$($%5Í   ½à À°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½Ðí¥ÐݽɭÅÕ½Ðì¤)¹%

works

Posted (edited)

$RenamedProfName = "Renamed"
$SelectedProfile_Name = "Original"

If Not ($RenamedProfName = "") And Not ($RenamedProfName = $SelectedProfile_Name) Then           
        MsgBox(0,"","it worked")
EndIf
oÝ÷ Ù«­¢+Ø(ÀÌØíI¹µAɽ9µôÅÕ½ÐíI¹µÅÕ½Ðì(ÀÌØíM±ÑAɽ¥±}9µôÅÕ½Ðí=É¥¥¹°ÅÕ½Ðì()%ÀÌØíI¹µAɽ9µ±ÐìÐìÅÕ½ÐìÅÕ½Ðì¹ÀÌØíI¹µAɽ9µ±ÐìÐìÀÌØíM±ÑAɽ¥±}9µQ¡¸(5Í    ½à À°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½Ðí¥ÐݽɭÅÕ½Ðì¤)¹%(

Clearly the best is the last as you are checking indifference with <> which is the most direct syntax. The 1st is convulted as Not has the highest precedence so it evaluates the condition immediately next to it 1st (which is giving you the wrong result that you may want to expect)

Look close at Operator in the help file for operator precedence.

:whistle:

Edited by MHz
Posted

Thanks MHZ that kinda clears things up.

while im on the topic of logical operators can i ask you what is the best way of checking if any 2 values are the same from 4 values.

e.g. values are 1,2,4,2 need to find if any two values are the same

would i have to check the first one against the other 3 then the second one against the last 2 then 3rd one against the last. this is the only way i can think of but it seems kind of longwinded

Posted

I Couldnt come up with anything better :whistle:

$Duplicates=0
            for $i=1 to 3
                for $f=$i+1 to 4
                    if GUICtrlRead($Inpt_ButTitle[$i])=GUICtrlRead($Inpt_ButTitle[$f]) then 
                        $Duplicates=1
                        ExitLoop 2
                    EndIf
                Next
            Next
            if $Duplicates=0 then
Posted

...what is the best way of checking if any 2 values are the same from 4 values.

Using arrays are easier then checking for double values in variables.

This is one way to check using variable to array conversion to get the double value.

$apple = 1
$orange = 2
$grape = 4
$banana = 2

$result = _FindDouble($apple & '|' & $orange & '|' & $grape & '|' & $banana)
If Not @error Then
    MsgBox(0, 'Double found', $result)
EndIf

Func _FindDouble($var)
    $array = StringSplit($var, '|')
    $size = UBound($array) - 1
    For $i = 1 To $size
        For $ii = 1 To $size
            If $i = $ii Then ContinueLoop
            If $array[$i] = $array[$ii] Then
                Return $array[$i]
            EndIf
        Next
    Next
    Return SetError(1, 0, 0)
EndFunc

If the values were stored in an array already then the code would have been less. An If...Then with checking variables against another would be a large structure to ensure a double value does exist.

Posted (edited)

Mhz Ive done it differently Ive used

for $ii=$i+1 to $size

in the second loop to not compare the same thing twice

Edited by Cue

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...