Technology Programming

How to Convert an Object to String in Visual Basic

    • 1). Create an object. For this example, a text box object is created. The code below creates a new text box object and saves it to a variable named "myTextbox."
      Dim myTextbox as Textbox
      myTextbox = New TextBox()

    • 2). Create a string variable to hold the converted string. This value can be used later in your code to determine the results. The code below creates a string variable for the conversion process:
      Dim strResult as String

    • 3). Convert the object to a string. The code below converts the text box object to a string and assigns the results to strResult:
      strResult = CType(myTextbox, String)

    • 4). Print the results to view the output. You can print to the debugger window to review the results of the conversion function using the following code:
      Print strResult



Leave a reply