Question Locked

Visual Basic 2005 Listbox Question...

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
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?

3 replies

by jiminpa

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

by whitney_willis4

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
Do
' 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

This discussion is closed to new replies.