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

Visual Studio VB 2005 Convert String to Single and other types


I have to convert a string Variable to Single. How does one do this.

Also how do you convert string values to other common types?

Thanks very much

Murray Brown
Murray Brown
2 Solutions
Carl TawnSystems and Integration DeveloperCommented:
       Dim s As String = "1.444"
        Dim sng As Single

            sng = CType(s, Single)
        Catch ex As InvalidCastException
            MessageBox.Show("Invalid conversion")
        End Try

Bear in mind that an "InvalidCastException" will be thrown if the cast you are trying is not possible.

        TryParse is a new feature in Vb2005

        Dim value As Integer = 0
        If Integer.TryParse("12", value) = False Then
        End If

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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