Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

am i doing it wrong? how can i improve this code.

Posted on 2004-08-26
17
Medium Priority
?
260 Views
Last Modified: 2010-04-17
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
Comment
Question by:andyakira
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 3
  • +1
17 Comments
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 11909837
what's the error can you elaborate
0
 

Author Comment

by:andyakira
ID: 11909841
it adds whatever is in text1x , even though some matches are in the list.
0
 
LVL 10

Expert Comment

by:anv
ID: 11909873
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
Industry Leaders: 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!

 
LVL 19

Expert Comment

by:arif_eqbal
ID: 11909971
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
 

Author Comment

by:andyakira
ID: 11909981
its doing : send "/unban " & text1x like 10 times . i dont get whats wrong
0
 
LVL 10

Expert Comment

by:anv
ID: 11910011
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
 

Author Comment

by:andyakira
ID: 11910132
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
 
LVL 10

Expert Comment

by:anv
ID: 11910159
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
 
LVL 10

Expert Comment

by:anv
ID: 11910161
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
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 11910921
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
 
LVL 10

Expert Comment

by:anv
ID: 11910962
great!! So ur Problem is solved...

how much points will i get now??
0
 
LVL 10

Accepted Solution

by:
anv earned 2000 total points
ID: 11910968
:)) lol
0
 

Author Comment

by:andyakira
ID: 11914153
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
 

Author Comment

by:andyakira
ID: 11914275
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
 

Author Comment

by:andyakira
ID: 11914323
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
 
LVL 26

Expert Comment

by:EDDYKT
ID: 11917557
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
 

Author Comment

by:andyakira
ID: 11917940
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

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Six Sigma Control Plans

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question