Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting string to integer

Tags:

vbscript

PrinterLabel = Printer + PrinterNumber  If Floors = 1 And (PrinterLabel) > 127 Then      Wscript.Echo "Invalid Printer11 Selection "         Wscript.Quit End If  If Floors = 2 And PrinterLabel > 220 Then      Wscript.Echo "Invalid Printerss Selection "         Wscript.Quit End If 

The problem is that PrinterLabel is a String and I want to convert it to an Int and compare it.

The PrinterLabel is a String that is also a number "218"

Any suggestions?

like image 963
Cocoa Dev Avatar asked Jan 20 '12 17:01

Cocoa Dev


People also ask

How do I convert text to integer?

Select the cells that have numbers stored as text. On the Home tab, click Paste > Paste Special. Click Multiply, and then click OK. Excel multiplies each cell by 1, and in doing so, converts the text to numbers.

Can you convert strings to integers in Python?

To convert, or cast, a string to an integer in Python, you use the int() built-in function. The function takes in as a parameter the initial string you want to convert, and returns the integer equivalent of the value you passed.

How do you change a string to an int C++?

One effective way to convert a string object into a numeral int is to use the stoi() function. This method is commonly used for newer versions of C++, with is being introduced with C++11. It takes as input a string value and returns as output the integer version of it.


1 Answers

The function you need is CInt.

ie CInt(PrinterLabel)

See Type Conversion Functions (Visual Basic) on MSDN

Edit: Be aware that CInt and its relatives behave differently in VB.net and VBScript. For example, in VB.net, CInt casts to a 32-bit integer, but in VBScript, CInt casts to a 16-bit integer. Be on the lookout for potential overflows!

like image 130
jon Avatar answered Oct 16 '22 09:10

jon