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

Visual Studio VB 2005 Convert String to Single and other types

Hi

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

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

        Try
            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.
0
 
ericwong27Commented:

        TryParse is a new feature in Vb2005

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

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