By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,558 Members | 1,607 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,558 IT Pros & Developers. It's quick & easy.

only integer

P: n/a
hi all,

how can i retrieve the type if a value inserted in an inputbox.

what i want to do is make shure people only insert an integer type, if they
don't they get an error message.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

inti = InputBox("Value", "Read frequenty")

End Sub

what should i add to this code that when the variable inti is'nt a number,
they get a massagbox "only numbers" .

kind regards Maarten
Nov 21 '05 #1
Share this Question
Share on Google+
38 Replies


P: n/a
"Maarten" <gu******@hotmail.com> schrieb:
how can i retrieve the type if a value inserted in an inputbox.

what i want to do is make shure people only insert an integer type, if
they don't they get an error message.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

inti = InputBox("Value", "Read frequenty")


\\\
inti = ...
Try
i = CInt(inti)
Catch
MsgBox("The number entered was not an integer.")
End Try
///

..NET 2.0 will have a 'Int32.TryParse' method.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2

P: n/a
hi,
thanks for the reply, but...

i tried yourre code, but it won't give the messagebox if i enter a non
integer

kind regards
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eb**************@TK2MSFTNGP14.phx.gbl...
"Maarten" <gu******@hotmail.com> schrieb:
how can i retrieve the type if a value inserted in an inputbox.

what i want to do is make shure people only insert an integer type, if
they don't they get an error message.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

inti = InputBox("Value", "Read frequenty")


\\\
inti = ...
Try
i = CInt(inti)
Catch
MsgBox("The number entered was not an integer.")
End Try
///

.NET 2.0 will have a 'Int32.TryParse' method.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3

P: n/a
I should, what value did you enter? Post your new code?

Chris

"Maarten" <gu******@hotmail.com> wrote in message
news:41***********************@news.skynet.be...
hi,
thanks for the reply, but...

i tried yourre code, but it won't give the messagebox if i enter a non
integer

kind regards
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eb**************@TK2MSFTNGP14.phx.gbl...
"Maarten" <gu******@hotmail.com> schrieb:
how can i retrieve the type if a value inserted in an inputbox.

what i want to do is make shure people only insert an integer type, if
they don't they get an error message.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

inti = InputBox("Value", "Read frequenty")


\\\
inti = ...
Try
i = CInt(inti)
Catch
MsgBox("The number entered was not an integer.")
End Try
///

.NET 2.0 will have a 'Int32.TryParse' method.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Nov 21 '05 #4

P: n/a
You could use the following function. It is only good for checking for
non-negative numbers.
if bNumbersOnly = True, the routine will return a -1 if the string is
not all numbers.
if bNumbersOnly = False, the routine will return the integer value of
all of the numbers in a string and ignore all other characters. $1,234
would return 1234. "There are 12 entries" would return 12. "Found 1 in
2000" would return 12000. So be careful out there! :)

'---------- Get the numbers from a string ----------
Public Function AtoI(ByVal s As String, ByVal bNumbersOnly As
Boolean) As Integer
Dim nLen As Integer ' Length of the
string
Dim i As Integer ' Loop counter
Dim nDigit As Integer ' Each digit
Dim nTot As Integer

nTot = 0 ' Starting value
nLen = s.Length ' Number of
characters
For i = 0 To nLen - 1 ' Check all
characters
nDigit = Asc(s.Substring(i, 1)) - 48 ' Get the current
digit
If nDigit >= 0 And nDigit <= 9 Then
nTot = nTot * 10 + nDigit ' Calculate digit
Else
If bNumbersOnly Then ' Only allow
numerics
nTot = -1 ' Flag as an error
Exit For ' Force routine to
end
End If
End If
Next i
Return (nTot) ' Return Value
End Function

Nov 21 '05 #5

P: n/a
Sorry about the indentations. Apparently postings knock out leading
tabs in the code.

Nov 21 '05 #6

P: n/a
this is the code,

Dim i As Integer

Dim Tmrsp as long

Tmrsp = InputBox("Value", "Read frequenty")

Try

i = CInt(inti)

MsgBox(Tmrsp)

Catch

MsgBox("The number entered was not an integer.")

End Try

End Sub
what does the catch statement do?

thanks Maarten

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:uw**************@tk2msftngp13.phx.gbl...
I should, what value did you enter? Post your new code?

Chris

"Maarten" <gu******@hotmail.com> wrote in message
news:41***********************@news.skynet.be...
hi,
thanks for the reply, but...

i tried yourre code, but it won't give the messagebox if i enter a non
integer

kind regards
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eb**************@TK2MSFTNGP14.phx.gbl...
"Maarten" <gu******@hotmail.com> schrieb:
how can i retrieve the type if a value inserted in an inputbox.

