4 Replies - 503 Views - Last Post: 30 January 2014 - 04:13 PM Rate Topic: -----

#1 Nigels  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 17-May 13

multiply a textbox value by whatever number

Posted 19 January 2014 - 04:43 AM

Hi I have created 2 TextBox's and a button on my form. I want it so that when I type in a number in the first Textbox and hit the button. What ever number has been placed in the TextBox will be multiplied by 9.
I thought I could simply do this.

If TextBox1.Text = "" Then
            TextBox2.Text = Val(TextBox1.Text) * "9"
        End If


Now all I did was put that code in to the button, but it does not work. Also I have read that I should not be using "Val" as it is soon not to be supported?
Can someone please put me right.
Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: multiply a textbox value by whatever number

#2 Nigels  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 17-May 13

Re: multiply a textbox value by whatever number

Posted 19 January 2014 - 05:29 AM

Hi, What I did was change the = to a <>
problem solved

Thanks
PS I still don't know if I am supposed to be using "Val"
Was This Post Helpful? 0
  • +
  • -

#3 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 154
  • View blog
  • Posts: 570
  • Joined: 01-February 13

Re: multiply a textbox value by whatever number

Posted 19 January 2014 - 08:13 AM

Hi,
I see you have it working for you but, i would strongly recommend that you turn on Option Strict. That will help you with good coding practices. You can turn it on in the IDE`s Options or you can place this line as the very first line of code in your program.
Option Strict On


What i mean by that is you are trying to multiply a number value by a String "9". If you take the quotes off from that then it would be a number value, not a string.

Also i would recommend using the TryParse method to get the value of the String in the textbox to be sure that the user entered an actual number. Suppose the user enters "A" in the textbox? The TryParse method would catch that error for you. For example
        Dim number As Integer = 0
        If Integer.TryParse(TextBox1.Text, number) Then
            'The user entered a valid integer number so do something with (number) here

        Else
            MessageBox.Show("User entered an invalid Integer number")
        End If


Was This Post Helpful? 1
  • +
  • -

#4 Nigels  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 17-May 13

Re: multiply a textbox value by whatever number

Posted 30 January 2014 - 03:35 PM

Hi IronRazor,
I have just put your example in to place.
Thanks Nige
Was This Post Helpful? 0
  • +
  • -

#5 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 154
  • View blog
  • Posts: 570
  • Joined: 01-February 13

Re: multiply a textbox value by whatever number

Posted 30 January 2014 - 04:13 PM

Your Welcome. I am glad it helped. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1