473,405 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Converting String to Integer

33
Hi everyone could you help me fix my code?

I tried to use convert.toint32 and integer.parse but no luck.

Here's my code:
Expand|Select|Wrap|Line Numbers
  1.    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.         'Label1.Text = TextBox1.Text * TextBox2.Text
  3.  
  4.         Dim int1 As Integer
  5.         int1 = System.Convert.ToInt32(TextBox1.Text)
  6.         Dim int2 As Integer
  7.         int2 = System.Convert.ToInt32(TextBox2.Text)
  8.         Label1.Text = int1 * int2
  9.  
  10.  
  11.     End Sub
Oct 12 '14 #1
6 1734
iam_clint
1,208 Expert 1GB
integer.parse or integer.tryparse would work.
Oct 12 '14 #2
Denden
33
i already use them but no luck sir
Oct 12 '14 #3
iam_clint
1,208 Expert 1GB
What kind of number is in the fields? This works just fine in a project I just created.
Expand|Select|Wrap|Line Numbers
  1.         Dim int1 As Integer = 0
  2.         Dim int2 As Integer = 0
  3.         Integer.TryParse(TextBox1.Text, int1)
  4.         Integer.TryParse(TextBox2.Text, int2)
  5.         Label1.Text = int1 * int2
  6.  
Oct 12 '14 #4
Denden
33
i am trying to perform a multiplication. ive got two textboxes and one label. i put my code on the load event handler that when someone opens up that form and they will enter numbers, those numbers will be multiply upon typing
Oct 12 '14 #5
iam_clint
1,208 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.  
  3.     End Sub
  4.     Private Sub doMath()
  5.         Dim int1 As Integer = 0
  6.         Dim int2 As Integer = 0
  7.         Integer.TryParse(TextBox1.Text, int1)
  8.         Integer.TryParse(TextBox2.Text, int2)
  9.         Label1.Text = int1 * int2
  10.     End Sub
  11.     Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
  12.         doMath()
  13.     End Sub
  14.  
  15.     Private Sub TextBox2_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyUp
  16.         doMath()
  17.     End Sub
  18.  
Oct 12 '14 #6
Denden
33
WOW. this is my first time using the keyup event. i am thinking that i do it inside the form load, i was wrong .. thank you sir.
Oct 12 '14 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Peter Warder | last post by:
I'm a newbie and I'm sorry this is so basic but . . . . If I have a String containing "123", how do I convert it to an Integer variable? I've tried all kinds of Integer.valueOf("123")...
2
by: Ken Fettig | last post by:
I have a quick simple question. How do you convert an integer to a string in Python? Thanks Ken Fettig
13
by: Gil | last post by:
I have a string : string A = "2"; I need to get it's integer value : // ?? int val = A ; // ??
4
by: rainmaker1234 | last post by:
Its very simple in VC++. In the followeing code I have declared a String, and a double than I am taking the string and converting it into Double. getch() at the end is only to pause the screen so...
0
by: wrytat | last post by:
In one web page, I redirect it to "prtDelReq.aspx?prtindex=0A2A3A8" after the user click the button. The prtindex actually contains many integers separated by 'A'. On the prtDelReq page, I use...
3
by: SiewSa | last post by:
I have come to a situation that I need to use the result of a string variable as a formula for performing calculation. As an example below: Dim X As Integer Dim Y As Integer Dim Result...
1
by: mdawoodk | last post by:
i am getting error "input string was not in correct format" when converting a string decimal into integer value. code is like this: string strVal = ""; int nVal = 0; strVal = "14.9"; nVal...
9
by: priyanka | last post by:
Hi there, I want to convert a String into integer. I get the string froma file using : string argNum; getline(inputStream,argNum); I now need to convert argNum into integer.
1
by: sake | last post by:
This problem seems to have a fairly simple solution in C, and google seems to love to pull up solutions for C. However, C++ just seems have the exact opposite luck. So pretty much, I want to...
7
by: tragic54 | last post by:
Alright so i've done this in some of my recent programs with option strict on and for some reason When i debug and select the option from the combo box, it crashes and gives me a 'Input String was...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
tracyyun
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...
0
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,...
0
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...

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.