• Welcome to Valhalla Legends Archive.
 

Prevent double sending?

Started by Gangz, December 30, 2003, 04:40 PM

Previous topic - Next topic

o.OV

#15
Quote from: Kp on December 30, 2003, 11:01 PM
Quote from: o.OV on December 30, 2003, 10:07 PM
now what other improvements can be done for the code i provided?

Well, I'd suggest storing your safelist and banlist in a true list of some sort rather than as a massive string with illegal characters to delimit entries.  As I recall, VB's support for such things tends to be rather poor though, so you may have some difficulty making it work.  I'll leave it to the VB gurus to explain how to implement the list (it'd be trivial in C, not so in VB afaik).

I don't expect a response from you since u said you will let the VB gurus explain how to implement the list.
But I took a look at the filter function and this is the best I can come up with.


Private Sub Form_Load()
   sArray = Array("<test1>", "<test>", "<3test>", "<4test4>")
   strng = "<test>"
   result = Filter(sArray, strng)
   Debug.Print result(0)
   'For x = LBound(result) To UBound(result)
   '    Debug.Print result(x)
   'Next x
End Sub


I wish to avoid any type of VB loop.
If the facts don't fit the theory, change the facts. - Albert Einstein

o.OV

#16
Quote from: Grok on December 31, 2003, 08:09 AM
Quote from: Kp on December 30, 2003, 11:01 PM
Quote from: o.OV on December 30, 2003, 10:07 PM
now what other improvements can be done for the code i provided?

Well, I'd suggest storing your safelist and banlist in a true list of some sort rather than as a massive string with illegal characters to delimit entries.  As I recall, VB's support for such things tends to be rather poor though, so you may have some difficulty making it work.  I'll leave it to the VB gurus to explain how to implement the list (it'd be trivial in C, not so in VB afaik).

Nah, quite easy to do in VB, really.  To wit:


Private Function OpenList(ByVal ListName As String) As ADODB.Recordset
   
   Dim rs As ADODB.Recordset
   Dim fso As Scripting.FileSystemObject
   Dim sFile As String
   
   Set fso = New Scripting.FileSystemObject
   sFile = fso.BuildPath(App.Path, ListName & ".xml")
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   If fso.FileExists(sFile) = True Then
       rs.Open sFile
   Else
       rs.Fields.Append "UserName", adVarChar, 30
       rs.Fields.Append "Namespace", adVarChar, 30
       rs.Fields.Append "Flags", adInteger
       rs.Fields.Append "DateAdded", adDate
       rs.Fields.Append "LastSeen", adDate
       rs.Fields.Append "Notes", adVarChar, 200
       rs.Open
       rs.Save sFile, adPersistXML
   End If
   Set OpenList = rs
   
End Function


Wow Grok.
If the facts don't fit the theory, change the facts. - Albert Einstein

Spht

Quote from: o.OV on December 31, 2003, 11:05 AM
Ok. So maybe that wasn't you or maybe it was.

You got me.If (flags and &H20) = &H20 ThenTo explain why, run this:    Dim i As Long
   Dim flags As Long
   flags = &H20
   Debug.Print "Checking &H" & Hex(flags) & " with flags 0 to 255 using If (flags And i) = i Then:"
   For i = 1 To &HFF
       If (flags And i) = i Then Debug.Print "(&H" & Hex(flags) & " And &H" & Hex(i) & ") = &H" & Hex(flags And i)
   Next i
   Debug.Print "Checking &H" & Hex(flags) & " with flags 0 to 255 using If (flags And i) Then:"
   For i = 1 To &HFF
       If (flags And i) Then Debug.Print "(&H" & Hex(flags) & " And &H" & Hex(i) & ") = &H" & Hex(flags And i)
   Next i

Spht

Quote from: o.OV on December 31, 2003, 12:25 PM

   sArray = Array("<test1>", "<test>", "<3test>", "<4test4>")
   strng = "<test>"


What's with the angle brackets?

o.OV

Quote from: Spht on December 31, 2003, 12:45 PM
Quote from: o.OV on December 31, 2003, 12:25 PM

   sArray = Array("<test1>", "<test>", "<3test>", "<4test4>")
   strng = "<test>"


What's with the angle brackets?

without it..


Private Sub Form_Load()
   sArray = Array("test1", "test", "3test", "4test4")
   strng = "test"
   result = Filter(sArray, strng)
   'Debug.Print result(0)
   For x = LBound(result) To UBound(result)
       Debug.Print result(x)
   Next x
End Sub


it would return all 4 items in the array
If the facts don't fit the theory, change the facts. - Albert Einstein

o.OV

#20
Quote from: Spht on December 31, 2003, 12:43 PM
Quote from: o.OV on December 31, 2003, 11:05 AM
Ok. So maybe that wasn't you or maybe it was.

