Posted: Sat Jun 18, 2016 12:58 pm Post subject: Write a float value as integer
Hey!
Can you write the (float) value of an address to a Label as an integer?
My Code is like that:
Code:
local memrec=addresslist_getMemoryRecordByDescription(getAddressList(), "Time")
local value=memoryrecord_getValue(memrec)
control_setCaption(UDF1_CELabel2, value)
UDF1.CELabel2.Caption = getAddressList().getMemoryRecordByDescription("Time").Value:match("^%d+") or "0"
Thank you for your answer.
Code:
.Value:match("^%d+")
So this converts a float into an integer?
And could you also do something like this?:
Code:
UDF1.CELabel2.Caption = getAddressList().getMemoryRecordByDescription("Time").Value:match("^%d+") or getAddressList().getMemoryRecordByDescription("TimeNrTwo").Value:match("^%d+")
No. The string.match function is used for taking one string (the value field) and finding a particular part of it that matches a specified pattern ("^%d+"). The or operator makes it such that if string.match didn't find anything that matches the pattern, it will just return 0. If that's the behavior you want, then go with what you wrote. If not, explain what you want.
Also, I forgot to include negative numbers with that pattern.
Code:
UDF1.CELabel2.Caption = getAddressList().getMemoryRecordByDescription("Time").Value:match("^-?%d+") or "0"
If you want to include NaN or +-Inf, make separate checks for that. _________________
I don't know where I'm going, but I'll figure it out when I get there.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum