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))
Frage
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.
Lösung 3
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))
Andere Tipps
Declare lineNo
as string:
Dim lineNo As String = InputBox("What is the last record number?" &
vbNewLine & vbNewLine & "Enter line number 0 - 30.", "Enter Line Number", 0)
lineNo
must be declared as integer somewhere else in your code. Just pasted my code
on visual studio and no complaints.
Even use another string variable if you need lineNo as integer.
I presume lineNo is declared as Integer? Clicking "Cancel" on the InputBox will return an empty string, and an emptry string cannot be converted to a numeric value. That's what your error says.
So you should get the result of the InputBox, which always returns a String, and convert it in a separate step, maybe with Integer.TryParse
.