what i want to do is make shure people only insert an integer type, if
they don't they get an error message.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

inti = InputBox("Value", "Read frequenty")

\\\
inti = ...
Try
i = CInt(inti)
Catch
MsgBox("The number entered was not an integer.")
End Try
///

.NET 2.0 will have a 'Int32.TryParse' method.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>



Nov 21 '05 #7

P: n/a
thanks for the code, but i have a problem with the function

i've never workes with functions, and i don't know how to send the text
trough the function, and then retreave it.

sry for this beginners question, but i'm realy intrested to know how it
works and how to make them.

kind regards Maarten
<sh***********@yahoo.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Sorry about the indentations. Apparently postings knock out leading
tabs in the code.

Nov 21 '05 #8

P: n/a
You could try using regex for this kind of test.

Dim s as string = InputBox("Value", "Read frequenty<sic>")

Dim rNumber As New System.Text.RegularExpressions.Regex("^\d*$")
If rNumber.IsMatch(s) Then
msgbox("ok")
Else
msgbox("not a whole number")
End If

HTH,
Greg

"Maarten" <gu******@hotmail.com> wrote in message
news:41**********************@news.skynet.be...
hi all,

how can i retrieve the type if a value inserted in an inputbox.

what i want to do is make shure people only insert an integer type, if
they don't they get an error message.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

inti = InputBox("Value", "Read frequenty")

End Sub

what should i add to this code that when the variable inti is'nt a
number, they get a massagbox "only numbers" .

kind regards Maarten

Nov 21 '05 #9

P: n/a
See below...

Maarten wrote:
this is the code,

Dim i As Integer

Dim Tmrsp as long

Tmrsp = InputBox("Value", "Read frequenty")
Tmrsp is now a long with the value typed in inputbox.
Please notice that you do nothing else with this variable then print a
messagebox with its value. What this example originally was trying to
show you is (if I am not mistaken) that, by using CInt and a string as
its parameter, this function would fail and would jump to the Catch
section showing the messagebox (here is determined that the string
entered was not an number). Still I find Double.TryParse(...) easier.
And if you don't mind using the vb classes:
Microsoft.VisualBasic.Information.IsNumeric("a string")

Try

i = CInt(inti)

MsgBox(Tmrsp)

Catch

MsgBox("The number entered was not an integer.")

End Try

End Sub
what does the catch statement do?

thanks Maarten

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:uw**************@tk2msftngp13.phx.gbl...
I should, what value did you enter? Post your new code?

Chris

"Maarten" <gu******@hotmail.com> wrote in message
news:41***********************@news.skynet.be. ..
hi,
thanks for the reply, but...

i tried yourre code, but it won't give the messagebox if i enter a non
integer

kind regards
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eb**************@TK2MSFTNGP14.phx.gbl...

"Maarten" <gu******@hotmail.com> schrieb:

>how can i retrieve the type if a value inserted in an inputbox.
>
>what i want to do is make shure people only insert an integer type, if
>they don't they get an error message.
>
>
>Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
>System.EventArgs) Handles Button2.Click
>
>inti = InputBox("Value", "Read frequenty")

\\\
inti = ...
Try
i = CInt(inti)
Catch
MsgBox("The number entered was not an integer.")
End Try
///

.NET 2.0 will have a 'Int32.TryParse' method.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Nov 21 '05 #10

P: n/a
Well you are trying to Cint(inti) but you never set it to a value. Try
this:
Dim i As Integer

Dim Tmrsp as long

Tmrsp = InputBox("Value", "Read frequenty")

Try

i = CInt(Tmrsp)

MsgBox(Tmrsp)

Catch

MsgBox("The number entered was not an integer.")

End Try

End Sub
The try...catch handles an exception. An exception will be thrown by the
Cint() funciton if it can not convert the Tmrsp variable to a integer. Read
up in the help file on it.

Chris


"Maarten" <gu******@hotmail.com> wrote in message
news:41***********************@news.skynet.be...
this is the code,

Dim i As Integer

Dim Tmrsp as long

Tmrsp = InputBox("Value", "Read frequenty")

Try

i = CInt(inti)

MsgBox(Tmrsp)

Catch

MsgBox("The number entered was not an integer.")

End Try

End Sub
what does the catch statement do?

thanks Maarten

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com>
wrote in message news:uw**************@tk2msftngp13.phx.gbl...
I should, what value did you enter? Post your new code?

Chris

"Maarten" <gu******@hotmail.com> wrote in message
news:41***********************@news.skynet.be...
hi,
thanks for the reply, but...

i tried yourre code, but it won't give the messagebox if i enter a non
integer

