Visual Basic Scripting (VBS) is a small programming language based on the Visual Basic language. It's used in network administration to automate tasks such as installing software, connecting and removing printers, and setting registry values on a client's computer. In all programming languages, the developer comes across the need to convert a string to a number. This can be done using the "CInt()" function in VBS.
Open the VBS file you want to edit in Notepad or any other simple text editor. VBS files are plain text, so they can be edited without any expensive compiler software.
Create a string variable with a numeric value. Although the numeric value is a number, when it is wrapped in quotations, it's considered a string in VBS. Below is an example of variable with an assigned a string value:
Dim strMyString As String
strMyString = "123"
Create a variable that will hold the converted string. Since the strMyString variable is designated as a string, you need to create a second variable designated as an integer. The following code creates an integer variable:
Dim intMyInt As Int
Convert the string and assign the value to the integer variable. Below is the code used to convert a string to an integer
intMyInt = CInt(strMyString)
The result of this conversion is that intMyInt now has the value of 123.
Tips & Warnings
- If the string is made up of characters or cannot be converted to a number, the compiler will return an error.
How to Convert a String to a Number in Visual Basic
Visual Basic (VB) is a programming language used to create desktop and website applications. One common part of VB programming is converting...