AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help with this please :)

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
netboom



Joined: 06 Jul 2008
Posts: 13

PostPosted: Sun Sep 21, 2008 11:29 am    Post subject: Help with this please :) Reply with quote

This code is to check that 1n or 2n matches 3n, 4n, 5n, 6n, 7n and if it does that number matches 3n, 4n, 5n, 6n, 7n. So basicly i'm check for 3 variables that have the same value using 1n or 2n but not both.

The code is working but I wanted to know if there was an easier way of doing it? thanks for any help you can give.

Code:

a::

1n = 6
2n = 8
3n = 4
4n = 7
5n = 8
6n = 6
7n = 6

if ((1n = 3n) || (1n = 4n) || (1n = 5n) || (1n = 6n) || (1n = 7n)) || ((2n = 3n) || (2n = 4n) || (2n = 5n) || (2n = 6n) || (2n = 7n))
   if ((3n = 4n) || (3n = 5n) ||(3n = 6n) ||(3n = 7n) ||(4n = 5n) || (4n = 6n) ||(4n = 7n) ||(5n = 6n) ||(5n = 7n) ||(6n = 7n))
      MsgBox, Correct
      
return
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5390
Location: /b/

PostPosted: Sun Sep 21, 2008 11:55 am    Post subject: Reply with quote

You can use If..In
_________________

Back to top
View user's profile Send private message Visit poster's website
Dra_Gon



Joined: 25 May 2007
Posts: 314

PostPosted: Sun Sep 21, 2008 7:48 pm    Post subject: Reply with quote

You could try a loop. I haven't tested this but maybe:

Code:
a::

1n = 6
2n = 8
3n = 4
4n = 7
5n = 8
6n = 6
7n = 6

Loop, 6
  {
     i := a_Index + 1
     If 1n = %i%n
       MsgBox, Correct
   }
Loop, 5
  {
     i := a_Index + 2
     If 2n = %i%n
       MsgBox, Correct
   }
Loop, 4
  {
     i := a_Index + 3
     If 3n = %i%n
       MsgBox, Correct
   }




That's about the best I can think of at the moment.

Ciao,
Dra'Gon
_________________

For a good laugh {hopefully} >> megamatts.50megs.com

My WritersCafe profile>>
http://www.writerscafe.org/writers/BlueDragonFire/
Back to top
View user's profile Send private message Send e-mail
[VxE]



Joined: 07 Oct 2006
Posts: 1496

PostPosted: Sun Sep 21, 2008 8:47 pm    Post subject: Reply with quote

Personally, I would use a set functions library and do it like this:

Code:
Set1 = 6, 8
Set2 = 4, 7, 8, 6, 6

If ( Set_Intersect( Set1, Set2 ) && Set_Size(Set2) > Set_Size(Set_Unique(Set2) ) )
      MsgBox, Correct
return

Set_Intersect(s1, s2) ; objects will be ordered as they appear in s1
{
   s2 := Set_Strip(s2)
   Loop, Parse, s1, `,, %A_Space%%A_Tab%
      If InStr( "," s2 ",", "," A_LoopField "," )
         news .= ", " A_LoopField
   return SubStr(news,3)
}

Set_Unique(Set)
{
   set := Set_Strip(set)
   Loop, Parse, set, `,, %A_Space%%A_Tab%
      If !InStr( news "," , ", " A_LoopField "," )
         news .= ", " A_LoopField
   return SubStr( news, 3 )
}

Set_Size(set)
{
   StringReplace, set, set, `,, `,, UseErrorLevel
   return (ErrorLevel + 1) * (Set != "")
}

Set_Strip(s)
{
   Loop Parse, s, `,, %A_Space%%A_Tab%
      set = %set%,%A_LoopField%
   return SubStr(set,2)
}

_________________
My Home Thread
More Common Answers: [1]. It's in the FAQ [2]. Ternary ( a ? b : c ) guide [3]. Post code inside [code][/code] tags !
Back to top
View user's profile Send private message
netboom



Joined: 06 Jul 2008
Posts: 13

PostPosted: Tue Sep 23, 2008 9:35 pm    Post subject: Reply with quote

hey guys thanks for your replys. upon further testing of my own code I found a problem. if n1 or n2 match any of n3 n5 n6 n7 and any of n3 n5 n6 n7 match themselves it shows correct. I only want it to be correct if the match in (n3 n5 n6 n7) is the same as n1 or n2. for example using your code(below) these number act the same as in my code? How would we go about changing this? also sometimes n6 and n7 are going to both be blank and dont want this to cause a problem either.

Thanks for your time.

Code:

a::

Set1 = 6, 4
Set2 = 9, 8, 8, 3, 6

If ( Set_Intersect( Set1, Set2 ) && Set_Size(Set2) > Set_Size(Set_Unique(Set2) ) )
      MsgBox, Correct
return

Set_Intersect(s1, s2) ; objects will be ordered as they appear in s1
{
   s2 := Set_Strip(s2)
   Loop, Parse, s1, `,, %A_Space%%A_Tab%
      If InStr( "," s2 ",", "," A_LoopField "," )
         news .= ", " A_LoopField
   return SubStr(news,3)
}

Set_Unique(Set)
{
   set := Set_Strip(set)
   Loop, Parse, set, `,, %A_Space%%A_Tab%
      If !InStr( news "," , ", " A_LoopField "," )
         news .= ", " A_LoopField
   return SubStr( news, 3 )
}

Set_Size(set)
{
   StringReplace, set, set, `,, `,, UseErrorLevel
   return (ErrorLevel + 1) * (Set != "")
}

Set_Strip(s)
{
   Loop Parse, s, `,, %A_Space%%A_Tab%
      set = %set%,%A_LoopField%
   return SubStr(set,2)
}

return
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group