02-06-2018 04:04 AM
Hello:
I have the following code:
dim Var Var=CDbl(Data.Root.ChannelGroups(1).Properties("Velocity_test_object_1").Value)
But the velocity test, is filled by another program before creating the TDM. (and somehow it does not recognize decimal points.)
I want only the first 4 digits as var.
For example:
Velocity=32345 Var=3234
Velocity=23 Var=2300
Velocity=1501 Var=1501
Velocity=555555 Var=5555
Either that or a way to read decimal points! 😛
Can someone help
Solved! Go to Solution.
02-06-2018 04:44 AM
CDbl is local dependent.
I assume your values have an other decimal value which is interpreted as thousand seperator.
You can use Val instead which always uses dot as decimal point.
MsgBox Val("1.2") & VBCRLF & Val("1,2") & VBCRLF & CDbl("1.2")& VBCRLF & CDbl("1,2")
So potentially
dim Var Var=Val(Data.Root.ChannelGroups(1).Properties("Velocity_test_object_1").Value)
might do the job.
02-06-2018 04:59 PM - edited 02-06-2018 05:02 PM
' Variables Dim velocity: velocity = Array(32345, 23, 1501, 555555) Dim desiredDigits: desiredDigits = 4 ' Conversion loop Dim i, number, length For i = 0 To UBound(velocity, 1) Step 1 ' For each velocity case length = Len(CStr(velocity(i))) ' get the number of digits If length >= desiredDigits Then ' If number of digits is bigger or equal desired number = Left(CStr(velocity(i)), desiredDigits) ' Simply take the leftmost digits Else number = Left(CStr(velocity(i)), length) ' Otherwise take all the leftmost digits (kinda redundant) While Len(number) < desiredDigits ' And keep adding trailing zeroes until reached desired number of digits number = number & "0" Wend End If Call LogFileWrite(number) ' Here number is a "String" type so simple convert CDbl(number) if you need Next
You can change the values in the "velocity" array to add cases or change the number of desired output digits in the variables at the top.
Output:
3224
2300
1501
5555
02-22-2018 04:16 AM
Second method did the trick