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(B yVal sender As System.Object, ByVal e As
System.EventArg s) 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 2140
"Maarten" <gu******@hotma il.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(B yVal sender As System.Object, ByVal e As System.EventArg s) 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******** ******@TK2MSFTN GP14.phx.gbl... "Maarten" <gu******@hotma il.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(B yVal sender As System.Object, ByVal e As System.EventArg s) 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******@hotma il.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******** ******@TK2MSFTN GP14.phx.gbl... "Maarten" <gu******@hotma il.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(B yVal sender As System.Object, ByVal e As System.EventArg s) 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******** ******@tk2msftn gp13.phx.gbl... I should, what value did you enter? Post your new code?
Chris
"Maarten" <gu******@hotma il.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******** ******@TK2MSFTN GP14.phx.gbl... "Maarten" <gu******@hotma il.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(B yVal sender As System.Object, ByVal e As System.EventArg s) 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******** *************@z 14g2000cwz.goog legroups.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.Reg ularExpressions .Regex("^\d*$")
If rNumber.IsMatch (s) Then
msgbox("ok")
Else
msgbox("not a whole number")
End If
HTH,
Greg
"Maarten" <gu******@hotma il.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(B yVal sender As System.Object, ByVal e As System.EventArg s) 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
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******@hotma il.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******** ******@tk2msftn gp13.phx.gbl...I should, what value did you enter? Post your new code?
Chris
"Maarten" <gu******@hotma il.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******** ******@TK2MSFTN GP14.phx.gbl... "Maarten" <gu******@hotma il.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(B yVal sender As System.Object, ByVal e As > System.EventArg s) 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/>
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 long.
I am writing a program in Visual C++ 6 SP5.
My code has a lot of "if" statements - 19 to be exact.
If the if statements are true (technically,...
|
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 references to this integer type ? When was it
introduced ?
Thank you
|
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 want to send page,and i dont want the server will
load page to send only 1 integer back.
so,what is the first method in server, i can implement, to...
|
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 into the text box...
Option Strict On
Option Explicit On
Imports System
Imports System.Windows.Forms
Imports System.ComponentModel
|
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 Explicit On
Option Strict Off
Imports System
Imports System.Text
| |
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 to be able to do
comparisons on them.
|
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 code to select
ONLY ALL FILTERED records of my first form or the "Contacts"
and open this filtered set of records in my "Languages" form. I have a...
|
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 have an integer: integerX.
Now i let let intergerX be the address of one of the objects (aObject,
bObject or cObject) but i dont know which.
Can...
|
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 has the following fields:
SPID (supervisor ID), total:group by, as row heading
Date, total:group by, as column heading
Calls handled, total:sum,...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |