Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In my code label26 is "CHOL" and i'm converting it to hex as "43484f4c" using below code and storing it in my database MS ACCESS using VB6 but now i want to save it as 2-digit hex code i want to allocate it only 2 bytes how is it possible

Thank You

What I have tried:

str = Label26.Caption
bytes = StrConv(str, vbFromUnicode)
str = ""
For i = LBound(bytes) To UBound(bytes)
str = str & Format$(Hex$(bytes(i)), "00") Next i
Label26.Caption = str
str = StrConv(bytes, vbUnicode)
rs.Fields("NameofTest").Value = Label26.Caption
Posted
Updated 12-Feb-18 21:48pm

1 solution

It isn't. The problem is that - at the very least - that is four alphabetic characters: 'A' to 'Z' in each place. That means that there are 26 possible values for each of the four characters that make up your code (or 36 if you also permit digits).
Two bytes can only hold four * 16 values - 0 to 65535 - and four * 26 requires 0 to 456875 which will not physically fit in two bytes.
 
Share this answer
 
Comments
ramadevi82 13-Feb-18 4:46am    
or can i store in packet format?
if yes,can u help me in coding
OriginalGriff 13-Feb-18 4:53am    
How would I know? I have no information about what you are doing other than exactly what you have typed, and so far that's just asking for something that isn't physically possible!
I have no idea why you are trying to do this, what your code is used for, anything.
ramadevi82 13-Feb-18 5:18am    
my code is used for biomedical machine.we perform some tests in it.to run a test we need some parameter values.previously we used to store the values manually using keypad but now i'm trying to store the values in pc and send them through rs232 to the machine.
for example,we have temperature as 37 degC,Test name as "CHOL"(cholesterol),aspiration volume etc...to those fields i have to save values
OriginalGriff 13-Feb-18 5:26am    
So the first thing you need to do is look at the communications with the machine, and what it accepts, and how it accepts them - because until you know exactly what you can send (and how you can send it) there is no point at all in starting to code, or even starting to design code - you can't change what the machine does, so you need to work round that. And that means fully understand the communications to it, and testing what you want to do using something like Hyperterminal to prove the concept before you start coding.
ramadevi82 13-Feb-18 5:45am    
i have to send the code in hex format and already the code has been developed earlier in C code now according to that i have to set parameters

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900