Search code examples
vb.netinputbox

Conversion from string "" to type 'Integer' is not valid. - VB.NET


When I click cancel button of the input box it shows this 'Conversion from string "" to type 'Integer' is not valid.' error in vb.net 2010. My code is,

Dim lineNo As Integer

lineNo = InputBox("What is the last record number?" & 
vbNewLine & vbNewLine & "Enter line number 0 - 30.", "Enter Line Number", 0)

What's the wrong in here?

Update: Dim lineNo As Integer. I have forgotten to state the declaration here.


Solution

  • since your inputbox return string so you have to do

    lineNo = val(InputBox("What is the last record number?" & vbNewLine & vbNewLine & "Enter line number 0 - 30.", "Enter Line Number", 0))