kind regards
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eb**************@TK2MSFTNGP14.phx.gbl...
"Maarten" <gu******@hotmail.com> schrieb:
> how can i retrieve the type if a value inserted in an inputbox.
>
> what i want to do is make shure people only insert an integer type, if
> they don't they get an error message.
>
>
> Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button2.Click
>
> inti = InputBox("Value", "Read frequenty")

\\\
inti = ...
Try
i = CInt(inti)
Catch
MsgBox("The number entered was not an integer.")
End Try
///

.NET 2.0 will have a 'Int32.TryParse' method.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>



Nov 21 '05 #11

P: n/a
you can try this,

if not isnumeric(InputBox("Value", "Read frequenty")) then
msgbox "only numbers please"
endif

"Maarten" <gu******@hotmail.com> escribió en el mensaje
news:41**********************@news.skynet.be...
hi all,

how can i retrieve the type if a value inserted in an inputbox.

what i want to do is make shure people only insert an integer type, if
they don't they get an error message.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

inti = InputBox("Value", "Read frequenty")

End Sub

what should i add to this code that when the variable inti is'nt a
number, they get a massagbox "only numbers" .

kind regards Maarten

Nov 21 '05 #12

P: n/a
Does the OP want any number or only an "integer" (aka whole number) ???

Greg

"Renán Wug" <rw**@globalcementsa.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
you can try this,

if not isnumeric(InputBox("Value", "Read frequenty")) then
msgbox "only numbers please"
endif

"Maarten" <gu******@hotmail.com> escribió en el mensaje
news:41**********************@news.skynet.be...
hi all,

how can i retrieve the type if a value inserted in an inputbox.

what i want to do is make shure people only insert an integer type, if
they don't they get an error message.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

inti = InputBox("Value", "Read frequenty")

End Sub

what should i add to this code that when the variable inti is'nt a
number, they get a massagbox "only numbers" .

kind regards Maarten


Nov 21 '05 #13

P: n/a
Maarten,

Strange somebody else involved in this does not show you this thread from 4
days ago, I think almost everything you ask is in that.

http://groups-beta.google.com/group/...9fe8d699acb4bd
I hope this helps?

Cor

"Maarten" <gu******@hotmail.com>
hi all,

how can i retrieve the type if a value inserted in an inputbox.

what i want to do is make shure people only insert an integer type, if
they don't they get an error message.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

inti = InputBox("Value", "Read frequenty")

End Sub

what should i add to this code that when the variable inti is'nt a
number, they get a massagbox "only numbers" .

kind regards Maarten

Nov 21 '05 #14

P: n/a
"Maarten" <gu******@hotmail.com> schrieb:
Dim i As Integer

Dim Tmrsp as long

Tmrsp = InputBox("Value", "Read frequenty")

Try

i = CInt(inti)

What's 'inti'?

Notice that 'InputBox' returns a string, so there is an implicit type
conversion done in the code above without 'Option Strict On'.

