buddylist mess

im having a problem as you have probably already guessed.
can anyone tell me whats wrong with this…if not thats ok too.

case “BuddyOff”
dim x as integer
for x=0 to buddies.Ubound
if buddies(x)=NthField(data,EndOfLine,2) then
buddies.remove x
end if
next
for x=0 to IDz.Ubound
if idz(x)=val(NthField(data,EndOfLine,3)) then
idz.Remove x
end if
next
for x=0 to servers.Ubound
if servers(x)=me then
servers(x).Disconnect
servers.Remove x
end if
next
dim i as integer
dim outstring as string
dim pack1,pack2,pack3 as string
outstring=“Buddies”+endofline
for i=0 to buddies.Ubound
pack1=buddies(i)
outstring=outstring+pack1+endofline
next
for i=0 to servers.Ubound-1
servers(i).Write outstring
next

tried downto also

Some suggestions:

  1. When posting code, please use the `` tags which makes it easier to read
  2. When removing something from an array, ALWAYS iterate from upper limit to lower limit. Otherwise, you may get unspecified results

Dim u As Integer =buddies.ubound for x = u Downto 0
will give you better speed
4) Beyond those suggestions, I don’t know what you are expecting and what you are getting instead. Please be specific

my problem is that i have a window that when closed it sends “BuddyOff” across a tcpsocket. i get the buddylist to load but when the window closes it doesnt wanna remove the username from an array and then send a updated list.

In what event have you placed this code?

tcpsocket.dataavailable

the socket is listening too

want me to email you the whole project?

If you put your code inside [code] tags it maintains formatting on the forum and makes it easier to read in the future!

what r code tags?

nvm i got it

case "BuddyOff" dim x as integer for x=buddies.Ubound downto 0 if buddies(x)=NthField(data,EndOfLine,2) then buddies.remove x end if next for x=IDz.Ubound downto 0 if idz(x)=val(NthField(data,EndOfLine,3)) then idz.Remove x end if next for x=servers.Ubound downto 0 if servers(x)=me then servers(x).Disconnect servers.Remove x end if next dim i as integer dim outstring as string dim pack1,pack2,pack3 as string outstring="Buddies"+endofline for i=0 to buddies.Ubound pack1=buddies(i) outstring=outstring+pack1+endofline next for i=servers.Ubound downto 0 servers(i).Write outstring next

for some reason when a user closes the window on the client side of the app i dont think its sending it out fast enough to go through. i have “BuddyOff” in a window close eventhandler. i dont think it ever being sent out because the window is being closed to fast. dunno what do u guys think?

ok i tried it in a pushbutton and still no luck

ChatWindow.ClientSocket1.write "BuddyOff"+endofline+ChatWindow.ClientSocket1.username+EndOfLine+str(ChatWindow.ClientSocket1.handle)+endofline ChatWindow.ClientSocket1.Disconnect ChatWindow.close LoginWindow.show

any ideas?

this worked thought i would share:

[code] me.Disconnect
dim x as integer
for x=0 to buddies.Ubound
if buddies(x)=NthField(data,endofline,2) then
buddies.Remove x
end if
next
dim i,i2 as integer
dim outstring as string
dim pack1,pack2,pack3 as string
outstring=“Buddies”+endofline

for i2=0 to buddies.Ubound
  pack1=buddies(i2)
  outstring=outstring+pack1+chr(5000)+str(me.tag)+chr(5000)+endofline
next
for i=0 to servers.Ubound-1
  servers(i).Write outstring
next

case “Chat”
dim i as integer
for i=0 to servers.Ubound-1
servers(i).Write data
next[/code]