What's wrong with this code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • zerocostproduct@gmail.com

    What's wrong with this code

    All,
    Been a long time since I messed with VB my brother-in-law is taking a
    intro programming class
    he wrote the following code but he's getting an error at the
    calculation line.
    I no longer have VB and looking with my rusty eyes this code didn't
    look like VB. After posting in a Visual basics group I was told it's
    VB.net.

    He's trying to capture seperate values from 2 different txtbox and
    display results of calculation in a third txtbox/


    Can anyone help?


    Private Sub CalulateBtn_Cli ck(ByVal sender As System.Object, ByVal e
    As System.EventArg s) Handles CalulateBtn.Cli ck
    Dim CalulateBtn As Action (Of Textbox3.value * txtInput.value)
    End Sub


  • Martin H.

    #2
    Re: What's wrong with this code

    Hello zerocostproduct ,

    It's not about your rusty eyes, it's about writing something without
    having any idea...

    If he wants to calculate with values from textboxes then it should be
    (very close to traditional VB) like this:

    Private Sub CalulateBtn_Cli ck(ByVal sender As System.Object, ByVal e As
    System.EventArg s) Handles CalulateBtn.Cli ck
    TextBox3.Text = (Val(TextBox1.T ext) * Val(TextBox2.Te xt)).ToString
    End Sub

    Assuming that the 3 textboxes are named TextBox1, TextBox2 and TextBox3.

    Best regards,

    Martin

    On 15.07.2008 22:21, wrote zerocostproduct @gmail.com:
    All,
    Been a long time since I messed with VB my brother-in-law is taking a
    intro programming class
    he wrote the following code but he's getting an error at the
    calculation line.
    I no longer have VB and looking with my rusty eyes this code didn't
    look like VB. After posting in a Visual basics group I was told it's
    VB.net.
    >
    He's trying to capture seperate values from 2 different txtbox and
    display results of calculation in a third txtbox/
    >
    >
    Can anyone help?
    >
    >
    Private Sub CalulateBtn_Cli ck(ByVal sender As System.Object, ByVal e
    As System.EventArg s) Handles CalulateBtn.Cli ck
    Dim CalulateBtn As Action (Of Textbox3.value * txtInput.value)
    End Sub
    >
    >

    Comment

    • Rory Becker

      #3
      Re: What's wrong with this code

      Hello zerocostproduct @gmail.com,
      He's trying to capture seperate values from 2 different txtbox and
      display results of calculation in a third txtbox/
      >
      Can anyone help?
      >
      Private Sub CalulateBtn_Cli ck(ByVal sender As System.Object, ByVal e
      As System.EventArg s) Handles CalulateBtn.Cli ck
      Dim CalulateBtn As Action (Of Textbox3.value * txtInput.value)
      End Sub
      Assuming 3 TextBoxs 'txtInput1', 'txtInput2' and 'txtOutput'....

      -------------------------------------------------------------
      Private Sub CalulateBtn_Cli ck(ByVal sender As System.Object, ByVal e As System.EventArg s)
      Handles CalulateBtn.Cli ck
      ' The following assumes capture of integer values.
      txtOutput.Text = cstr(cint(txtIn put1.Text) * cint(txtInput2. Text))
      End Sub
      -------------------------------------------------------------

      If your brother in law is learning now, please help him by suggesting the
      following code for the top of all his files until he can discover a reason
      not to. It should help him discover some errors earlier in any given development
      cycle.
      -------------------------------------------------------------
      Option Strict On
      -------------------------------------------------------------


      --
      Rory


      Comment

      • kimiraikkonen

        #4
        Re: What's wrong with this code

        On Jul 15, 5:21 pm, zerocostprod... @gmail.com wrote:
        All,
        Been a long time since I messed with VB my brother-in-law is taking a
        intro programming class
        he wrote the following code but he's getting an error at the
        calculation line.
        I no longer have VB and looking with my rusty eyes this code didn't
        look like VB. After posting in a Visual basics group I was told it's
        VB.net.
        >
        He's trying to capture seperate values from 2 different txtbox and
        display results of calculation in a third txtbox/
        >
        Can anyone help?
        >
        Private Sub CalulateBtn_Cli ck(ByVal sender As System.Object, ByVal e
        As System.EventArg s) Handles CalulateBtn.Cli ck
        Dim CalulateBtn As Action (Of Textbox3.value * txtInput.value)
        End Sub

        Hi,
        As stated by you, it can be sampled with 3 textboxes named "TextBox1",
        "TextBox2" for user input and "txtResult" for displaying result:

        /////////////////
        ' Assuming you're doing an multiplication calculation:

        Private Sub CalulateBtn_Cli ck_1(ByVal sender As System.Object, ByVal e
        As System.EventArg s) Handles CalulateBtn.Cli ck

        txtResult.Text = CInt(TextBox1.T ext) * CInt(TextBox2.T ext)

        End Sub
        \\\\\\\\\\\\\\\ \\

        Note that, you're converting textbox's strings to integers explictly
        using "CInt" to do the arithmetic calculation and to "avoid" string
        concentration.

        Hope this helps,

        Onur Güzel



        Comment

        Working...