\\\
Dim s As String = InputBox("Value", Read fequenty")
Dim i As Integer
Try
i = CInt(s)
...
Catch
MsgBox("You didn't enter an integer!")
End Try
///

Add these lines on top of your source file:

\\\
Option Explicit On
Option Strict On
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #15

P: n/a
@Herfried K. Wagner, about the "Option Explicit On" and "Option Strict
On" settings: Isn't it more efficient to do this at project level
instead of source file level?

Herfried K. Wagner [MVP] wrote:
"Maarten" <gu******@hotmail.com> schrieb:
Dim i As Integer

Dim Tmrsp as long

Tmrsp = InputBox("Value", "Read frequenty")

Try

i = CInt(inti)


What's 'inti'?

Notice that 'InputBox' returns a string, so there is an implicit type
conversion done in the code above without 'Option Strict On'.

\\\
Dim s As String = InputBox("Value", Read fequenty")
Dim i As Integer
Try
i = CInt(s)
...
Catch
MsgBox("You didn't enter an integer!")
End Try
///

Add these lines on top of your source file:

\\\
Option Explicit On
Option Strict On
///

Nov 21 '05 #16

P: n/a

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote
how can i retrieve the type if a value inserted in an inputbox.
\\\
inti = ...
Try
i = CInt(inti)
Catch
MsgBox("The number entered was not an integer.")
End Try
///


Best practises suggest that you really should not be using exceptions
to control program logic. There are basically 3 types of exceptions
that an application can have:

1. Anticipated errors
2. Unanticipated errors
3. Business rule violations

( http://msdn.microsoft.com/library/de...orhandling.asp )

Error handling should ordinarily be reserved for (2.) unanticipated
errors, while the other two should be coded (or refactored) to test
for proper conditions.

From the Best Practises page:
( http://msdn.microsoft.com/library/de...exceptions.asp )

"The method you choose depends on how often you expect the event to occur. If the event
is truly exceptional and is an error (such as an unexpected end-of-file), using exception
handling is better because less code is executed in the normal case. If the event happens
routinely, using the programmatic method to check for errors is better. "

Also:
( http://msdn.microsoft.com/library/de...netchapt05.asp )

"While exception handling is recommended to create robust, maintainable code, there is an
associated performance cost. Throwing and catching exceptions is expensive. For this reason,
you should use exceptions only in exceptional circumstances and not to control regular logic
flow. A good rule of thumb is that the exceptional path should be taken less than one
time in a thousand."

HTH
LFS
Nov 21 '05 #17

P: n/a
"Michel van den Berg" <mv*@promontis.nl> schrieb:
@Herfried K. Wagner, about the "Option Explicit On" and "Option Strict On"
settings: Isn't it more efficient to do this at project level instead of
source file level?


Yes, that's easier, but if you are working with a large project that was
developed with 'Option * Off' then it's easier to turn it on on file-by-file
basis.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #18

P: n/a
Larry,

"Larry Serflaten" <se*******@usinternet.com> schrieb:
> how can i retrieve the type if a value inserted in an inputbox.

\\\
inti = ...
Try
i = CInt(inti)
Catch
MsgBox("The number entered was not an integer.")
End Try
///


Best practises suggest that you really should not be using exceptions
to control program logic.


Well, I know that, but what are the alternatives in this particular case, as
long as there is no 'Int32.TryParse'? OK, maybe we could utilize
'Double.TryParse' or regular expressions + range check, but this is IMO far
too complicated to implement and should be possible out of the box (which is
the case for .NET 2.0).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #19

P: n/a

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote
Best practises suggest that you really should not be using exceptions
to control program logic.


Well, I know that, but what are the alternatives in this particular case, as
long as there is no 'Int32.TryParse'? OK, maybe we could utilize
'Double.TryParse' or regular expressions + range check, but this is IMO far
too complicated to implement and should be possible out of the box (which is
the case for .NET 2.0).


Too complicated? Since when has writting user interface code been a breeze ???
<g>

For one such alternative:

Dim user As String
Do
user = InputBox("Enter a number")
If user.Length = 0 OrElse user Like "*[!0-9]*" Then
MsgBox("A numeric value is required to continue.")
Else
Console.WriteLine(user)
Exit Do
End If
Loop
A more robust solution would be:

Dim user As String
Dim value As Integer
Do
user = InputBox("Enter a number")
If user.Length = 0 OrElse user Like "*[!0-9]*" Then
MsgBox("A numeric value is required to continue.")
Else
If user.Length < 11 _
AndAlso CLng(user) <= Integer.MaxValue _
AndAlso CLng(user) >= Integer.MinValue Then
value = CInt(user)
Exit Do
Else
MsgBox("Please enter a whole number between " _
& Integer.MinValue & " and " & Integer.MaxValue)
End If
End If
Loop
Console.WriteLine(value)
LFS

Nov 21 '05 #20

P: n/a
Larry,

"Larry Serflaten" <se*******@usinternet.com> schrieb:
> Best practises suggest that you really should not be using exceptions
> to control program logic.


Well, I know that, but what are the alternatives in this particular case,
as
long as there is no 'Int32.TryParse'? OK, maybe we could utilize
'Double.TryParse' or regular expressions + range check, but this is IMO
far
too complicated to implement and should be possible out of the box (which
is
the case for .NET 2.0).


Too complicated? Since when has writting user interface code been a
breeze ???
<g>
[...]
A more robust solution would be:

Dim user As String
Dim value As Integer
Do
user = InputBox("Enter a number")
If user.Length = 0 OrElse user Like "*[!0-9]*" Then
MsgBox("A numeric value is required to continue.")
Else
If user.Length < 11 _
AndAlso CLng(user) <= Integer.MaxValue _
AndAlso CLng(user) >= Integer.MinValue Then
value = CInt(user)
Exit Do
Else
MsgBox("Please enter a whole number between " _
& Integer.MinValue & " and " &
Integer.MaxValue)
End If
End If
Loop


'CLng' can throw an exception too when the parsed number does not fit into
the 'Long' datatype...

;-)

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #21

P: n/a
the Op want's a number, see what i want do do is an option to set the
timerspeed of a timer

this can be a number from 0 to 1,2,3,4,5,....10 000 and more
but if the text in the inputbox is like "jjfjfj" or "1.555" or "^^4654klj"
, i need a messagebox that says please enter a valid number to set the
timerspeed.

kind regards Maarten

Ps: thanks for all the reply's i realy appreciate it

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:e$**************@TK2MSFTNGP14.phx.gbl...
Does the OP want any number or only an "integer" (aka whole number) ???

Greg

"Renán Wug" <rw**@globalcementsa.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
you can try this,

if not isnumeric(InputBox("Value", "Read frequenty")) then
msgbox "only numbers please"
endif

"Maarten" <gu******@hotmail.com> escribió en el mensaje
news:41**********************@news.skynet.be...
hi all,

how can i retrieve the type if a value inserted in an inputbox.

what i want to do is make shure people only insert an integer type, if
they don't they get an error message.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

inti = InputBox("Value", "Read frequenty")

End Sub

what should i add to this code that when the variable inti is'nt a
number, they get a massagbox "only numbers" .

kind regards Maarten



Nov 21 '05 #22

P: n/a
Hey OP, 1.555 is a number. :^) You want a whole number.

I stand by my original suggestion of using regex expression:

Dim s as string = InputBox("Value", "Read frequenty<sic>")

Dim rNumber As New System.Text.RegularExpressions.Regex("^\d*$")
If rNumber.IsMatch(s) Then
msgbox("ok")
Else
msgbox("not a whole number")
End If

Greg

"Maarten" <gu******@hotmail.com> wrote in message
news:41***********************@news.skynet.be...
the Op want's a number, see what i want do do is an option to set the
timerspeed of a timer

this can be a number from 0 to 1,2,3,4,5,....10 000 and more
but if the text in the inputbox is like "jjfjfj" or "1.555" or
"^^4654klj" , i need a messagebox that says please enter a valid number to
set the timerspeed.

kind regards Maarten

Ps: thanks for all the reply's i realy appreciate it

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:e$**************@TK2MSFTNGP14.phx.gbl...
Does the OP want any number or only an "integer" (aka whole number) ???

Greg

"Renán Wug" <rw**@globalcementsa.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
you can try this,

if not isnumeric(InputBox("Value", "Read frequenty")) then
msgbox "only numbers please"
endif

"Maarten" <gu******@hotmail.com> escribió en el mensaje
news:41**********************@news.skynet.be...
hi all,

how can i retrieve the type if a value inserted in an inputbox.

what i want to do is make shure people only insert an integer type, if
they don't they get an error message.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

inti = InputBox("Value", "Read frequenty")

End Sub

what should i add to this code that when the variable inti is'nt a
number, they get a massagbox "only numbers" .

kind regards Maarten



Nov 21 '05 #23

P: n/a

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote
If user.Length < 11 _
AndAlso CLng(user) <= Integer.MaxValue _
AndAlso CLng(user) >= Integer.MinValue Then

'CLng' can throw an exception too when the parsed number does not fit into
the 'Long' datatype...


It would be impossible to overflow a Long type with only 10 digits....

<g>
LFS
Nov 21 '05 #24

P: n/a

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote
I stand by my original suggestion of using regex expression:

Dim s as string = InputBox("Value", "Read frequenty<sic>")

Dim rNumber As New System.Text.RegularExpressions.Regex("^\d*$")
If rNumber.IsMatch(s) Then
msgbox("ok")
Else
msgbox("not a whole number")
End If


That certainly seems like an easy solution to me...

Now if I could only bring myself to learn more about that RegEx syntax!

;-)
LFS
Nov 21 '05 #25

P: n/a
> Now if I could only bring myself to learn more about that RegEx syntax!

This will do it...

http://www.bookpool.com/.x/ahatnbdcc6/sm/0596002890

Greg
"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote
I stand by my original suggestion of using regex expression:

Dim s as string = InputBox("Value", "Read frequenty<sic>")

Dim rNumber As New System.Text.RegularExpressions.Regex("^\d*$")
If rNumber.IsMatch(s) Then
msgbox("ok")
Else
msgbox("not a whole number")
End If


That certainly seems like an easy solution to me...

Now if I could only bring myself to learn more about that RegEx syntax!

;-)
LFS

Nov 21 '05 #26

P: n/a
Maarten,

First, I don't understand why I see such a long thread while everything in
my opinion is alreayd told in the the thread I showed you about this (last
message in this thread).

However, when you with a valid number would be in my opinion "dim myinteger
as integer = Cint(textbox.text)" and as well a limit of the max and the
minimum of the integer all you have to do, or my example I show you in the
thread where the maximum positions of the textbox are limited.

However there is more written in that thread as well by Larry, Herfried, and
Alex.

Cor

"Maarten" <gu******@hotmail.com>
the Op want's a number, see what i want do do is an option to set the
timerspeed of a timer

this can be a number from 0 to 1,2,3,4,5,....10 000 and more
but if the text in the inputbox is like "jjfjfj" or "1.555" or
"^^4654klj" , i need a messagebox that says please enter a valid number to
set the timerspeed.

kind regards Maarten

Ps: thanks for all the reply's i realy appreciate it

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:e$**************@TK2MSFTNGP14.phx.gbl...
Does the OP want any number or only an "integer" (aka whole number) ???

Greg

"Renán Wug" <rw**@globalcementsa.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
you can try this,

if not isnumeric(InputBox("Value", "Read frequenty")) then
msgbox "only numbers please"
endif

"Maarten" <gu******@hotmail.com> escribió en el mensaje
news:41**********************@news.skynet.be...
hi all,

how can i retrieve the type if a value inserted in an inputbox.

what i want to do is make shure people only insert an integer type, if
they don't they get an error message.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

inti = InputBox("Value", "Read frequenty")

End Sub

what should i add to this code that when the variable inti is'nt a
number, they get a massagbox "only numbers" .

kind regards Maarten



Nov 21 '05 #27

P: n/a
Larry,

"Larry Serflaten" <se*******@usinternet.com> schrieb:
> If user.Length < 11 _
> AndAlso CLng(user) <= Integer.MaxValue _
> AndAlso CLng(user) >= Integer.MinValue Then


'CLng' can throw an exception too when the parsed number does not fit
into
the 'Long' datatype...


It would be impossible to overflow a Long type with only 10 digits....

<g>


Oh, I missed that... :-(((.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #28

P: n/a
"Larry Serflaten" <se*******@usinternet.com> schrieb:
It would be impossible to overflow a Long type with only 10 digits....

<g>
LFS


The user could enter "10E200" AFAIS...

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #29

P: n/a
Maarten wrote:
hi all,

how can i retrieve the type if a value inserted in an inputbox.

what i want to do is make shure people only insert an integer type, if they
don't they get an error message.


The way I do it is to add a handler to the keypress event and filter out
any character not in the 0-9 range. That way they can't even enter non
numeric values. I don't understand why noone in this thread has thought
about that option yet.
--
Rinze van Huizen
C-Services Holland b.v.
Nov 21 '05 #30

P: n/a

"C-Services Holland b.v." <cs*@REMOVEcsh4u.nl> wrote

how can i retrieve the type if a value inserted in an inputbox.

what i want to do is make shure people only insert an integer type, if they
don't they get an error message.


The way I do it is to add a handler to the keypress event and filter out
any character not in the 0-9 range. That way they can't even enter non
numeric values. I don't understand why noone in this thread has thought
about that option yet.

Re-read the first sentence, you don't get events from the InputBox....

;-)
LFS
Nov 21 '05 #31

P: n/a
thank you verry much, this works fine and is just what i needed.

regards,
Maarten

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:O4**************@TK2MSFTNGP09.phx.gbl...
Hey OP, 1.555 is a number. :^) You want a whole number.

I stand by my original suggestion of using regex expression:

Dim s as string = InputBox("Value", "Read frequenty<sic>")

Dim rNumber As New System.Text.RegularExpressions.Regex("^\d*$")
If rNumber.IsMatch(s) Then
msgbox("ok")
Else
msgbox("not a whole number")
End If

Greg

"Maarten" <gu******@hotmail.com> wrote in message
news:41***********************@news.skynet.be...
the Op want's a number, see what i want do do is an option to set the
timerspeed of a timer

this can be a number from 0 to 1,2,3,4,5,....10 000 and more
but if the text in the inputbox is like "jjfjfj" or "1.555" or
"^^4654klj" , i need a messagebox that says please enter a valid number
to set the timerspeed.

kind regards Maarten

Ps: thanks for all the reply's i realy appreciate it

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:e$**************@TK2MSFTNGP14.phx.gbl...
Does the OP want any number or only an "integer" (aka whole number) ???

Greg

"Renán Wug" <rw**@globalcementsa.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
you can try this,

if not isnumeric(InputBox("Value", "Read frequenty")) then
msgbox "only numbers please"
endif

"Maarten" <gu******@hotmail.com> escribió en el mensaje
news:41**********************@news.skynet.be...
> hi all,
>
> how can i retrieve the type if a value inserted in an inputbox.
>
> what i want to do is make shure people only insert an integer type, if
> they don't they get an error message.
>
>
> Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button2.Click
>
> inti = InputBox("Value", "Read frequenty")
>
> End Sub
>
>
>
> what should i add to this code that when the variable inti is'nt a
> number, they get a massagbox "only numbers" .
>
>
>
> kind regards Maarten
>
>



Nov 21 '05 #32

P: n/a
Hi all

thanks for the plenty of replies, it works fine now

i used the code of greg and does a great job

Dim s as string = InputBox("Value", "Read frequenty<sic>")

Dim rNumber As New System.Text.RegularExpressions.Regex("^\d*$")
If rNumber.IsMatch(s) Then
msgbox("ok")
Else
msgbox("not a whole number")
End If
kind regards,
Maarten
"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...

"C-Services Holland b.v." <cs*@REMOVEcsh4u.nl> wrote
>
> how can i retrieve the type if a value inserted in an inputbox.
>
> what i want to do is make shure people only insert an integer type, if
> they
> don't they get an error message.


The way I do it is to add a handler to the keypress event and filter out
any character not in the 0-9 range. That way they can't even enter non
numeric values. I don't understand why noone in this thread has thought
about that option yet.

Re-read the first sentence, you don't get events from the InputBox....

;-)
LFS

Nov 21 '05 #33

P: n/a
"Maarten" <gu******@hotmail.com> schrieb:
i used the code of greg and does a great job

Dim s as string = InputBox("Value", "Read frequenty<sic>")

Dim rNumber As New System.Text.RegularExpressions.Regex("^\d*$")
If rNumber.IsMatch(s) Then
msgbox("ok")
Else
msgbox("not a whole number")
End If


Mhm... The code won't prevent the user from entering a number that does not
fit into an 'Integer' or 'Long' -- and thus will throw an exception when
parsing.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #34

P: n/a
thanks,

i can't figure that out, becouse the source is set to a textbox type, but
what textbox?

i tried to set the source to the variable s of the inputbox, but can't get
it to work

i'm intersted in this tread becouse it uses the errorprovider, and i like to
know more about is

i beleave it is new in vb.net or am i wrong?.

Thanks,
Maarten

"Cor Ligthert" <no************@planet.nl> wrote in message
news:eG**************@TK2MSFTNGP09.phx.gbl...
Maarten,

Strange somebody else involved in this does not show you this thread from
4 days ago, I think almost everything you ask is in that.

http://groups-beta.google.com/group/...9fe8d699acb4bd
I hope this helps?

Cor

"Maarten" <gu******@hotmail.com>
hi all,

how can i retrieve the type if a value inserted in an inputbox.

what i want to do is make shure people only insert an integer type, if
they don't they get an error message.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

inti = InputBox("Value", "Read frequenty")

End Sub

what should i add to this code that when the variable inti is'nt a
number, they get a massagbox "only numbers" .

kind regards Maarten


Nov 21 '05 #35

P: n/a
Larry Serflaten wrote:
"C-Services Holland b.v." <cs*@REMOVEcsh4u.nl> wrote
how can i retrieve the type if a value inserted in an inputbox.

what i want to do is make shure people only insert an integer type, if they
don't they get an error message.


The way I do it is to add a handler to the keypress event and filter out
any character not in the 0-9 range. That way they can't even enter non
numeric values. I don't understand why noone in this thread has thought
about that option yet.


Re-read the first sentence, you don't get events from the InputBox....

;-)
LFS


