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

Converting String to Integer

P: 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
Share this Question
Share on Google+
6 Replies


iam_clint
Expert 100+
P: 1,208
integer.parse or integer.tryparse would work.
Oct 12 '14 #2

P: 33
i already use them but no luck sir
Oct 12 '14 #3

iam_clint
Expert 100+
P: 1,208
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

P: 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
Expert 100+
P: 1,208
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

P: 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

Post your reply

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