Valhalla Legends Forums Archive | Battle.net Bot Development | removing users

AuthorMessageTime
guest-
My problem is:: When some one leaves the channel i get
"run-time error 91 - Object variable or With block variable not set" message when trying to remove that user off of my userlist. It can remove some user's off of my userlist then that message pops up.

Here's The Code

[code]
Public Sub ChatBot_OnLeave(ByVal Username As String)
main.lvUser.ListItems.Remove main.lvUserFindItem(UserName).Index
End Sub
[/code]

anyhelp would be appreciated
August 7, 2003, 12:35 AM
TeEhEiMaN
main.lvUser.ListItems.Remove main.lvUser.FindItem(UserName).Index
^
^
^
::)

That would help
August 7, 2003, 1:56 AM
Grok
If you could have a magic button that would show you errors in your code, would you push it? Well, what if it would zoom right to the error and even highlight it? Does this sound useful?

It is not magic, it is a feature of Visual Basic called explicit declaration.

Go to the menu Tools -> Options, and look on the "Editor" tab. There are checkboxes there, the second of which is "Require Variable Declaration". This box should be checked, and is not checked when you install VB. Check it now and click OK.

From now on, whenever you compile your project, Visual Basic will complain if it sees a variable which you did not Dim or Declare properly, or is not declared by an object, control, or library you are using.

The error you just posted would have been caught by the magic button.
August 7, 2003, 2:10 AM
guest-
Well i just did it...still has same problem. Then when i added error on resume next the run time stopped appearing, and thank you Grok for that option.
August 7, 2003, 4:01 AM
Grok
Oh, you also have to add

Option Explicit

as the first line of existing forms and modules that you already created before you set that checkbox. Any new forms and modules will automatically insert that line for you.
August 7, 2003, 11:00 AM
Adron
I don't understand what Grok is saying - the error you are getting is typically *not* affected by option explicit. What you are doing is dereferencing a null pointer - typically doing something with an object variable that is set to nothing.
August 7, 2003, 11:54 AM
Grok
I'm saying he would have noticed his listview typo (the missing dot) had he used the IDE option to require explicit declaration, which would have placed "Option Explicit" in his module. When he compiled, the compiler would have generated a syntax error on the typo because the variable would not be in any referenced namespace.
August 7, 2003, 9:52 PM
Adron
Are you sure? I thought option explicit covered cases where a variable is automagically declared for you, and that automagical declare would be done at compile-time, not runtime. And then it wouldn't apply to a run-time error. If I had vb5 here i'd test it :)
August 7, 2003, 10:02 PM
Grok
Right, and that's my point. You could avoid some logical errors where you had intended to user a variable name, but misspelled the name but didn't know it. VB would treat that as a variant and it would be the value Empty. You could conceivably then attempt to use that value in some way that creates a run-time error.

Thus the goal of using Option Explicit is as a tool to catch certain types of mistakes at compile time, so they don't become logic and/or runtime errors later.

All that being said, I tested VB6EE against the above code. Even leaving out the . between lvusers and FindItem(), VB compile always catches the syntax error. It doesn't create a variant object for you named lvuserFindItem automatically as I was assuming.

So in this particular instance, the sample code pasted cannot be what he actually had compiled.
August 8, 2003, 12:38 AM
Adron
OK, good, I'm totally with you now :)

Doing what he did and adding "On Error Resume Next" doesn't strike me as the best way of fixing the error...

Unless it's a case of user already being removed - then FindItem returns Nothing I'm assuming...
August 8, 2003, 8:19 AM

Search