• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 73
  • Last Modified:

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(tempArray(1))
                            DSIValues.Add(tempArray(0))
                         End if
'This will place the value received in the DSIValue Array into the Reading box.
 CType(newGraphics.readingLabelArrayList(intloop), Label).Text = Format(muxClass.DSIValues(0) + gage.Offset, howToDiplayDecimalPlaces)
0
cmdolcet
Asked:
cmdolcet
  • 8
  • 7
1 Solution
 
Fernando SotoRetiredCommented:
Hi cmdolcet;

If you were to place a break point on this line in your code,
CType(newGraphics.readingLabelArrayList(intloop), Label).Text = Format(muxClass.DSIValues(0) + gage.Offset, howToDiplayDecimalPlaces)

Open in new window

What are the values of these variables at that time, muxClass.DSIValues(0), gage.Offset, and howToDiplayDecimalPlaces?
0
 
cmdolcetAuthor Commented:
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?
0
 
Fernando SotoRetiredCommented:
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.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
cmdolcetAuthor Commented:
Im curious about how things can get shifted around.
0
 
Fernando SotoRetiredCommented:
That makes to of us.
0
 
cmdolcetAuthor Commented:
The code I posted there should be no shifting correct. We did run a COM port sniffer and the values where coming over correctly.
0
 
Fernando SotoRetiredCommented:
And therefore must be changing in code and the reason to inspect the lines of code that could cause that.
0
 
cmdolcetAuthor Commented:
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?
0
 
Fernando SotoRetiredCommented:
Hi cmdolcet;

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)

Open in new window

0
 
cmdolcetAuthor Commented:
OK tried that code above and still got the same decimal shift result as before.
0
 
Fernando SotoRetiredCommented:
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?
0
 
cmdolcetAuthor Commented:
OK here's what I am thinking... What if I put a conditional Statement that if the inches go over 2.00" It would flag it and dump the reading.
0
 
Fernando SotoRetiredCommented:
If that will show the problem then that will do.
0
 
cmdolcetAuthor Commented:
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.readingLabelArrayList(intloop), Label).Text = Format(muxClass.DSIValues(0) + gage.Offset, howToDiplayDecimalPlaces) "#####0.0000"

Is there any other way to display this? or another function
0
 
cmdolcetAuthor Commented:
This solution worked!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now