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.

Error when using an array of types

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-27-2007, 07:21 PM
Newbie
 
Join Date: Oct 2007
Posts: 1
Unhappy Error when using an array of types

Hi,

could someone help me with this :

I'm using a array of type :
Sub Globals
Dim Type(Dep, Arr, Fic1, Fic2, Tra) Depart (1)

Then, in a procedure, I'm reading the size of the array :
NbDepart = FileRead (c1)

I'm sizing the array :
Dim Depart (NbDepart)

But then I've got an error when trying :
Depart(0).Dep = 1

---
I've tried to put a fixed size on the array of type and it works.
I've tried to add 1 to NbDepart, to be sure it's concerted to an integer but it does not work.

Any idea ? Is this a bug ?
Reply With Quote
  #2 (permalink)  
Old 10-27-2007, 07:47 PM
taximania's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Derbyshire. UK
Posts: 585
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Once you've declared a Global variable, you can't change its size
__________________
.
.
.
Don't ask, I'm fine, honest. !!
.
.
.
Just a little crazy at times



O2 XDA, GW Evo 2.1 UC WWE Rom, WM6.1
Radio Ver 03.34.90
With Basic4ppc V6.80


http://www.taximania.co.uk
Reply With Quote
  #3 (permalink)  
Old 10-27-2007, 07:53 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 13,162
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

One dimension array-structures are actually two dimension arrays where the second rank value equals to the number of fields.
You must use the array syntax to resize the structure:
Code:
Sub Globals
    
Dim Type(Dep, Arr, Fic1, Fic2, Tra) Depart (0)
End Sub

Sub App_Start
    
Dim Depart(NbDepart,5)
    Depart(
0).dep = 13331
    Depart(
1).Tra = 321
End Sub
Quote:
Once you've declared a Global variable, you can't change its size
You can resize an array any number of times during a program (resizing an array will clear all its records).
Reply With Quote
  #4 (permalink)  
Old 10-27-2007, 07:54 PM
Cableguy's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: N 41º11'30.30" W 8º39'46.60"
Posts: 2,313
Awards Showcase
Forum Contributer 
Total Awards: 1
Default

Quote:
Originally Posted by taximania View Post
Once you've declared a Global variable, you can't change its size
Not true...
I have used globals before, and have their initial value (set in the globals sub) altered in other subs....

I'm thinking more of a file related error...

Code:
NbDepart = FileRead (c1)
Have you open the file for reading?
Are you sure you aren't getting an empty string?

EDIT: Erel beat me to the clock and as always he knows best...
__________________
Paulo Gomes - Porto, Portugal - Living/Working in France-Saumur
Mobile Device: Samsung Galaxy S, Android 2.3.4 CUstom ROM
Laptop: Toshiba NB100-130 (running on Win7Ultimate)
B4PPC DLL Version Listing - B4Android DLL Version Listing

Last edited by Cableguy : 10-27-2007 at 07:57 PM.
Reply With Quote
  #5 (permalink)  
Old 10-27-2007, 08:29 PM
taximania's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Derbyshire. UK
Posts: 585
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Originally Posted by taximania View Post
Once you've declared a Global variable, you can't change its size
I meant a Global Array.
I stand corrected

But: I'm even more confused now

Code:
Dim Depart(NbDepart,5)
    Depart(
0).dep = 13331
Doesn't that make an Array of NbDepart(5)

So shouldn't it be NbDepart(0).dep = 13331 etc
__________________
.
.
.
Don't ask, I'm fine, honest. !!
.
.
.
Just a little crazy at times



O2 XDA, GW Evo 2.1 UC WWE Rom, WM6.1
Radio Ver 03.34.90
With Basic4ppc V6.80


http://www.taximania.co.uk
Reply With Quote
  #6 (permalink)  
Old 10-27-2007, 09:19 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 13,162
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

NbDepart is an integer. We like to resize Depart which is an array of structures.
As I wrote, an array of structures is actually a two dimensions array.
So:
Depart(0).Fic1 = 3 equals to Depart(0,2) = 3
And when we need to resize Depart we write:
Dim Depart(100,5) or Dim Depart(NbDepart,5) where 5 is the number of fields.
Reply With Quote
  #7 (permalink)  
Old 02-26-2011, 04:56 AM
Newbie
 
Join Date: Feb 2011
Location: Mumbai, India
Posts: 7
Send a message via Skype™ to thecrowkaka
Default

I want to resize an array declared in global and yet be able to retain the data in the array. i.e. if I have an array a(5) and there is data in all the five elements. Now I want to make the array a(10), I need to have the data in the first five elements as it is and the next 5 elements would be clear. In vb6 we get this by using "Preserve" with Redim.

Please let me know if this is possible in B4PPC. Moreover, if not possible what could be the workaround to get this done?
Reply With Quote
  #8 (permalink)  
Old 02-26-2011, 07:26 AM
taximania's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Derbyshire. UK
Posts: 585
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Copy the data into a temp array, resize the original one, copy the data back ?
__________________
.
.
.
Don't ask, I'm fine, honest. !!
.
.
.
Just a little crazy at times



O2 XDA, GW Evo 2.1 UC WWE Rom, WM6.1
Radio Ver 03.34.90
With Basic4ppc V6.80


http://www.taximania.co.uk
Reply With Quote
  #9 (permalink)  
Old 02-26-2011, 08:41 AM
Basic4ppc Expert
 
Join Date: May 2008
Location: Berkshire, UK
Posts: 762
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Originally Posted by taximania View Post
Copy the data into a temp array, resize the original one, copy the data back ?
That's what I've been doing, where I thought that using a collection instead would be too much like hard work...

Mike.
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
Different Line Types ceaser Code Samples & Tips 4 08-20-2008 02:39 PM
Nullifying an Array mjcoon Questions (Windows Mobile) 1 06-20-2008 06:20 PM
Array but not array Cableguy Questions (Windows Mobile) 1 09-22-2007 09:09 PM
Array of Array possibility? Stellaferox Basic4ppc Wishlist 0 09-18-2007 01:16 PM
Undeclared array error with version 5 mwaite Questions (Windows Mobile) 6 05-19-2007 11:39 AM


All times are GMT. The time now is 03:56 AM.


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