33
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?

Dan J
  • 16,319
  • 7
  • 50
  • 82
Cocoa Dev
  • 9,361
  • 31
  • 109
  • 177

1 Answers1

66

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!

Vivian River
  • 31,198
  • 62
  • 198
  • 313
jon
  • 5,986
  • 5
  • 28
  • 35
  • 1
    I tried to convert my Array which stores a string, but i get `Typeconflict: 'CInt'` – Black Nov 18 '15 at 20:48
  • @Black There must be some leading or trailing spaces in numeric string, use `Trim` function to remove them and then cast to a 16-bit integer using `CInt`. – GTAVLover Aug 23 '17 at 05:31