GAH inputbox... that's why I made my own input class :) Basically looks
the same as the inputbox, but with all the events exposed.

--
Rinze van Huizen
C-Services Holland b.v.
Nov 21 '05 #36

P: n/a
Just one more thing. ;)
First, I don't understand why I see such a long thread while everything in
my opinion is alreayd told in the the thread I showed you about this (last
message in this thread).
No mention of a regex solution in the aforementioned thread...
However, when you with a valid number would be in my opinion "dim
myinteger as integer = Cint(textbox.text)"
Yeah, if you have a valid number this will work, otherwise you get an
exception. It gives no feedback if the user enters a decimal number. Isn't
that the whole point of this thread: validating a whole number?
...as well a limit of the max and the minimum of the integer all you have
to do, or my example I show you in the thread where the maximum positions
of the textbox are limited.
The OP is using an InputBox, not a TextBox control.

Greg
"Cor Ligthert" <no************@planet.nl> wrote in message
news:er**************@TK2MSFTNGP09.phx.gbl... Maarten,

First, I don't understand why I see such a long thread while everything in
my opinion is alreayd told in the the thread I showed you about this (last
message in this thread).

However, when you with a valid number would be in my opinion "dim
myinteger as integer = Cint(textbox.text)" and as well a limit of the max
and the minimum of the integer all you have to do, or my example I show
you in the thread where the maximum positions of the textbox are limited.

