  Dim-ing variables

Discussion in 'Questions (Windows Mobile)' started by colin9876, Nov 17, 2007.

1. I wanted to draw a moving polygon
to store the 5 coordinates I did
dim x(5)
dim y(5)
Q1) rather than saying x(0)=0 x(1)=100 x(2)=120 x(3)=140 etc....
is there a quick way assigning the array such as> x()=[0,100,120,140,80]

Q2) The polygon command errored - what is wrong with
form1.polygon(x(),0,y(),0,5,cBlue)
which should be the right format to say x() starting at 0, y() starting at 0,count 5, in colour Blue)

2. A1) Currently not. Maybe it will be implemented in the next version.
A2) What error do you get? Can you post all or part of your code?

3. ok with a triangle
dim x(3)
dim y(3)
x(0)=0 y(0)=0 x(1)=0 y(1)=100 x(2)=200 y(2)=100
form1.polygon(x(),0,y(),0,3,cRed)
Error description: ArgumentNullException

Last edited: Nov 17, 2007
4. Works fine here (don't forget to create a form named Form1).
Code:
Sub Globals

'Declare the global variables here.
Dim x(3),y(3)
End Sub

Sub App_Start
x(
0)=0 :y(0)=0 :x(1)=0: y(1)=100: x(2)=200: y(2)=100
form1.polygon(x(),
0,y(),0,3,cRed)
Form1.Show
End Sub
I prefer to use a structure:
Code:
Sub Globals

'Declare the global variables here.
Dim Type(x,y) points(3)
End Sub

Sub App_Start
points(
0).x = 0
points(
0).y = 0
points(
1).x = 0
points(
1).y = 100
points(
2).x = 200
points(
2).y = 100
form1.polygon(points(),
0,3,cBlue)
Form1.Show
End Sub

5. Silly me,
I had set the values of x(0) etc in the Sub Globals and not the App_start, I thought you could define the values of variables in either! Ive seen it done before like in clock prog
Sub Global
mytime=0
End Sub

Is it different for array values? Anyway it works now - Thanks

Last edited: Nov 17, 2007
6. Yes, arrays must be declared (in Sub Globals).
You can later change their size with another dim statement.

7. You should be able to! This works for me.

Code:
Sub Globals

'Declare the global variables here.
Dim array(3)

array(0) = 1

array(1) = 2

array(2) = array(0) + array(1)
End Sub

Sub App_Start

Msgbox(array(2)) ' displays 3
End Sub

8. Sorry guys, mystery solved ... but how weird is this

At first I had these (faulty) lines in the Sub global -
x(0)=0 y(0)=0 .....
x(1)=0 y(1)=100

But the error reported at the polygon statement

When I moved them to the App sub
The error reported at the first
x(0)=0 y(0)=0
now I realise there should have been a : between them when setting two variables on the same line.

But for some reason the error message came at a different point when my coding error was in the different Subs!

i.e. the x(0)=0 y(0)=0 didnt error immediately when its in the Global sub but it did in the App sub

Totally my mistake, but thrown by the differnt error reporting???

Last edited: Nov 17, 2007
9. Sub Globals is a special Sub, which should be used for global variables declaration.
The compiler treats this sub a little bit differently.