Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with application logic - issuing commands 1

Status
Not open for further replies.

nickd87

Technical User
Jan 18, 2006
110
AU
I need some help kicking my brain into gear!

I have an application that I have put a winsock control on so that I can telnet to it and issue commands. All commands are in the format <action> <object> <qualifier>, so for example 'change ip-address 127.0.0.1'.

I want to implement something where I can only partially enter the keywords and have the application automatically fill in the rest. So I could issue 'cha ip-a 127.0.0.1' and that would be equivalent to the above.

Now, some of the commands begin with the same first few letters, for example we have 'change ip-address' and 'change ip-phone-config' and so on. So, yes, the user would need to enter the minimum amount of letters that are required to eliminate ambiguity. I have tried to achieve this by checking for the Left$() of what I know is the minimum command that is not ambiguous. However, this isn't quite right because I could enter something like 'cha ip-a-boo! 127.0.0.1' and it would pick it up as 'chang ip-address 127.0.0.1'.

Can someone think of a better way to implement what I'm trying to do? I'm stumped!

Thanks

Nick
 
It depends on how many commands there are, but regular expressions may be a way. RegEx will evaluate a text to see if it matches the patter you define.

 
You need to test the whole abbreviated command against the same length piece of each command to see if there's a unique match. That will handle the ip-a-boo! piece matching erroneously.

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
Thank you ArtieChoke - I've got it working the way it should now!

But now I have the problem of ambiguous commands. It just picks up the first command that matches in the Collection.

How should I check for ambiguity ?
 
Keep checking and keep a count of all matches. Once you come out of the loop, check the count and if it's > 1, then you have an ambiguous match and kick it back to the user.

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
Thank you - perfect!

You know, it's amazing what someone else's brain can do to another's.
 
That and experience... :)

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
Umm, sorry just another quick question:

How do you delete everything in a collection? Do I have to loop through them and do .Remove?
 
Just checked the members - there is no clear operation, so you'll have to loop.

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
I tried doing "Set myCollection = Nothing" and it worked. Don't know if that's the right way, but it worked nonetheless; no looping required.
 
Yeah, that'll work. You are disposing of the collection object. Then you have to recreate it again. Takes a little time, but on a 3GHz machine, not gonna be a big deal! :)

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
>Takes a little time

Sure, but disposing of each collection item one by one also takes a little time. But, as you say, who's going to notice?
 
Based on a small test of 100,000 entries in a collection, getting rid of the object is around twice as fast as singly removing each entry. It was still around .1 second, so either way it's not gonna matter much! :)

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top