Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


Dim-ing variables


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-17-2007, 10:44 AM
Basic4ppc Veteran
 
Join Date: Nov 2007
Posts: 316
Awards Showcase
Beta Tester 
Total Awards: 1
Default Dim-ing variables

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)
But it didnt work, please help?
Reply With Quote
  #2 (permalink)  
Old 11-17-2007, 11:09 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,199
Default

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?
Reply With Quote
  #3 (permalink)  
Old 11-17-2007, 11:23 AM
Basic4ppc Veteran
 
Join Date: Nov 2007
Posts: 316
Awards Showcase
Beta Tester 
Total Awards: 1
Default

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 by colin9876 : 11-17-2007 at 11:37 AM.
Reply With Quote
  #4 (permalink)  
Old 11-17-2007, 11:56 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,199
Default

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
Reply With Quote
  #5 (permalink)  
Old 11-17-2007, 12:37 PM
Basic4ppc Veteran
 
Join Date: Nov 2007
Posts: 316
Awards Showcase
Beta Tester 
Total Awards: 1
Default

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 by colin9876 : 11-17-2007 at 12:40 PM.
Reply With Quote
  #6 (permalink)  
Old 11-17-2007, 01:55 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,199
Default

Yes, arrays must be declared (in Sub Globals).
You can later change their size with another dim statement.
Reply With Quote
  #7 (permalink)  
Old 11-17-2007, 02:12 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,770
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Quote:
Originally Posted by colin9876 View Post
I thought you could define the values of variables in either!
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
Reply With Quote
  #8 (permalink)  
Old 11-17-2007, 05:38 PM
Basic4ppc Veteran
 
Join Date: Nov 2007
Posts: 316
Awards Showcase
Beta Tester 
Total Awards: 1
Default

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 by colin9876 : 11-17-2007 at 06:00 PM.
Reply With Quote
  #9 (permalink)  
Old 11-17-2007, 06:47 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,199
Default

Sub Globals is a special Sub, which should be used for global variables declaration.
The compiler treats this sub a little bit differently.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
program variables tremara1 Questions & Help Needed 2 10-16-2008 08:52 AM
Environment Variables Zenerdiode Questions & Help Needed 1 05-22-2008 04:36 PM
automatic typecasting of variables? Stellaferox Questions & Help Needed 4 02-04-2008 01:17 PM
Help about variables/objects skipper Questions & Help Needed 6 12-19-2007 04:45 PM
Structure variables Erel Code Samples & Tips 0 05-19-2007 11:36 AM


All times are GMT. The time now is 10:18 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0