Repetition

C

Carlo

I need to take the values stored in the variables o1 to o7 and
multiply them by 0.90 and print the result in a list box. What is the
problem with the coding below to perform this operation:


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim o1, o2, o3, o4, o5, o6, o7, sale As Double
Dim n As Integer
o1 = 39
o2 = 21
o3 = 7.75
o4 = 33
o5 = 6.75
o6 = 24
o7 = 26
For n = 1 To 7
sale = CDbl(("o" & n) * 0.9)
lstOutput.Items.Add(CDbl(sale))
Next


Thanks
Carlo
 
J

Jeremy Todd

Carlo said:
I need to take the values stored in the variables o1 to o7 and
multiply them by 0.90 and print the result in a list box. What is the
problem with the coding below to perform this operation:
sale = CDbl(("o" & n) * 0.9)

That line is the problem.What it's doing is trying to multiply
the -string- "o1" by 0.9, which throws an exception because you can't
multiply a string and a numeric value. You should use an array instead:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim o(6) As Double
Dim sale As Double
Dim n As Integer
o(0) = 39
o(1) = 21
o(2) = 7.75
o(3) = 33
o(4) = 6.75
o(5) = 24
o(6) = 26
For n = 0 To 6
sale = o(n) 0.9
lstOutput.Items.Add(sale)
Next
End Sub

Jeremy
 
C

Cor

Hi Carlo,

To give a more theoraticly answer

o1 is a human readable replacement of a virtual memory adress, which is set
by the compiler to a real virtual memory adres.

When you use o&1 you are doing that in runtime, the virtual adres o and the
value one.

If you use the adres o(1) as Jeremy told you, you says the virtual adres
which start on o incremented with the positions of the lenght of the virtual
objectadres or valuelength as told to use for this.

I hope this helps?

Cor
 

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