Results 1 to 10 of 10

Thread: [RESOLVED] Cast from String to type double is not valid

Hybrid View

  1. #1
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Cast from String to type double is not valid

    Use
    Double.TryParse method.

    Code:
    ' this will cast string to double:
    Dim str As String = "3.14"
    Dim d As Double = 0
    
    If Not Double.TryParse(str, d) Then
       ' The string is in invalid format
    End If

  2. #2

    Thread Starter
    Junior Member
    Join Date
    May 2010
    Posts
    26

    Re: Cast from String to type double is not valid

    HI i am relatively new to VB.NET. I have tried to add TryParse to my code but get an error saying that:

    Argument not specified for parameter 'result' pf [ublic Shared Function TryParse

    my amended code is:
    Code:
    Dim dValidType As Integer
    Dim d As Double = 0
    
    If Double.TryParse(OrderTotal, d) And OrderTotal >= dMinOrderTotal And OrderTotal <= dMaxOrderTotal Then
                dValidType = 0
    ElseIf Double.TryParse(OrderTotal, d) And (OrderTotal < dMinOrderTotal Or OrderTotal > dMaxOrderTotal) Then
             dValidType = 2
    Else
             dValidType = 1
    
    End If
    Return dValidType

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width