1 Replies - 284 Views - Last Post: 20 November 2012 - 04:40 AM Rate Topic: -----

#1 gauree  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 28-October 12

getting error when trying to run the code....how to remove it?

Posted 20 November 2012 - 03:03 AM

[code]
Private Function checkDepth() As Boolean
Dim _ZDepth As Decimal = Convert.ToDecimal(txtZDepth.Text)
Dim _XVal As Decimal = Convert.ToDecimal(txtXaxis.Text)
Dim _YVal As Decimal = Convert.ToDecimal(txtYaxis.Text)
Dim _ZVal As Decimal = Convert.ToDecimal(txtZaxis.Text)

'check if spark mode is -ve
If cmbAxis.Text.Contains("-") Then
_XVal = _XVal * -1
_YVal = _YVal * -1
_ZVal = _ZVal * -1
End If

Dim SMode As String = getSparkMode()
'ZYX
Dim CAxisValue As Decimal = 0
If SMode = "04" Or SMode = "05" Then
CAxisValue = _XVal
ElseIf SMode = "02" Or SMode = "03" Then
CAxisValue = _YVal
ElseIf SMode = "00" Or SMode = "01" Then
CAxisValue = _ZVal

End If

If _ZDepth <= CAxisValue Then
Return False
Else
Return True

End If
End Function[code]
above is my code.when i am trying to run the code that time "Formatexception was un handled" and "Input string was not in correct format"these errors are occured and i want remove that errors.

Is This A Good Question/Topic? 0
  • +

Replies To: getting error when trying to run the code....how to remove it?

#2 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 765
  • Joined: 19-October 11

Re: getting error when trying to run the code....how to remove it?

Posted 20 November 2012 - 04:40 AM

My advice would be:
  • use function's parameters for setting local variables inside the function, so it won't be UI dependent (like Function CheckDepth(ByVal first As Decimal, ByVal second As Decimal,...) As Boolean)
  • use Decimal.TryParse to safely try to convert string(user input text) to decimal
  • learn how to debug your code, and understand your error messages

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1