inputbox

  • Thread starter Thread starter about:mozilla
  • Start date Start date
A

about:mozilla

I'm just a newbie in vb.net and I have this terrible problem.
I want to use inputbox to get number.
-User can give numbers starting from 0
-If cancel is pressed then default number stays
-If text is given then messagebox gives error

Thanks in advance...

Newbie
 
about:mozilla said:
I'm just a newbie in vb.net and I have this terrible problem.
I want to use inputbox to get number.
-User can give numbers starting from 0
-If cancel is pressed then default number stays
-If text is given then messagebox gives error

Thanks in advance...

As a newbie you should get a book and learn basics of VB.NET.

My suggestion is "Murach's Beginning Visual Basic.NET"
 
about:mozilla said:
I'm just a newbie in vb.net and I have this terrible problem.
I want to use inputbox to get number.
-User can give numbers starting from 0
-If cancel is pressed then default number stays
-If text is given then messagebox gives error

The 'InputBox' is pretty limited in its functionality. It's currently
impossible to decide whether the user clicked the "Cancel" button or not.
As you say, input cannot be limited to a certain format too. If you want a
good user experience, implement a form that replaces 'InputBox' and provides
the additional functionality.
 
Dim sNumber As String
Dim iNumber As Integer

sNumber = InputBox("Enter a number", "Numbers Only", "0")

If IsNumeric(sNumber) Then
iNumber = CInt(sNumber)
Else
If sNumber <> "" Then 'Cancel returns an empty string
MessageBox.Show("Enter numeric values only", "Numbers Only",
MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End If
 
No, but it does what was asked and gives him something to play around with.
 
After all, he was asking for some pretty fundamental functionality. The
snippet I provided has everything for which he had asked. I didn't state that
it was the "end all" of input routines. The InputBox may have limitations
but it is still useful for simple data input.
 
ocertain said:
After all, he was asking for some pretty fundamental functionality. The
snippet I provided has everything for which he had asked. I didn't state
that
it was the "end all" of input routines. The InputBox may have
limitations
but it is still useful for simple data input.

I fully agree. The intention of my post was to make the OP aware of
possible limitations of the approach you posted.
 
And - as I stated - the snippet will work for the purposes the OP
established. The method you proposed may be a bit much for a beginner. Using
VB's built in objects like InputBox is a good way for a begginer to get his
feet wet. It's best to learn to walk before one attempts to runs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top