Solved

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

Posted on 2004-08-26
17
253 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
  • 7
  • 6
  • 3
  • +1
17 Comments
 
LVL 19

Expert Comment

by:arif_eqbal
Comment Utility
what's the error can you elaborate
0
 

Author Comment

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

Expert Comment

by:anv
Comment Utility
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
 
LVL 19

Expert Comment

by:arif_eqbal
Comment Utility
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
Comment Utility
its doing : send "/unban " & text1x like 10 times . i dont get whats wrong
0
 
LVL 10

Expert Comment

by:anv
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 10

Expert Comment

by:anv
Comment Utility
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
Comment Utility
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
Comment Utility
great!! So ur Problem is solved...

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

Accepted Solution

by:
anv earned 500 total points
Comment Utility
:)) lol
0
 

Author Comment

by:andyakira
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now