andyakira
asked on
am i doing it wrong? how can i improve this code.
For i = 0 To Form1.banned.ListCount - 1
If LCase(text1x) Like "*" & LCase(Form1.banned.list(i) ) & "*" Then
'MsgBox Form1.banned.list(i)
send "/unban " & Form1.banned.list(i)
else
send "/unban " & text1x
End If
Next i
basically it searches the banned.list for a matching text *text* , *text, text*, and /unbans them 1 by 1, and if the text is not in the list then just /unban & the original text without the * btw its not working :{
If LCase(text1x) Like "*" & LCase(Form1.banned.list(i)
'MsgBox Form1.banned.list(i)
send "/unban " & Form1.banned.list(i)
else
send "/unban " & text1x
End If
Next i
basically it searches the banned.list for a matching text *text* , *text, text*, and /unbans them 1 by 1, and if the text is not in the list then just /unban & the original text without the * btw its not working :{
what's the error can you elaborate
ASKER
it adds whatever is in text1x , even though some matches are in the list.
why dont u use
instr instead of Like
here's how ur code will go using instr
For i = 0 To Form1.banned.ListCount - 1
If instr(1,LCase(text1x),Form 1.banned.l ist(i),vbT extCompare )) then
'MsgBox Form1.banned.list(i)
send "/unban " & Form1.banned.list(i)
else
send "/unban " & text1x
End If
Next i
instr instead of Like
here's how ur code will go using instr
For i = 0 To Form1.banned.ListCount - 1
If instr(1,LCase(text1x),Form
'MsgBox Form1.banned.list(i)
send "/unban " & Form1.banned.list(i)
else
send "/unban " & text1x
End If
Next i
You can use InStr of course but your If clause is fine
there's no problem in the If clause.
Check your logic
You are matching a part of text1x with list value
if text1x value is ABCD and List contains CD it will match and call send "/unban " & Form1.banned.list(i)
not the other way round i.e. if text1x value is CD and list contains ABCD it will call send "/unban " & text1x
If this is what you want its working fine for me...
there's no problem in the If clause.
Check your logic
You are matching a part of text1x with list value
if text1x value is ABCD and List contains CD it will match and call send "/unban " & Form1.banned.list(i)
not the other way round i.e. if text1x value is CD and list contains ABCD it will call send "/unban " & text1x
If this is what you want its working fine for me...
ASKER
its doing : send "/unban " & text1x like 10 times . i dont get whats wrong
could u xplain it with an example what exactly u want
say if the list item is "abcdefg" then if text1 has "ab" or "cd" etc... then ur condition is true is this what u want??
if yes then best would be to use Instr
say if the list item is "abcdefg" then if text1 has "ab" or "cd" etc... then ur condition is true is this what u want??
if yes then best would be to use Instr
ASKER
the list:
anv
andy
andz
candy
blur
scout
haste
doom
anvil
if text1x=an* or *n* or *nv it would find the following matches: anv, anvil
if text1x=o* it would find the following matches: doom, scout
-Andy
anv
andy
andz
candy
blur
scout
haste
doom
anvil
if text1x=an* or *n* or *nv it would find the following matches: anv, anvil
if text1x=o* it would find the following matches: doom, scout
-Andy
hi andy
try this
For i = 0 To Form1.banned.ListCount - 1
If (Form1.banned.List(i) - 1
Like Text1) Then
'MsgBox Form1.banned.list(i)
send "/unban " & Form1.banned.list(i)
else
send "/unban " & text1x
End If
Next
try this
For i = 0 To Form1.banned.ListCount - 1
If (Form1.banned.List(i) - 1
Like Text1) Then
'MsgBox Form1.banned.list(i)
send "/unban " & Form1.banned.list(i)
else
send "/unban " & text1x
End If
Next
i hope in the text box u r passing values like this
*an* or *an or an*
in your code u will have to interchange the positions of text and Form1.banned.List(i)
hope it helped
*an* or *an or an*
in your code u will have to interchange the positions of text and Form1.banned.List(i)
hope it helped
that's the problem actually...
even in your first code if you interchange the positions of text1x and Form1.banned.List(i) it would work.
even in your first code if you interchange the positions of text1x and Form1.banned.List(i) it would work.
great!! So ur Problem is solved...
how much points will i get now??
how much points will i get now??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yes it works, now. but theres a problem: even if there is matches in the list (after successfully unbanning the matches) it does a /unban & text1x. how do i make it not do a /unban text1x after it finds / unbans the matches?
ASKER
everytime there is no match, it adds a /unban text1x to the queue. so if theres 30 names in that bannedlist and there are no matches it does /unban text1x 30 times.
ASKER
For i = 0 To Form1.banned.ListCount - 1
If LCase(Form1.banned.list(i) ) Like "*" & LCase(text1x) & "*" Then
send "/unban " & Form1.banned.list(i)
End If
Next i
send "/unban " & text1x
if i put it like this it still sends /unban " & text1x after fixing searching/unbanning the list
If LCase(Form1.banned.list(i)
send "/unban " & Form1.banned.list(i)
End If
Next i
send "/unban " & text1x
if i put it like this it still sends /unban " & text1x after fixing searching/unbanning the list
then use variable
ie
dim found as boolean
For i = 0 To Form1.banned.ListCount - 1
If LCase(Form1.banned.list(i) ) Like "*" & LCase(text1x) & "*" Then
send "/unban " & Form1.banned.list(i)
found = true
End If
Next i
if not found then send "/unban " & text1x
ie
dim found as boolean
For i = 0 To Form1.banned.ListCount - 1
If LCase(Form1.banned.list(i)
send "/unban " & Form1.banned.list(i)
found = true
End If
Next i
if not found then send "/unban " & text1x
ASKER
thanks all, i wish i can split the points since everyone helped on this one. anv can choose to accept assisted answer from arif_eqbal if he likes :)