Crescend0
Crescend0

Reputation: 13

Visual Basic - Array

Say I have a list of variables like so, ranging from x0 to x1:

x0 = 0.0
x1 = 1.0
x2 = 3
x3 = 9
x4 = 18
x5 = 20
x6 = 30

There is a function within a software package I'm writing the code for which selects a point on a given co-ordinate (the actual function doesnt really matter).

call view.selectCircle(x, y, z, "Set", "Point")

What I want to do is write a loop function which runs this function for all my values of x0-x1. I've tried this but have failed to get it to work...

For i = 1 To 6

call view.selectCircle("x" & i, 0.0, 0.5, "Set", "Point")

Next 

Sorry if this is an extremely basic question as I'm pretty new to programming!

Thanks for any help.

Upvotes: 0

Views: 58

Answers (1)

SierraOscar
SierraOscar

Reputation: 17637

You don't currently have an array, you have 7 separate variables. If you want an array you have two options:

x = Array(0.0, 1.0, 3, 9, 18, 20, 30)

For Each point In x
    Call view.selectCircle(point, 0.0, 0.5, "Set", "Point")
Next

Dim x(0 To 6) As Double

x(0) = 0.0
x(1) = 1.0
x(2) = 3
x(3) = 9
x(4) = 18
x(5) = 20
x(6) = 30

For i = LBound(x) To UBound(x)
    call view.selectCircle(x(i), 0.0, 0.5, "Set", "Point")
Next

Note that the different types of loop aren't relevant to the type of array, I've just used two examples to give you an option - they are interchangeable as far as these solutions are concerned.

Upvotes: 1

Related Questions