What's wrong with this code

Z

zerocostproduct

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_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles CalulateBtn.Click
Dim CalulateBtn As Action (Of Textbox3.value * txtInput.value)
End Sub
 
M

Martin H.

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_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles CalulateBtn.Click
TextBox3.Text = (Val(TextBox1.Text) * Val(TextBox2.Text)).ToString
End Sub

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

Best regards,

Martin
 
R

Rory Becker

Hello (e-mail address removed),
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_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles CalulateBtn.Click
Dim CalulateBtn As Action (Of Textbox3.value * txtInput.value)
End Sub

Assuming 3 TextBoxs 'txtInput1', 'txtInput2' and 'txtOutput'....

-------------------------------------------------------------
Private Sub CalulateBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles CalulateBtn.Click
' The following assumes capture of integer values.
txtOutput.Text = cstr(cint(txtInput1.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.
 
K

kimiraikkonen

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_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles CalulateBtn.Click
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_Click_1(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles CalulateBtn.Click

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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top