cmdolcet
asked on
Shifting and Trunkating decimal places
I am having a problem when after I read my COM port I get a decimal shift of values from a result of .1515 to 1515.0. Not sure why it will display 1515.0 I see the correct value in the following code.
'Reads the Value inside the COM Port.
strData = serialPort.ReadExisting
'Parse out any unwanted cahracters
strData = strData.Replace(vbCrLf, vbTab).Replace(Chr(26), "").Replace(Chr(12), "").Replace(Chr(13), "")
'Parses out the information gathered from the COM port to a temp location
tempArray = Split(strData, ",")
'Parses out Wireless ID that is sent over when a Data Send is picked up on the COM port.
'This will Add the Wireless ID to all LMI 200, LMI 241, LMI TP
If tempArray.Length = 2 Then
WirelessGageID.Add(tempArr ay(1))
DSIValues.Add(tempArray(0) )
End if
'This will place the value received in the DSIValue Array into the Reading box.
CType(newGraphics.readingL abelArrayL ist(intloo p), Label).Text = Format(muxClass.DSIValues( 0) + gage.Offset, howToDiplayDecimalPlaces)
'Reads the Value inside the COM Port.
strData = serialPort.ReadExisting
'Parse out any unwanted cahracters
strData = strData.Replace(vbCrLf, vbTab).Replace(Chr(26), "").Replace(Chr(12), "").Replace(Chr(13), "")
'Parses out the information gathered from the COM port to a temp location
tempArray = Split(strData, ",")
'Parses out Wireless ID that is sent over when a Data Send is picked up on the COM port.
'This will Add the Wireless ID to all LMI 200, LMI 241, LMI TP
If tempArray.Length = 2 Then
WirelessGageID.Add(tempArr
DSIValues.Add(tempArray(0)
End if
'This will place the value received in the DSIValue Array into the Reading box.
CType(newGraphics.readingL
ASKER
It happens so infrequently that when I do place a breakpoint to step through the code it never happens. With the current code above can you see anything I may be doing wrong?
Then I would say to open a file with append, write the values to a file then flush and close the file. do this just before that line of code. Then when it crashes the last line in the file are the values just before the crash.
ASKER
Im curious about how things can get shifted around.
That makes to of us.
ASKER
The code I posted there should be no shifting correct. We did run a COM port sniffer and the values where coming over correctly.
And therefore must be changing in code and the reason to inspect the lines of code that could cause that.
ASKER
OK I think the variable howtoDisplayDecimalPlaces is causing the issue right now it is setup like this "#####,0.0000"
Could this setup be causing the shift?
Could this setup be causing the shift?
Hi cmdolcet;
Try modifying the following two lines of code in your program.
Try modifying the following two lines of code in your program.
// Where you set up the format specifier for a numeric value
string howToDiplayDecimalPlaces = "###,##0.0000";
// Where you modify the text value of the Label control
CType(newGraphics.readingLabelArrayList(intloop), Label).Text = Format(CType(muxClass.DSIValues(0) + gage.Offset, Double), howToDiplayDecimalPlaces)
ASKER
OK tried that code above and still got the same decimal shift result as before.
Well I can not think of anything other then a coding issue as long as the input coming from the comm port is correct. Is it possible to create a small project hard coding the data from the comm port and then using your current code to that will show the issue and upload that project to the web somewhere where I can download it, a web site like OneDrive?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If that will show the problem then that will do.
ASKER
OK I tried narrow it down by comparing the original value in the COM port to what I should be expecting. What I think is happening is when I use variable "HowtoDisplayDecimalPlaces ". The numbers get shifted.
CType(newGraphics.readingL abelArrayL ist(intloo p), Label).Text = Format(muxClass.DSIValues( 0) + gage.Offset, howToDiplayDecimalPlaces) "#####0.0000"
Is there any other way to display this? or another function
CType(newGraphics.readingL
Is there any other way to display this? or another function
ASKER
This solution worked!
If you were to place a break point on this line in your code,
Open in new window
What are the values of these variables at that time, muxClass.DSIValues(0), gage.Offset, and howToDiplayDecimalPlaces?