Visual Basic 2005 Listbox Question...

By whitney_willis4 ·
I am in the process of creating a program with which to use as an inventory program and am using listboxes in order to enter the numbers. I am attempting to set it up with a function to multiply two numbers within the same listbox, and each time I try, I always make it so it just multiplies the first number by itself. How do I get two seperate numbers which I have entered into the listbox to multiply against eachother?

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -

Can you post the code you're trying to use?

by jimmy-jam In reply to Visual Basic 2005 Listbox ...

It may be a little easier to help you that way.

Collapse -

Here we go...

by whitney_willis4 In reply to Can you post the code you ...

Private Sub multiplyButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles multiplyButton.Click

' initialization phase
Dim result As Integer = 0
Dim operandCounter As Integer = 0
Dim operand1 As Integer = 0
Dim operand2 As Integer = 0

' multiply operands from ListBox
' read operands from ListBox
operand1 = OperandsListBox.Items.Item(operandCounter)
operand2 = OperandsListBox.Items.Item(operandCounter)
result = (operand1 * operand2) ' multiply operands by eachother
operandCounter *= 2 ' increment counter
Loop While operandCounter >= 2

resultLabel.Text = String.Format("{0:G}", result)
multiplyButton.Enabled = True ' Enable Multiply Button
inputTextBox.Focus() 'reset focus to Enter operand: Textbox

End Sub ' multiplyButton_Click

Related Discussions

Related Forums