How to Output a String in Visual Basic

Save

In computer programming, the String variable is widely used to capture and output data among variables or controls. In Visual Basic, you can use the "ToString" method to output a String value to a String variable. This method is useful when you're using Double data types for mathematical operations and the output needs to be a String. You can also use this method to parse a string before it's displayed to the user.

  • Launch Microsoft Visual Basic Express, click "New Project..." on the left pane of your screen. Select "Console Application." Click "OK" to create a new console project.

  • Type the following code to declare a Double and a String variable:

    Dim myNumber As Double = 52.2

        Dim myString As String
  • Add the following code to convert the numeric value to its equivalent string representation and output the string using a message box:

    myString = myNumber.ToString()

        MsgBox(myString)
  • Click the "Debug" menu and click "Start Debugging" to run your program.

References

  • Photo Credit Stockbyte/Stockbyte/Getty Images
Promoted By Zergnet

Comments

You May Also Like

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

M
Is DIY in your DNA? Become part of our maker community.
Submit Your Work!