However there is more written in that thread as well by Larry, Herfried,
and Alex.

Cor

"Maarten" <gu******@hotmail.com>
the Op want's a number, see what i want do do is an option to set the
timerspeed of a timer

this can be a number from 0 to 1,2,3,4,5,....10 000 and more
but if the text in the inputbox is like "jjfjfj" or "1.555" or
"^^4654klj" , i need a messagebox that says please enter a valid number
to set the timerspeed.

kind regards Maarten

Ps: thanks for all the reply's i realy appreciate it

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:e$**************@TK2MSFTNGP14.phx.gbl...
Does the OP want any number or only an "integer" (aka whole number) ???

Greg

"Renán Wug" <rw**@globalcementsa.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
you can try this,

if not isnumeric(InputBox("Value", "Read frequenty")) then
msgbox "only numbers please"
endif

"Maarten" <gu******@hotmail.com> escribió en el mensaje
news:41**********************@news.skynet.be...
> hi all,
>
> how can i retrieve the type if a value inserted in an inputbox.
>
> what i want to do is make shure people only insert an integer type, if
> they don't they get an error message.
>
>
> Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button2.Click
>
> inti = InputBox("Value", "Read frequenty")
>
> End Sub
>
>
>
> what should i add to this code that when the variable inti is'nt a
> number, they get a massagbox "only numbers" .
>
>
>
> kind regards Maarten
>
>



