Help assigning HEX value to 1 byte field in VB3.0 
Author Message
 Help assigning HEX value to 1 byte field in VB3.0

I'm using VB 3.0 and need to create an output file (using random
access) that will contain hex characters in a 1 byte field.  I've done
this before by assigning a hex value directly to an Integer type as
follows:

dim myint as integer
myint = &H0D  (integer value 13)

My problem is that Integer types take up 2 bytes in the output file
(even though the value is stored in only 1 of those  bytes) and I need
to have the value stored in a 1 byte field.  It appears that the only
1 byte field that's available in VB is a string of length 1 (string *
1), but I can't figure out how to directly assign a hex value to this
field (the above code won't work - it returns a 'type mismatch').  

I'm sure that there is some way to do this easily, but I just can't
figure it out.  Does anybody have any suggestions on how to accomplish
this?

Thanks - Matt



Mon, 31 Aug 1998 03:00:00 GMT  
 Help assigning HEX value to 1 byte field in VB3.0

: I'm using VB 3.0 and need to create an output file (using random
: access) that will contain hex characters in a 1 byte field.  I've done
: this before by assigning a hex value directly to an Integer type as
: follows:

: dim myint as integer
: myint = &H0D  (integer value 13)

: My problem is that Integer types take up 2 bytes in the output file
: (even though the value is stored in only 1 of those  bytes) and I need
: to have the value stored in a 1 byte field.  It appears that the only
: 1 byte field that's available in VB is a string of length 1 (string *
: 1), but I can't figure out how to directly assign a hex value to this
: field (the above code won't work - it returns a 'type mismatch').  

 Use the Chr$() function: Chr$(MyInt) returns a single byte of string
type containing the value you want.



Mon, 31 Aug 1998 03:00:00 GMT  
 Help assigning HEX value to 1 byte field in VB3.0

Quote:

>I'm using VB 3.0 and need to create an output file (using random
>access) that will contain hex characters in a 1 byte field.  I've done
>this before by assigning a hex value directly to an Integer type as
>follows:
>dim myint as integer
>myint = &H0D  (integer value 13)
>My problem is that Integer types take up 2 bytes in the output file
>(even though the value is stored in only 1 of those  bytes) and I need
>to have the value stored in a 1 byte field.  It appears that the only
>1 byte field that's available in VB is a string of length 1 (string *
>1), but I can't figure out how to directly assign a hex value to this
>field (the above code won't work - it returns a 'type mismatch').  
>I'm sure that there is some way to do this easily, but I just can't
>figure it out.  Does anybody have any suggestions on how to accomplish
>this?

Sure.

Dim sStr * 1

sStr = Chr$(13)  ' or if you're determined to use hex, Chr$(&hd)

Cheers,
        lauren :}



Tue, 01 Sep 1998 03:00:00 GMT  
 Help assigning HEX value to 1 byte field in VB3.0

Quote:

>I'm using VB 3.0 and need to create an output file (using random
>access) that will contain hex characters in a 1 byte field.  I've done
>this before by assigning a hex value directly to an Integer type as
>follows:

>dim myint as integer
>myint = &H0D  (integer value 13)

>My problem is that Integer types take up 2 bytes in the output file
>(even though the value is stored in only 1 of those  bytes) and I need
>to have the value stored in a 1 byte field.  It appears that the only
>1 byte field that's available in VB is a string of length 1 (string *
>1), but I can't figure out how to directly assign a hex value to this
>field (the above code won't work - it returns a 'type mismatch').  

Yep, sucks doesn't it. Microsoft assumes that people that use VB are
NEVER going to do any bit, byte, word or dword manipulation.

To output to the file:

Dim MyInt as Integer

        MyInt=&H0AA
        Print #1,Chr$(MyInt and &HFF)

Et, voila - a nice AA (hex) in the output file. When reading (you
guessed correctly):

        MyInt = Asc(Mid$(InputBufferString,Position,1))

Regards,
Rod



Tue, 01 Sep 1998 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. use hex values in calc field

2. Newbie - assigning calculated value to table field

3. Assigning Rank and Points based on a field value

4. Assigning new values to fields

5. Assign Value to Enterprise Project Field

6. Assign a string value to an enum field

7. Assign the null value to DB2 fields.

8. Assigning Null Values to data bound fields using remote data control

9. Assigning field values to variables

10. Counter Fields - value assigned on Addnew not Update?

11. Assigning field values to variable

12. Converting hex value in str format to hex

 

 
Powered by phpBB® Forum Software