Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

For/Next with changeable variable.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-12-2009, 05:12 PM
enonod's Avatar
Basic4ppc Veteran
 
Join Date: Oct 2007
Location: U.K.
Posts: 324
Default For/Next with changeable variable.

Is there anything wrong with using variables in For/Next because the code below only does 3 columns, the last next seems to skip? It should do columns 0 and 14 then 1 and 13
Code:
Sub AddSprites
Lft=
0
Rgt=
14
'Add the master frames
    Master.New2(AppPath & "\Psprite.png",6,15,15,6)
'Add remaining sprites, 3 colours
    For i=0 To 1
        
For col=Lft To Rgt Step Rgt
            
For j=0 To 14
                Pawn.New4(Master.FrameBitmaps,
6,15,15,6)
'Binary data for later XOR, zero not usable so start at 1
                Pawn.Data=Bin.ShiftLeft(1,j Mod 3)
                Pawn.X = (col)*
16+1
                Pawn.Y = ((j+(i)*
14Mod 15)*16+1
'Zero frame not usable as binary so -1
                Pawn.CurrentFrame=Pawn.Data-1
                gw.SpriteAdd(Pawn.Value)    
            
Next
        
Next
        Lft=
1
        Rgt=
13
    
Next
End Sub
__________________
You never stop learning until you die.
Sometimes I think I am dead.
Sometimes others think I am dead!
Homesite: http://www.don-simmonds.co.uk for Libyan Mural

Device:Viewsonic VPad7, Android 2.2.2
Reply With Quote
  #2 (permalink)  
Old 07-12-2009, 06:05 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,726
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

You can use variables in the for/next loop.

In the second iteration the 'for' line equals to:
Code:
For col=1 To 13 Step 13
So col will first be 1 and then 14 which is higher than the upper limit.
Reply With Quote
  #3 (permalink)  
Old 07-12-2009, 06:12 PM
enonod's Avatar
Basic4ppc Veteran
 
Join Date: Oct 2007
Location: U.K.
Posts: 324
Default

Thank you Erel, I have been on that for ages.
__________________
You never stop learning until you die.
Sometimes I think I am dead.
Sometimes others think I am dead!
Homesite: http://www.don-simmonds.co.uk for Libyan Mural

Device:Viewsonic VPad7, Android 2.2.2
Reply With Quote
  #4 (permalink)  
Old 07-12-2009, 06:15 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Lft=1
Rgt=13
For col=Lft To Rgt Step Rgt

First pass
col = 1

Second pass
col = 1 + 13 = 14
14 is > Rgt(13) so loop ends

EDIT:- Damn , Erel got in while I was writing a reply
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.

Last edited by agraham : 07-12-2009 at 06:18 PM.
Reply With Quote
  #5 (permalink)  
Old 07-12-2009, 07:15 PM
enonod's Avatar
Basic4ppc Veteran
 
Join Date: Oct 2007
Location: U.K.
Posts: 324
Default

Thank you also agraham. I am a person that suffers from fence post syndrome!
Anyway, there is also another fault having I have spotted in that line, that I wouldn't have seen but for the comments posted. In the first loop I am starting from zero (necessarily) and so what will now become step(rgt-1) still wont allow the column 14 to work but 13 will. Back to the drawing board. [Edit] so the line should read For col=Lft To Rgt Step (rgt-lft)
__________________
You never stop learning until you die.
Sometimes I think I am dead.
Sometimes others think I am dead!
Homesite: http://www.don-simmonds.co.uk for Libyan Mural

Device:Viewsonic VPad7, Android 2.2.2

Last edited by enonod : 07-13-2009 at 05:41 AM.
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 Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
variable address robert black Questions (Windows Mobile) 2 12-24-2008 08:53 PM
Help on getting variable jeterry Questions (Windows Mobile) 2 11-11-2008 10:09 PM
Dim variable c% as Double colin9876 Basic4ppc Wishlist 8 05-28-2008 01:26 PM
LoadCSV from a variable nsidney Questions (Windows Mobile) 7 01-30-2008 01:29 AM
Changeable pen neilnapier Questions (Windows Mobile) 12 11-25-2007 06:56 PM


All times are GMT. The time now is 04:39 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0