I've been searching a lot, but couldn't find anything about what I would imagine to be pretty easy.

I'm trying to get a number out of a List, that is getting information out of an Excel file. But I don't think that matters.
I then want to give it a percentage, but it doesn't want to see the list as a value.

So I figured I would put the List Value into a Text Value, to then calculate it.

Private Sub cmdBereken_Click()

Text1.AddItem (lstPrijs.Text)

prijs = Val(Text1.Text)
percent = 1 + Val(Text2.Text) / 100

eind = prijs * percent

Text3.Text = eind

Text2 = ""

End Sub

Can anyone help me with this?

Thanks in advance,

Q~

Recommended Answers

All 2 Replies

I've been searching a lot, but couldn't find anything about what I would imagine to be pretty easy.

Private Sub List1_Click()
   Dim strListValue As String, sngPercentage As Single
   strListValue = List1.List(List1.ListIndex)
   ' Check for numeric value to avoid run time error
   If IsNumeric(strListValue) Then
      Text1 = Format(CDec(strListValue) * sngPercentage, "currency")
   End If
End Sub

Thanks, that solved it.
I used it differently though:

Private Sub lstPrijs_Click()

   Dim strListValue As String
   strListValue = lstPrijs.List(lstPrijs.ListIndex)

   If IsNumeric(strListValue) Then
      Text1 = strListValue
   End If

End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.