Valhalla Legends Forums Archive | Battle.net Bot Development | Code not activating from module.

AuthorMessageTime
GoSu_KaOs
Aight, I got this:

[code]

'moduleBnet"
ID_JOIN
frmMain.figureout
****

'frmMain
Sub figureout()
Dim itm1 As ListItem, itm2 As ListItem
Dim str1 As String, str2 As String

For Each itm1 In frmAliasManager.lvAliases.ListItems 'loop the first listview
If InStr(1, itm1.Text, ":") Then 'just make sure ":" is in there
 str1 = Left$(LCase(itm1.Text), InStr(1, LCase(itm1.Text), ":") - 1)  'get the leftside of ":"
 str2 = Mid$(LCase(itm1.Text), InStr(1, LCase(itm1.Text), ":") + 1)  'get the rightside of ":"
 
  For Each itm2 In Form1.ChannelList.ListItems 'loop second listview
   If LCase(itm2.Text) = str1 Then  'see if it matches the string
     itm2.Text = str2 'if it does, change it
   End If
  Next itm2
End If
Next itm1
End Sub
[/code]

The problem is, When someone joins a channel, eveyrthing under ID_JOIN activates exept frmMain.Figureout. When I put Call frmMain.Figureout ina  button, it works. But in moduleBnet, it doesent activate. This is gettin frustrating.

