Oww, you got a few mistakes in there.
First, the message you got did tell you the truth: There's an "end if"
missing. Second, your line breaks look weird.
The RB "if-then-else" syntax allows two forms:
1) if a>b then beep else msgBox("Hey!")
2)
if a>b then
beep
else
msgBox("Hey!")
end if
Either put it all in one line, or use "end if". In this case, the "end if"
belongs just before the "next" statement.
Your third problem: This way, you're adding the address up to ten times to
the list, because the "addrow" is inside your loop.
Fourth, you'll get more OutOfBounds exceptions here, because your for-next
loop goes from 1 to 10, and not from 0 to ListBox.ListCount-1.
I suggest this code:
(make a window property "dictSenders as Dictionary")
dim dg as Datagram
dim n as integer
if dictSenders = nil then dictSenders = new dictionary
do until me.PacketsAvailable < 1
dg = me.Read
dictSenders.Value(dg.Address) = "abc"
loop
Liste_Masters_Detectes.DeleteAllRows
for n=0 to Min(9, dictSenders.Count-1) // this will show max. 10 hosts
Liste_Masters_Detectes.AddRow dictSenders.Key(n)
next
The trick is using the keys of a Dictionary object; because the keys are
unique, no host will be added twice.
You might even need some more code to prevent the listbox from changing too
quickly, depending on the speed at which the packets are coming in.
Cheers,
Frank+++
On 08.01.2004 20:52 Uhr, Vincèn Pujol wrote:
> You are really wonderful Franck :-) So I modified your code so it
> doesn't add again in my list an adress I would have already received
> but there is still something wrong about then expected after if and
> about the Then Exit !
>
> dim dg as Datagram
> dim X as Integer
> do until me.PacketsAvailable < 1
> dg = me.Read
> For x = 1 to 10
> if dg.Address = Liste_Masters_Detectes.Cell(X,0)
> Then exit
> else
> Liste_Masters_Detectes.AddRow dg.Address
> next x
>
> if Liste_Masters_Detectes.ListCount > 10 then
> Liste_Masters_Detectes.RemoveRow 0
> end if
> loop
>
> Thanks
>
--
"Never trust a computer you can't throw out a window."
- Steve Wozniak
Günter Schmidt & Co. oHG
Frank Bitterlich eMail: bitterlich at gsco dot de
Schlosserstr. 4 WWW: http://www.gsco.de/gsco
D-60322 Frankfurt Tel.: 069 / 156809-29
GERMANY Fax: 069 / 156809-28
- - -
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
|