Nov 21 '05 #37

P: n/a
I'll give you that, but it is a simple fix.

^\d{0,10}$

Greg
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eE****************@tk2msftngp13.phx.gbl...
"Maarten" <gu******@hotmail.com> schrieb:
i used the code of greg and does a great job

Dim s as string = InputBox("Value", "Read frequenty<sic>")

Dim rNumber As New System.Text.RegularExpressions.Regex("^\d*$")
If rNumber.IsMatch(s) Then
msgbox("ok")
Else
msgbox("not a whole number")
End If


Mhm... The code won't prevent the user from entering a number that does
not fit into an 'Integer' or 'Long' -- and thus will throw an exception
when parsing.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #38

P: n/a
Greg,

I missed the inputbox, he answered it to me as well, however thanks.
(This can be done than of course with .length)
However when the regex function fits, than why botter it is nice short.

:-)

Cor

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> > Just one more thing. ;)
First, I don't understand why I see such a long thread while everything
in my opinion is alreayd told in the the thread I showed you about this
(last message in this thread).


No mention of a regex solution in the aforementioned thread...
However, when you with a valid number would be in my opinion "dim
myinteger as integer = Cint(textbox.text)"


Yeah, if you have a valid number this will work, otherwise you get an
exception. It gives no feedback if the user enters a decimal number.
Isn't that the whole point of this thread: validating a whole number?
...as well a limit of the max and the minimum of the integer all you have
to do, or my example I show you in the thread where the maximum positions
of the textbox are limited.


