Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

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 :{
0
andyakira
Asked:
andyakira
  • 7
  • 6
  • 3
  • +1
1 Solution
 
arif_eqbalCommented:
what's the error can you elaborate
0
 
andyakiraAuthor Commented:
it adds whatever is in text1x , even though some matches are in the list.
0
 
anvCommented:
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),Form1.banned.list(i),vbTextCompare)) then
 'MsgBox Form1.banned.list(i)
send "/unban " & Form1.banned.list(i)
else
send "/unban " & text1x
 End If
Next i
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
arif_eqbalCommented:
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...
0
 
andyakiraAuthor Commented:
its doing : send "/unban " & text1x like 10 times . i dont get whats wrong
0
 
anvCommented:
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
0
 
andyakiraAuthor Commented:
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
0
 
anvCommented:
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
0
 
anvCommented:
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
0
 
arif_eqbalCommented:
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.

0
 
anvCommented:
great!! So ur Problem is solved...

how much points will i get now??
0
 
anvCommented:
:)) lol
0
 
andyakiraAuthor Commented:
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?
0
 
andyakiraAuthor Commented:
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.
0
 
andyakiraAuthor Commented:
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
0
 
EDDYKTCommented:
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
0
 
andyakiraAuthor Commented:
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 :)
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 7
  • 6
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now