login about faq

Hi

You need to send 10 bytes of Hex (x00 x01 x02 x03 x04 x05 x06 x07 x08 x09) You can do this with ActiveX socket.SendBytes

Success = socket.SendBytes (&H0001020304)

Success = socket.SendBytes (&H000102030405) - error

If more than 4 bytes then an error

asked Apr 29 at 12:20

anges's gravatar image

anges
32

edited Apr 29 at 12:30


I'm guessing the error you are getting is an Overflow error?

Assuming this is VB6, you can't stuff more than 4 bytes into a hex value indicated by the &H prefix since it converts to a 32-bit long integer at the most.

You should use a byte array of the required size and populate with the values you need, then pass the array to SendBytes.

link

answered Apr 29 at 13:31

jpbro's gravatar image

jpbro ♦
1.1k2618

Thank you

And how to transfer an array in SendBytes?

link

answered Apr 29 at 13:51

anges's gravatar image

anges
32

Assuming VB6, you can do something like this:

Dim la_Bytes() As Byte
Dim l_NumberOfBytes As Long

l_NumberOfBytes = 6
Redim la_Bytes(l_NumberOfBytes - 1)

la_Bytes(0) = &H00
la_Bytes(1) = &H01
la_Bytes(2) = &H02
la_Bytes(3) = &H03
la_Bytes(4) = &H04
la_Bytes(5) = &H05

success = socket.SendBytes(la_Bytes)
link

answered Apr 29 at 13:58

jpbro's gravatar image

jpbro ♦
1.1k2618

I am writing for VBScript (Visual Basic Scripting).

I tried your way, it works, but it's transmitted 20 bytes and not 10 bytes A similar problem was discussed at http://www.chilkatforum.com/questions/7683/how-to-ensure-sendbytes-only-sends-one-byte-per-character

It was suggested to use SendString StringCharset = "windows-1252", but I get an error.


set socket = CreateObject("Chilkat_9_5_0.Socket")

success = socket.UnlockComponent("xxxxx") MsgBox socket.LastErrorText

socket.KeepSessionLog = 1 socket.SessionLogEncoding = "hex"

ssl = 0 maxWaitMillisec = 20000 port = 80 success = socket.Connect("127.0.0.1",port,ssl,maxWaitMillisec)

MsgBox "Connect: " & success

dim new_arr(10)

new_arr(0) = &H00

new_arr(1) = &H01

new_arr(2) = &H02

new_arr(3) = &H03

new_arr(4) = &H04

new_arr(5) = &H05

new_arr(6) = &H06

new_arr(7) = &H07

new_arr(8) = &H08

new_arr(9) = &H09

success = socket.SendBytes(new_arr)

MsgBox socket.SessionLog

link

answered Apr 29 at 19:16

anges's gravatar image

anges
32

edited Apr 29 at 19:19

When you don't choose the variable type for your array, it uses the Variant type - I suspect this is being coerced to a Unicode string when you call SendBytes. As Chilkat posted below, make sure you choose the Byte datatype for your array.

Also, arrays have 0-based indexes, so if you want X elements you should dimension your array using X-1.

For example:

Dim new_arr(9) As Byte

(Apr 30 at 09:07) jpbro ♦

Try this:

Dim b(1 To 10) As Byte

b(1) = 0 b(2) = 1 b(3) = 2 b(4) = 3 b(5) = 4 b(6) = 5 b(7) = 6 b(8) = 7 b(9) = 8 b(10) = 9 success = socket.SendBytes(b)

link

answered Apr 29 at 20:51

chilkat's gravatar image

chilkat ♦♦
12.8k317366477

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×81

Asked: Apr 29 at 12:20

Seen: 320 times

Last updated: Apr 30 at 09:07

powered by OSQA