The OP is using an InputBox, not a TextBox control.

Greg
"Cor Ligthert" <no************@planet.nl> wrote in message
news:er**************@TK2MSFTNGP09.phx.gbl...
Maarten,

First, I don't understand why I see such a long thread while everything
in my opinion is alreayd told in the the thread I showed you about this
(last message in this thread).

However, when you with a valid number would be in my opinion "dim
myinteger as integer = Cint(textbox.text)" and as well a limit of the max
and the minimum of the integer all you have to do, or my example I show
you in the thread where the maximum positions of the textbox are limited.

However there is more written in that thread as well by Larry, Herfried,
and Alex.

Cor

"Maarten" <gu******@hotmail.com>
the Op want's a number, see what i want do do is an option to set the
timerspeed of a timer

this can be a number from 0 to 1,2,3,4,5,....10 000 and more
but if the text in the inputbox is like "jjfjfj" or "1.555" or
"^^4654klj" , i need a messagebox that says please enter a valid number
to set the timerspeed.

kind regards Maarten

Ps: thanks for all the reply's i realy appreciate it

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:e$**************@TK2MSFTNGP14.phx.gbl...
Does the OP want any number or only an "integer" (aka whole number) ???

Greg

"Renán Wug" <rw**@globalcementsa.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
> you can try this,
>
> if not isnumeric(InputBox("Value", "Read frequenty")) then
> msgbox "only numbers please"
> endif
>
> "Maarten" <gu******@hotmail.com> escribió en el mensaje
> news:41**********************@news.skynet.be...
>> hi all,
>>
>> how can i retrieve the type if a value inserted in an inputbox.
>>
>> what i want to do is make shure people only insert an integer type,
>> if they don't they get an error message.
>>
>>
>> Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
>> System.EventArgs) Handles Button2.Click
>>
>> inti = InputBox("Value", "Read frequenty")
>>
>> End Sub
>>
>>
>>
>> what should i add to this code that when the variable inti is'nt a
>> number, they get a massagbox "only numbers" .
>>
>>
>>
>> kind regards Maarten
>>
>>
>
>



Nov 21 '05 #39

This discussion thread is closed

Replies have been disabled for this discussion.