> -----Original Message----- > From: Edson Brusque [SMTP:brusque.listas@CITRONICS.COM.BR] > Sent: Monday, April 29, 2002 6:37 PM > To: PICLIST@MITVMA.MIT.EDU > Subject: [OT]: VisualBasic: How to retrieve an array on a variant? > > Hello, > > sorry for ressending. I've forgot to say it's about MS Visual Basic. > > The MSComm control have the option to put the received bytes as text > on > a string variable (comInputModeText)or as binary data on a variant > variable > (comInputModeBinary). > > When using comInputModeBinary how can I retrieve the array of data > (integers) received? > > Thanks, > > Brusque > If you mean 16 bit integers than you cannot do this directly. The CommControl will return a variant containing a byte array. You will have to arrange putting them into the high and low bytes of an integer. Remember that VB has only signed types (apart from byte) so unless you specificaly want to use signed integers then using longs makes things a little easier. ' Assumes MSComm has been correctly setup to receive binary data! Dim SerialData as Variant Dim IntegerValue as Long Do While MSComm1.InBufferCount < 2 ' wait for 2 bytes to arrive DoEvents Loop SerialData = MSComm1.Input ' use input method to retreive the variant byte array IntegerValue = SerialData(0) + (Clng(SerialData(1)) * 256) ' convert to 16 bit unsigned value held in a Long Regards Mike -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu