473,626 Members | 3,231 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Textbox.text, Input to Integer

I've been reading and looking on the internet - but I just can't fin
this. Perhaps I'm approaching this the wrong way - code-wise

I'm attempting to learn how "things" work in VBNET by creating
small app - 3 textbox objects. I want the user to input data int
textbox1 and textbox2 - and then click on a button - which will tak
the values to textbox1 and textbox2 and multiply them together. Th
result - displays in textbox 3

I think I'm running into problems where I'm attempting to convert th
textbox string (I guess it considers it a string by default) - int
an integer - so that I can take the 2 integers from textbox1 and
and multiply them together. Is the code below wrong? How do I ge
the data that the user inputs into the textbox - into a variable tha
is an integer

dim one as intege
one = val(textbox1.te xt

Does anyone see what I'm trying to do? Can someone show me a cod
sample of what needs to be done. I would think that this would no
be too difficult

Nov 20 '05 #1
38 11124
See Integer.Parse(s tring), or Double.Parse(st ring). All the numeric types
have a Parse method that parses a string and returns a number (if possible).

"Keith" <an*******@disc ussions.microso ft.com> wrote in message
news:7B******** *************** ***********@mic rosoft.com...
I've been reading and looking on the internet - but I just can't find
this. Perhaps I'm approaching this the wrong way - code-wise.

I'm attempting to learn how "things" work in VBNET by creating a
small app - 3 textbox objects. I want the user to input data into
textbox1 and textbox2 - and then click on a button - which will take
the values to textbox1 and textbox2 and multiply them together. The
result - displays in textbox 3.

I think I'm running into problems where I'm attempting to convert the
textbox string (I guess it considers it a string by default) - into
an integer - so that I can take the 2 integers from textbox1 and 2
and multiply them together. Is the code below wrong? How do I get
the data that the user inputs into the textbox - into a variable that
is an integer?

dim one as integer
one = val(textbox1.te xt)

Does anyone see what I'm trying to do? Can someone show me a code
sample of what needs to be done. I would think that this would not
be too difficult.

Nov 20 '05 #2
You could try

dim one as integer = 0
dim two as integer = 0
dim total as integer = 0
try
one = cint(textbox1.t ext)
two = cint(textbox1.t ext)
total = one * two
catch
'error doing calc or converting to int
end try

"Keith" <an*******@disc ussions.microso ft.com> wrote in message
news:7B******** *************** ***********@mic rosoft.com...
I've been reading and looking on the internet - but I just can't find
this. Perhaps I'm approaching this the wrong way - code-wise.

I'm attempting to learn how "things" work in VBNET by creating a
small app - 3 textbox objects. I want the user to input data into
textbox1 and textbox2 - and then click on a button - which will take
the values to textbox1 and textbox2 and multiply them together. The
result - displays in textbox 3.

I think I'm running into problems where I'm attempting to convert the
textbox string (I guess it considers it a string by default) - into
an integer - so that I can take the 2 integers from textbox1 and 2
and multiply them together. Is the code below wrong? How do I get
the data that the user inputs into the textbox - into a variable that
is an integer?

dim one as integer
one = val(textbox1.te xt)

Does anyone see what I'm trying to do? Can someone show me a code
sample of what needs to be done. I would think that this would not
be too difficult.

Nov 20 '05 #3
Hi Keith,

I would do it something like this.
(I am an expert in making typos, so watch for that)

\\\
If IsNumeric(textb ox1.txt) andalso Isnumeric(textb ox2.txt) then
textbox3.txt = Cint(textbox1.t xt) * Cint(textbox2.t xt)
else
messagebox.show ("The values are not numeric")
end if
///

I hope this helps?
Cor
Nov 20 '05 #4
Hi Keith,

Only to help, using a "try catch end try" for this kind of operatins is
not a good way to do.

The try .... cost a lot of time when there is an exception, while the only
error can be that the values are not numeric.

Use those exceptions catching for things you cannot see before (mostly
datahandling ).

Just an adittion, not ment as critique, so keep on helping.

Cor
Nov 20 '05 #5
"Cor Ligthert" <no**********@p lanet.nl> wrote in news:OJzQULmPEH A.1392
@TK2MSFTNGP09.p hx.gbl:
The try .... cost a lot of time when there is an exception, while the only
error can be that the values are not numeric.


Unless you are in a loop the time overhead is insignificant. Getting results
from a user input and even triggering one catch is literally no overhead.

--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programmin g is an art form that fights back"

Get your ASP.NET in gear with IntraWeb!
http://www.atozed.com/IntraWeb/
Nov 20 '05 #6
Hi Kudzu,
The try .... cost a lot of time when there is an exception, while the only error can be that the values are not numeric.
Unless you are in a loop the time overhead is insignificant. Getting

results from a user input and even triggering one catch is literally no overhead.


I do not agree, I said only use catch if there is no better alternative. And
mostly is it, when you make your programs well. Except if there is something
that you have no influence on.

In this sample by instance it will stop the program every time the user
enters an nonnumeric character, while there is a direct test for that.

Cor
Nov 20 '05 #7
"Cor Ligthert" <no**********@p lanet.nl> wrote in
news:OP******** ******@TK2MSFTN GP09.phx.gbl:
> The try .... cost a lot of time when there is an exception, while the
> error can be that the values are not numeric.


Unless you are in a loop the time overhead is insignificant. Getting

results
from a user input and even triggering one catch is literally no
overhead.


I do not agree, I said only use catch if there is no better alternative.


No - you said "The try .... cost a lot of time when there is an exception"
which is the part I replied to.

If there is a non catch way to do it, of course us it. But the statement you
posted regarding performance is too general and there are a lot of learning
developers here. Thats why I clarified it.

I didnt say catch was a better choice in this situation.

--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programmin g is an art form that fights back"

Make your ASP.NET applications run faster
http://www.atozed.com/IntraWeb/
Nov 20 '05 #8
Hi Kudzu,

Same idea and what is a lot of time, I see people here talking about things
which takes thousands of nanoseconds, and this can take parts of seconds
when it goes wrong, therefore.

However I am glad we agree.

Cor
Nov 20 '05 #9
"Cor Ligthert" <no**********@p lanet.nl> wrote in news:#FEgoanPEH A.3708
@TK2MSFTNGP10.p hx.gbl:
Same idea and what is a lot of time, I see people here talking about things
which takes thousands of nanoseconds, and this can take parts of seconds
when it goes wrong, therefore.


It takes milliseconds at most. In a loop yes - but compared against the
drawing of the text in the text box and the user typing, we are talking ants
on the Titanic. ;)
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programmin g is an art form that fights back"