You got me.If (flags and &H20) = &H20 ThenTo explain why, run this:    Dim i As Long
   Dim flags As Long
   flags = &H20
   Debug.Print "Checking &H" & Hex(flags) & " with flags 0 to 255 using If (flags And i) = i Then:"
   For i = 1 To &HFF
       If (flags And i) = i Then Debug.Print "(&H" & Hex(flags) & " And &H" & Hex(i) & ") = &H" & Hex(flags And i)
   Next i
   Debug.Print "Checking &H" & Hex(flags) & " with flags 0 to 255 using If (flags And i) Then:"
   For i = 1 To &HFF
       If (flags And i) Then Debug.Print "(&H" & Hex(flags) & " And &H" & Hex(i) & ") = &H" & Hex(flags And i)
   Next i


Cool. I'll try that out right now Spht. =)
_____

I just tried it out and the results were quite long ^^
but it definitely showed the unwanted results =)
thx spht
If the facts don't fit the theory, change the facts. - Albert Einstein

o.OV

#21
Quote from: o.OV on December 31, 2003, 12:50 PM
Quote from: Spht on December 31, 2003, 12:43 PM
Quote from: o.OV on December 31, 2003, 11:05 AM
Ok. So maybe that wasn't you or maybe it was.

You got me.If (flags and &H20) = &H20 ThenTo explain why, run this:    Dim i As Long
   Dim flags As Long
   flags = &H20
   Debug.Print "Checking &H" & Hex(flags) & " with flags 0 to 255 using If (flags And i) = i Then:"
   For i = 1 To &HFF
       If (flags And i) = i Then Debug.Print "(&H" & Hex(flags) & " And &H" & Hex(i) & ") = &H" & Hex(flags And i)
   Next i
   Debug.Print "Checking &H" & Hex(flags) & " with flags 0 to 255 using If (flags And i) Then:"
   For i = 1 To &HFF
       If (flags And i) Then Debug.Print "(&H" & Hex(flags) & " And &H" & Hex(i) & ") = &H" & Hex(flags And i)
   Next i


Cool. I'll try that out right now Spht. =)
_____

I just tried it out and the results were quite long ^^
but it definitely showed the unwanted results =)
thx spht

I took another look at it..


flags = &H20
If (flags And &H30) = &H30 or (flags And &H20) = &H20 Then


or


flags = 32
If flags = 48 or flags = 32 Then


or


flags = &H20
If flags = &H30 or flags = &H20 Then


is code execution faster with the first one?
does it make any difference or should i use the first example so the code would look proper

am i going at this the wrong way?

if i use


flags = &H20
If (flags And &H20) Then


i may get TWO unwanted results:

&H22
&H32
and there are other flags i dont rememeber
such as bnet rep and flags for special icons

and yes. i see why using &H would be a better idea
flags make more sense
If the facts don't fit the theory, change the facts. - Albert Einstein

o.OV

#22
Quote from: o.OV on December 31, 2003, 12:25 PM
Quote from: Kp on December 30, 2003, 11:01 PM
Quote from: o.OV on December 30, 2003, 10:07 PM
now what other improvements can be done for the code i provided?

Well, I'd suggest storing your safelist and banlist in a true list of some sort rather than as a massive string with illegal characters to delimit entries.  As I recall, VB's support for such things tends to be rather poor though, so you may have some difficulty making it work.  I'll leave it to the VB gurus to explain how to implement the list (it'd be trivial in C, not so in VB afaik).

I don't expect a response from you since u said you will let the VB gurus explain how to implement the list.
But I took a look at the filter function and this is the best I can come up with.


Private Sub Form_Load()
   sArray = Array("<test1>", "<test>", "<3test>", "<4test4>")
   strng = "<test>"
   result = Filter(sArray, strng)
   Debug.Print result(0)
   'For x = LBound(result) To UBound(result)
   '    Debug.Print result(x)
   'Next x
End Sub


I wish to avoid any type of VB loop.

To remove a String Item .. I use Replace
-current

To remove a GUI Listbox Item .. I use RemoveItem
-I hate using Form based items

Now how do I remove an array item without using a loop?
If the facts don't fit the theory, change the facts. - Albert Einstein

MrRaza


Grok

#24
Quote from: o.OV on December 31, 2003, 02:42 PMNow how do I remove an array item without using a loop?

It is possible, but requires you to first learn how arrays are stored in memory.  Then you can write a utility function to remove a specific item by copying the [n+1] elements memory down to [n]'s address, then adjusting the array's header so it knows the new number of elements.

TheMinistered may have already researched this, you should ask him.

P.S. This appears to be more about Visual Basic than BnetBot Development.  Do you have any BnetBot Development questions?

o.OV

#25
Quote from: Grok on January 02, 2004, 10:43 AM
Quote from: o.OV on December 31, 2003, 02:42 PMNow how do I remove an array item without using a loop?

It is possible, but requires you to first learn how arrays are stored in memory.  Then you can write a utility function to remove a specific item by copying the [n+1] elements memory down to [n]'s address, then adjusting the array's header so it knows the new number of elements.

TheMinistered may have already researched this, you should ask him.

P.S. This appears to be more about Visual Basic than BnetBot Development.  Do you have any BnetBot Development questions?

Here is a link I found on the subject:

http://www.developerfusion.com/show/3367/2/

I'm tinkering with it now..

If you can redirect me to a better resource page, please do. =) thx
________

The example they give still uses a loop..
If the facts don't fit the theory, change the facts. - Albert Einstein