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 38 2126
"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/>
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/>
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/>
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
Sorry about the indentations. Apparently postings knock out leading
tabs in the code.
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/>
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.
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
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/>
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/>
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
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
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
"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/>
@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 ///
"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
"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/>
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/>
"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
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/>
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
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
"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
"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
> 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
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
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/>
"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/>
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.
"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
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 > >
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
"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/>
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
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.
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 > >
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/>
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 >> >> > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: root |
last post by:
Hi group,
Apologies in advance if this has been asked somewhere before, but I haven't
managed to get anything from the Google archives - I've been getting
introductory guides to C++ all day...
|
by: Timothy Madden |
last post by:
Hello
I've read here that only C language has a standard 64bit integer.
Can you please tell me what are the reasons for this ? What is special about
C language ?
Can you please show me some...
|
by: roni |
last post by:
hi.
i hope i will be clear here,
i want to know ,what method i need to use in the asp.net for minimal
process,to send only 1 integer to the client.(its just example).
what i mean is, i dont...
|
by: Tom Shelton |
last post by:
This is a simple example of a numeric only text box. It allows only the
entry of integer values. The advantage of this example is that it also
handles user attempts to past non integer text data...
|
by: Supra |
last post by:
' 2004
'An unhandled exception of type 'System.NullReferenceException' occurred
in system.windows.forms.dll
'Additional information: Object reference not set to an instance of an
object.
Option...
|
by: cj |
last post by:
If I want to check to see if it's after "11:36 pm" what would I write?
I'm sure it's easy but I'm getting tired of having to work with dates
and times. Sometimes I just want time or date. And...
|
by: Ironr4ge |
last post by:
Hi everyone,
I am trying to open the form "Languages" with a diffrent record
source
to the "Contacts" form where I conducted the search or filter... .
I was wondering whether there was a vba...
|
by: bob the builder |
last post by:
Can i get the class of an object of which i only have the address?
Lets say i have 3 classes: AClass,BClass,CClass.
i also have an object of each class: aObject, bObject, cObject
And finally i...
|
by: ollyb303 |
last post by:
Hi,
I am trying to create a dynamic crosstab report which will display number of calls handled (I work for a call centre) per day grouped by supervisor.
I have one crosstab query (Query1) which...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |