PDA

View Full Version : VB .NET typecasting problem


NotAnIllusion
28th October 2006, 20:59
Hi, I want to try and write some InSim stuff in VB .NET, since VS2k5 Express is free and all that, but I have a problem.

In my InSimInit class I have


Public port As Integer
and when send it it still shows as e.g. 29999, 5-bytes in length. I've tried Convert.ToUInt16 and some other stuff but I can't get it to become 2-bytes in length :(

How do I convert the port to the InSim word? Also, I don't think Convert.ToByte is working with flags and nodesecs :scratchch

Thanks for your help :D

Stuff
28th October 2006, 23:07
Hmm.. what I do in VB6 is when filling out the packet to be sent I make the port 2 bytes instead an integer. Since VB bytes are the only unsigned data types it tends to work better. Something like..

Packet.Port(0) = intPort Mod 256
Packet.Port(1) = intPort \ 256

Might work for ya. :)

NotAnIllusion
29th October 2006, 00:25
Yeah seems to be working finally. Thanks! :D