Multiplay text box entry with predifined number

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Alkis Arxontas
    New Member
    • Mar 2011
    • 10

    Multiplay text box entry with predifined number

    Hello :)
    I have started using Visual Basic Express 2008 today, but I kind of feel I am not getting even the basics running..
    I'd like to do the following:
    I have a textbox and a button which I would like to use as the submit button. I'd just like to be able to add a value in the text box and by clicking on the calculate button it should show me the result of a multiplication by 0,5
    If someone could help me with this and how to make that work, i'd much appreciate it!
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Why not read some books to learn the basics of the language.

    Comment

    • Guido Geurs
      Recognized Expert Contributor
      • Oct 2009
      • 767

      #3
      Private Sub Command1_Click( )
      Text1.Text = Val(Text1.Text) * 0.5
      End Sub

      Comment

      • Alkis Arxontas
        New Member
        • Mar 2011
        • 10

        #4
        Thanks for your answer! :)
        I actually searched and figured out

        Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click

        If TextBox1.Text = "" Then
        MessageBox.Show ("Please insert a value.", "Error!", MessageBoxButto ns.OK, MessageBoxIcon. Exclamation)
        Else
        Dim a As String
        a = TextBox1.Text
        Label2.Text = Math.Round(a * 0.5)
        End If
        End Sub

        How can I add Mathround to
        Text1.Text = Val(Text1.Text) * 0.5
        because your code seems to be better and cleaner than mine?

        Comment

        • Guido Geurs
          Recognized Expert Contributor
          • Oct 2009
          • 767

          #5
          Code:
          If TextBox1.Text = "" Then
             MessageBox.Show("Please insert a value.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
          Else
             Label2.Text = Math.Round(Val(TextBox1.Text) * 0.5)
          End If

          Comment

          • Alkis Arxontas
            New Member
            • Mar 2011
            • 10

            #6
            Perfect! Thanks a lot! :)

            Comment

            Working...