Valhalla Legends Forums Archive | Visual Basic Programming | MakeWORD Problem

AuthorMessageTime
Zer0
ok i dont see anything wroung with this but mabey im just stupid or somthn? i am using VB.Net

[code]
Public Function MakeWORD(ByRef Value As Short) As String
Dim Result As New VB6.FixedLengthString(2)
CopyMemory(Result.Value, Value, 2)
MakeWORD = Result.Value
End Function
[/code]

it is telling me there is a error in
[code]
CopyMemory(Result.Value, Value, 2)
[/code]
September 27, 2006, 3:01 AM
FrostWraith
Don't scream at me if this doesnt work but in VB you only user parentheses when calling or setting to a variable. Try this:
[code]CopyMemory Result.Value, Value, 2[/code]
September 27, 2006, 3:05 AM
Topaz
[quote author=Zer0 link=topic=15794.msg159066#msg159066 date=1159326068]
ok i dont see anything wroung with this but mabey im just stupid or somthn? i am using VB.Net

[code]
Public Function MakeWORD(ByRef Value As Short) As String
Dim Result As New VB6.FixedLengthString(2)
CopyMemory(Result.Value, Value, 2)
MakeWORD = Result.Value
End Function
[/code]

it is telling me there is a error in
[code]
CopyMemory(Result.Value, Value, 2)
[/code]
[/quote]

1. What's the error
2. The value you're trying to convert is probably not the right size
September 27, 2006, 3:13 AM
l2k-Shadow
try placing ByVal in front of Result.Value so
[code]
CopyMemory(ByVal Result.Value, Value, 2)
[/code]
September 27, 2006, 3:40 AM
Myndfyr
The problem is that you're using CopyMemory in VB.NET where there are 30 better ways for you to do it.
September 27, 2006, 3:52 AM
Zer0
shadow when i tryed using ByVal i got...
Expression expected.

and MyndFyre u mind telling me a better one?
September 27, 2006, 3:55 AM
Myndfyr
In .NET, you should be treating your binary data as byte arrays, not as strings.  That's because they're handled efficiently in .NET, and the Framework Class Library has classes that support using byte arrays for data.  Not only that, but converting from a string back to a byte array to be sent via a Socket, NetworkStream, TcpClient, or any of the other classes will cause data loss and truncation.

To convert from a Short to a Byte(), use BitConverter.GetBytes(ByVal s As Short).  To convert two bytes at a specific byte array index, use BitConverter.ToInt16(ByVal arr() As Byte, ByVal index As Integer).  Alternatively, you may want to investigate the System.IO.MemoryStream class, which treats memory sort of like a pointer.

MBNCSUtil has packet buffers and data readers written in C# that demonstrate how to use this functionality in the class library.  I highly suggest that you check it out.
September 27, 2006, 5:55 AM
Zer0
wow lol from looking at what u just showd me im going to have to re-write almost the entire bot. Is there a source out there for a example of a working .Net bot so i can get a little clearer idea because i am still rather new to .Net. Thx for the help MyndFyre n everyone else who tried :)
September 27, 2006, 6:19 AM
FrOzeN
[quote author=Zer0 link=topic=15794.msg159082#msg159082 date=1159337962]
Is there a source out there for a example of a working .Net bot so i can get a little clearer idea because i am still rather new to .Net. Thx for the help MyndFyre n everyone else who tried :)
[/quote]
Yeah, most likely. Though IMO, I think you'll find that trying to develop a bot yourself, you'll grasp a much better understand of how it works. You'll also gain more skills investigating and learning how to handle packets, debug better, etc. Having a source code as a reference takes away these things, and won't give you as much understanding of your code.
September 27, 2006, 8:10 AM

Search