Develop ASP.NET applications easier and in less time:
http://www.atozed.com/IntraWeb/
Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
6842
by: Sonoman | last post by:
hi all: I am trying to write a program using VB6. This program loops (well, not yet) and reads a constant data stream from a serial port. Then it outputs the "formatted" data to a textBox and writes it to a file. Well, I have no Idea how to go about this because I have never used VB. I think I am making some good progress so far but I need some help to keep going. What I currently have pops a small window that has an OK button (which I...
4
20600
by: Alpha | last post by:
Hi, I have a window based applicaton. I want to make sure that the users enter integer numbers before I save it to the database. I know to code this in the textbox_validating event but I don't know what function to call to make sure the input are all integer nubmers. Thanks, Alpha
7
8687
by: DazedAndConfused | last post by:
Curently I manualy code keypress edits. i.e. allow only 3 digits before decimal and two digits after decimal in .NET. Is there an easy solution to mask text boxes? The MSMASK32.OCX from vb6 does not seem to be appropriate for a desktop application with textboxes not bound to a dataset, am I wrong? -- How time fly's when you don't know what you are doing!
0
2605
by: d.steininger | last post by:
Hi there! Is there a way to bind a Textbox.Text to a ScrollBar.Value (not the Textbox-own Scrollbar) and vice versa? The Problem: I have to deal with two controls. The Textbox should accept integers as input, limited by a ScrollBar's Minimum- and Maximum. Changing the ScrollBar-Value should update the Textbox-Text and vice versa. So the textbox-text and scrollbar-value represent the same value. The user is
8
5742
by: nil | last post by:
Hello all, It's urgent... i want to add autocomplete textbox facility in my application like google. as you type it suggests option to the user..i want the same kind of facility...i know i can do only with ajax(xml and javascript) but i want to fetch possible values from database and want to show as the user types in text box.
5
21273
by: YardDancer | last post by:
Hi all I don't want to use the the Cint() or CDec() or other VB.Net Functions and I dont want to restrict keystrokes in the textbox. I am also using the "strict type semantic" settings that requires you to explicitly state all conversions. --
19
107929
Frinavale
by: Frinavale | last post by:
Filtering user input is extremely important for web programming. If input is left unfiltered users can input malicious code that can cripple your website. This article will explain how to make sure that the user only submits a number to your .NET web application and also demonstrate how to add JavaScript to your ASPX pages. Upon popular demand, I have added a section that also covers how to use a validator control to check if a text box...
2
4895
by: =?Utf-8?B?SmVycnkgSg==?= | last post by:
Hello, I am using asp.net 2003 using C#. I am creating textboxes dynamically and want to validate to make sure the user can only input an integer. I don't think I can use the validators because I don't know what the ID of the textbox is ahead of time. I am trying to do it with javascript with a tableCell.Attributes.Add. I'm not sure I can do what I am trying.
1
2450
by: rakeshnair | last post by:
i wrote a code in jsp to create dynamic table..the problem is i need data base connection when cursor moves from one cell to other... eg...when i enter product id in the first cell, the product name and its rate should come in the next two cells...it should take from the data base... it's my code........ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" > <%@ page import="java.sql.*"...
0
8269
marktang
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8203
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8711
Oralloy
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8642
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8368
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
7203
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4094
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1515
bsmnconsultancy
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.