Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Misc] Some useful functions...
#1
Hey guys Smile Here are just a few useful functions I've made lately Smile Enjoy Big Grin

[code]Public Function IsInRange(ByVal TestX As Integer, ByVal TestY As Integer, ByVal X As Byte, ByVal Y As Byte, ByVal Range As Byte) As Boolean

IsInRange = False

TestX = Sqr(((TestX - X) * (TestX - X)) + ((TestY - Y) * (TestY - Y)))
If TestX
Reply
#2
Quick question

Shouldn't the AddInt and AddLong be like this:
Code:
Public Sub AddIntegerToSetBuffer(ByRef Buffer() As Byte, vData As Integer, ByRef WriteHead As Integer)
  
  Call CopyMemory(Buffer(WriteHead), vData, 2)
  WriteHead = WriteHead + 2
End Sub
Code:
Public Sub AddLongToSetBuffer(ByRef Buffer() As Byte, vData As Long, ByRef WriteHead As Integer)
  
  Call CopyMemory(Buffer(WriteHead), vData, 4)
  WriteHead = WriteHead + 4
End Sub

Otherwise:
Code:
Public Sub AddIntegerToSetBuffer(ByRef Buffer() As Byte, vData As Integer, ByRef WriteHead As Integer)
  Dim tBytes() As Byte

  ReDim tBytes(UBound(Buffer))
  
  Call CopyMemory(tBytes(WriteHead), vData, 2)
  
  Buffer = tBytes

  WriteHead = WriteHead + 2
End Sub

You'd be overwriting anything you've written to the Buffer() before that call because it's setting Buffer = tBytes. tBytes is never given the data from Buffer.
Reply
#3
Dugor Wrote:Quick question

Shouldn't the AddInt and AddLong be like this:
Code:
Public Sub AddIntegerToSetBuffer(ByRef Buffer() As Byte, vData As Integer, ByRef WriteHead As Integer)
  
  Call CopyMemory(Buffer(WriteHead), vData, 2)
  WriteHead = WriteHead + 2
End Sub
Code:
Public Sub AddLongToSetBuffer(ByRef Buffer() As Byte, vData As Long, ByRef WriteHead As Integer)
  
  Call CopyMemory(Buffer(WriteHead), vData, 4)
  WriteHead = WriteHead + 4
End Sub

Otherwise:
Code:
Public Sub AddIntegerToSetBuffer(ByRef Buffer() As Byte, vData As Integer, ByRef WriteHead As Integer)
  Dim tBytes() As Byte

  ReDim tBytes(UBound(Buffer))
  
  Call CopyMemory(tBytes(WriteHead), vData, 2)
  
  Buffer = tBytes

  WriteHead = WriteHead + 2
End Sub

You'd be overwriting anything you've written to the Buffer() before that call because it's setting Buffer = tBytes. tBytes is never given the data from Buffer.

Ah true, fixed Smile Thanks Dugor Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)