Visual Studio VB 2005 Convert String to Single and other types

Posted on 2006-04-06
Last Modified: 2007-12-19

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

Question by:murbro
    LVL 52

    Accepted Solution

           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.
    LVL 10

    Assisted Solution


            TryParse is a new feature in Vb2005

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

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now