Link to home
Start Free TrialLog in
Avatar of dejandejanovic
dejandejanovic

asked on

Trying to SUM listbox items, but getting "Conversion from type 'ListItem' to type 'String' is not valid". Need someone to check code.

Hello,
can someone please advise what I'm doing wrong. I have try many solutions, but just cannot get out from error like:
"Conversion from type 'ListItem' to type 'String' is not valid", or
Conversion from type 'ListItem' to type 'Double' is not valid, or
Conversion from type 'ListItem' to type 'Integer' is not valid, etc

Dim result As Double = Math.Round((TextBoxA.Text + TextBoxB.Text, 1)
        MsgBox(result)
        Dim Pcs As String = result * TextBoxC.Text
        MsgBox(Pcs)
        ListBox1.Items.Add(Pcs)
        Dim sum As Double
        For Each item As String In ListBox1.Items
            sum += Double.Parse(item)
        Next

Open in new window


Thanks in advance for hlep!
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Dim result As Double = Math.Round((TextBoxA.Text + TextBoxB.Text, 1)
        MsgBox(result)
        Dim Pcs As String = result * TextBoxC.Text
        MsgBox(Pcs)
        ListBox1.Items.Add(Pcs)
        Dim sum As Double
        For Each item As Object In ListBox1.Items
            sum += Double.TryParse(item.ToString())
        Next

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dejandejanovic
dejandejanovic

ASKER

Works perfect! Thanks.