Help?
January 28, 2005, 2:15 AM
Kp
[quote author=GoSu_KaOs link=topic=10337.msg97035#msg97035 date=1106878533]Help?[/quote]

Yes: write better code.  I'm pretty sure even VB supports splitting text on a delimiter, so that left/mid construct isn't needed.
January 28, 2005, 2:31 AM
Newby
[quote author=Kp link=topic=10337.msg97042#msg97042 date=1106879506]
[quote author=GoSu_KaOs link=topic=10337.msg97035#msg97035 date=1106878533]Help?[/quote]

Yes: write better code.  I'm pretty sure even VB supports splitting text on a delimiter, so that left/mid construct isn't needed.
[/quote]
Split()
January 28, 2005, 2:35 AM
GoSu_KaOs
[quote author=Kp link=topic=10337.msg97042#msg97042 date=1106879506]
[quote author=GoSu_KaOs link=topic=10337.msg97035#msg97035 date=1106878533]Help?[/quote]

Yes: write better code.  I'm pretty sure even VB supports splitting text on a delimiter, so that left/mid construct isn't needed.
[/quote]

What does left/mid have to do with ID_JOIN.
It doesnt activate the code. I tryed making it, Sub figureout, module1.figureout, Call figureout, still not activating.
January 28, 2005, 2:43 AM
Networks
[quote author=GoSu_KaOs link=topic=10337.msg97047#msg97047 date=1106880219]
[quote author=Kp link=topic=10337.msg97042#msg97042 date=1106879506]
[quote author=GoSu_KaOs link=topic=10337.msg97035#msg97035 date=1106878533]Help?[/quote]

Yes: write better code.  I'm pretty sure even VB supports splitting text on a delimiter, so that left/mid construct isn't needed.
[/quote]

What does left/mid have to do with ID_JOIN.
It doesnt activate the code. I tryed making it, Sub figureout, module1.figureout, Call figureout, still not activating.
[/quote]

use debug.print and figure out where the problem lies.
January 28, 2005, 3:20 AM
The-FooL
Do you have an Error handler somewhere that may be causing it to stop execution? 

Also, make a breakpoint at the top of ID_Join and step through to find the problem.
January 28, 2005, 3:23 AM
GoSu_KaOs
Fixed it! The problem was, I put frmMain.Figureout before the usernames were added to the Listview.

But now, when the userleaves the channel, the renamed username doesent get removed from the listview.

This is my ID_LEAVE code:

[code]Case ID_LEAVE
For X = 1 To Form1.ChannelList.ListItems.Count
  If frmMain.ChannelList.ListItems.Item(X).Text = Username Then
    frmMain.ChannelList.ListItems.Remove (frmMain.ChannelList.FindItem(Username).Index)
End If
Next X
[/code]

The problem is , this code compares the Username and the text in the listview. If the username is the same as the listview, it removes the text from the listview. But now, since the listview text is renamed, the code doesnt remove it because the Username and the listview text doesnt match up.
Is there a way to fix this?

I was thinking, mabe using the Split meathod I used before, but in reverse. It loads all the usernames that are stored as "username1:alias1", get the text before and after the ":", and use the text before the ":" to find the text after ":" in the listview. Then remove the text.

I cant figure out how to write this.
January 28, 2005, 5:02 AM
Adron
[quote author=Kp link=topic=10337.msg97042#msg97042 date=1106879506]
[quote author=GoSu_KaOs link=topic=10337.msg97035#msg97035 date=1106878533]Help?[/quote]

Yes: write better code.  I'm pretty sure even VB supports splitting text on a delimiter, so that left/mid construct isn't needed.
[/quote]

VB5 doesn't. Have to use the Left/Mid thing.
January 28, 2005, 9:26 AM
iago
[quote author=Adron link=topic=10337.msg97098#msg97098 date=1106904392]
[quote author=Kp link=topic=10337.msg97042#msg97042 date=1106879506]
[quote author=GoSu_KaOs link=topic=10337.msg97035#msg97035 date=1106878533]Help?[/quote]

Yes: write better code.  I'm pretty sure even VB supports splitting text on a delimiter, so that left/mid construct isn't needed.
[/quote]

VB5 doesn't. Have to use the Left/Mid thing.
[/quote]

Then the suggestion would be to use a more up-to-date language.  Java 1.3 also doesn't have split(), so I update to Java 1.4 :)
January 28, 2005, 2:32 PM
GoSu_KaOs
I need this done in a few days, can anyone figure out how to remove the changed username from the listview?

I've been tying but all I get is errors.
January 28, 2005, 4:11 PM
drivehappy
[code]
Case ID_LEAVE
For X = 1 To Form1.ChannelList.ListItems.Count
  If frmMain.ChannelList.ListItems.Item(X).Text = Username Then
    frmMain.ChannelList.ListItems.Remove (frmMain.ChannelList.FindItem(Username).Index)
End If
Next X
[/code]

One problem is you're using a 1 based counting system on a zero based index. Also, I don't see why you need to find the username again to remove it, the index x should contain it if it fulfills the IF condition. Also you should either convert everything to upper case or lower case to compare usernames.

[code]
Case ID_LEAVE
For X = 0 To Form1.ChannelList.ListItems.Count - 1
  If UCase(frmMain.ChannelList.ListItems.Item(X).Text) = UCase(Username) Then
    frmMain.ChannelList.ListItems.Remove (X)
    X = X - 1 'Compensate for the removed item
End If
Next X
[/code]
January 28, 2005, 5:42 PM
GoSu_KaOs
Aight.. This works..

[code]

Sub RemoveUser()
On Error GoTo error
Dim itm1 As ListItem, itm2 As ListItem
Dim str1 As String, str2 As String

For Each itm1 In frmManagers.lvAliases.ListItems  'loop the first listview
If InStr(1, itm1.Text, ":") Then 'just make sure ":" is in there
  str1 = Left$(LCase(itm1.Text), InStr(1, LCase(itm1.Text), ":") - 1)  'get the leftside of ":"
  str2 = Mid$(LCase(itm1.Text), InStr(1, LCase(itm1.Text), ":") + 1)  'get the rightside of ":"
 
  For Each itm2 In Form1.ChannelList.ListItems  'loop second listview
    If LCase(itm2.Text) = str2 Then  'see if it matches the string
      'itm2.Text = str2 'if it does, change it
      Form1.ChannelList.ListItems.Remove (Form1.ChannelList.FindItem(str2).Index)
    End If
  Next itm2
End If
Next itm1
error:
End Sub[/code]

BUT, If I take off the error handler, I get an error, " Control's collection has been modified." and it highlights Next itm2. But when I press play again, it sais," For loop not initialized.".

Will this make a problem or can I just leave it with the errors.
January 28, 2005, 10:31 PM
tA-Kane
[quote author=GoSu_KaOs link=topic=10337.msg97158#msg97158 date=1106951487]Will this make a problem or can I just leave it with the errors.[/quote]You should always catch and properly handle your errors.

[quote]On Error GoTo Hell[/quote]
January 28, 2005, 11:57 PM
GoSu_KaOs
Can someone tell me why the error is showing up ("Control's collection has been modified")?
January 29, 2005, 6:39 AM
Myndfyr
[quote author=GoSu_KaOs link=topic=10337.msg97226#msg97226 date=1106980776]
Can someone tell me why the error is showing up ("Control's collection has been modified")?
[/quote]

Because you're changing the control's collection while inside the For Each statement, which operates on an enumerator.
January 29, 2005, 10:41 AM
R.a.B.B.i.T
[quote author=Adron link=topic=10337.msg97098#msg97098 date=1106904392]
[quote author=Kp link=topic=10337.msg97042#msg97042 date=1106879506]
[quote author=GoSu_KaOs link=topic=10337.msg97035#msg97035 date=1106878533]Help?[/quote]

Yes: write better code.  I'm pretty sure even VB supports splitting text on a delimiter, so that left/mid construct isn't needed.
[/quote]

VB5 doesn't. Have to use the Left/Mid thing.
[/quote]He could always MAKE one.
January 29, 2005, 11:51 PM
GoSu_KaOs
So how can I prevent this?
January 31, 2005, 2:22 AM
Kp
[quote author=GoSu_KaOs link=topic=10337.msg97546#msg97546 date=1107138146]So how can I prevent this?[/quote]

Use only functions, not member methods.  Or if you must use a member method, make it static.
January 31, 2005, 3:27 AM

Search