ricmarti Posted May 21, 2010 Share Posted May 21, 2010 I am reading a date register that is in decimal format that needs to be converted to hexadecimal , then the four digit number needs to be sperated into MSB, LSB. Then converted back to decimal. If done manually it would go like this, register value '1301' : converted to hex value 515: split to 5 & 15: converted to 5 & 21. So 1301 represents May 21. How can I perform this calculation in the DAQ expression box? Thanks for your assistance. Link to comment Share on other sites More sharing options...
AzeoTech Posted May 21, 2010 Share Posted May 21, 2010 decimal to hex: private string hexval = format("%04x",decimalValue) then use string functions to pull out the desired values: private month = strtodouble(left(hexval,2)) private year = strtodouble(right(hexval,2)) note the 04 in format() means prepend 0's to make the result at least 4 characters long. This makes it easier to split into month and year. Link to comment Share on other sites More sharing options...
ricmarti Posted May 28, 2010 Author Share Posted May 28, 2010 Thanks. This partly works. In the variable value componenet expression(expanded) of page_2, if I enter format("%04x", decimal value) I get correct hex value. But if I enter private string hexval = format("%04x", decimal value) I get 'C1000 Channel or function not found' error. It appears the private string hexval statement is the problem. I am just learning the software, thanks for your help. I also tried combining the formula Right(format("%04x", decimal value),2) which did produce the correct value of the right two hex values. Then I tried converting this back to decimal value by entering format("%d",(Right(format("%04x",decimal value),2))) . There was no result, just a blue screen. I think I maybe trying to many operations in one entry? Link to comment Share on other sites More sharing options...
AzeoTech Posted May 28, 2010 Share Posted May 28, 2010 You probably just have a typo. Try just splitting it into two lines: private string hexval hexval = format(...) Also, you don't want to use format() to make it into a number. Format() always returns a string. Use strToDouble() instead. Link to comment Share on other sites More sharing options...
ricmarti Posted July 27, 2010 Author Share Posted July 27, 2010 Still unable to obtain correct result. If I enter following formula: Right(Format("%04x",H[0]),2) I get correct hex result of 1b If I enter: hexval = Right(Format("%04x",H[0]),2) I get incorrect result of C1000 channel or function not found I can live with the hex value being displayed, but it would be nice to display in decimal format. Link to comment Share on other sites More sharing options...
AzeoTech Posted July 27, 2010 Share Posted July 27, 2010 Where are you entering this? Did you declare hexval as a variable? It has to be a string variable. If you are trying to do this in a component's expression, you have to combine everything I did into one long expression: strtodouble(left(Right(Format("%04x",H[0]),2),2)) + "/" + strtodouble(right(Right(Format("%04x",H[0]),2),2)) Link to comment Share on other sites More sharing options...
ricmarti Posted July 27, 2010 Author Share Posted July 27, 2010 How do I declare hexval as a string variable? Link to comment Share on other sites More sharing options...
AzeoTech Posted July 27, 2010 Share Posted July 27, 2010 The way I did in the second post: private string hexval But this is only if you are doing this in a sequence, not in a component's expression. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.