Erase a static array [Resolved]

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kcc
New User
New User
Posts: 3
Joined: Tue Sep 15, 2009 10:17 am

Erase a static array [Resolved]

Post by Kcc »

Hello at all

How can i do for erase a static array and have only five result at the second time ???

For example :

Code: Select all

A
E
R
T
U
""
""
""
""
""
The code

Code: Select all

Procedure ChargeTablo(Number)
 
 Static Dim ArrayLetter.s(100)
 
 For i = 1 To Number
 
  Repeat
   Ascii = Random(90)
  Until Ascii > 64
  
  ArrayLetter(i) = Chr(Ascii)
  
 Next 
 
 ArrayLetter(0) = "Stop"
 ProcedureReturn @ArrayLetter()
 
EndProcedure

Dim ArrayKcc.s(0)
ChargeTablo(10)
ArrayKcc() = ChargeTablo(5)

For i = 0 To 10
 Debug ArrayKcc(i)
Next 
Thanks for your help 8)
Last edited by Kcc on Wed Sep 16, 2009 2:07 pm, edited 1 time in total.
The happiness is a road, not a destination.
I'm the personaly IDIOTMAN of SROD, and i'm proud of that, it's no much, but it's already an usefulness in this forum.
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Re: Erase a static array

Post by milan1612 »

Code: Select all

Repeat
  Ascii = Random(90)
Until Ascii > 64
:shock: :o :lol: :lol:

Here's a more 'direct' way :P

Code: Select all

Ascii = Random(25) + 65
Windows 7 & PureBasic 4.4
User avatar
Kcc
New User
New User
Posts: 3
Joined: Tue Sep 15, 2009 10:17 am

Re: Erase a static array

Post by Kcc »

Hello MILAN glad to talk to you :D

I see i'm always also funny, even when i don't want :lol: :lol: :lol:
Ascii = Random(25) + 65
Cool, it's so simple, that i have not thinking of that :oops:

And for my problem you don't know how i can erase a static array ??? :roll:
The happiness is a road, not a destination.
I'm the personaly IDIOTMAN of SROD, and i'm proud of that, it's no much, but it's already an usefulness in this forum.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: Erase a static array

Post by Kaeru Gaman »

Code: Select all

Dim ArrayLetter(0)
... is this what you want?
oh... and have a nice day.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Erase a static array

Post by srod »

Redimension it using Dim (not ReDim).

Code: Select all

Dim a.s(10)
a(1) = "Hello!"
Debug a(1)

Dim a.s(10)
Debug a(1)
I may look like a mule, but I'm not a complete ass.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5522
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Erase a static array

Post by Kwai chang caine »

Hello at you two 8)

I use a DLL who return the pointer of array.
But for return a pointer of array, i must dim it in STATIC or GLOBAL, i don't have the choice :(

So when i call the first time the DLL, the array is good STATIC dimensionned :D
But the second time, i want erase the STATIC array for write new word in him

With this example, i want obtain in the debbuger:

Code: Select all

Hello!
"" <---- empty a(2)
"" <---- empty a(1)
Goodbye!
But i obtain

Code: Select all

Hello!
"" <---- empty a(2)
Hello! <---- I don't want a(1) i want that the array is erase for the second time
Goodbye!
This is the big code :lol:

Code: Select all

Global x

Procedure TheArray()

 Static Dim a.s(10)
  
 If x = 1
  a(1) = "Hello!"
 Else
  a(2) = "Goodbye!" 
 EndIf
  
 Debug a(1)
 Debug a(2)
 
EndProcedure 

x + 1
TheArray()
x + 1
TheArray()
I have try :

Code: Select all

Static Dim a.s(0)
ReDim a(10)
Not works

Code: Select all

Dim a.s(0)
Static Dim a.s(10)
Not authorized

Code: Select all

 Static Dim a.s(10)
 Dim a.s(0)
 Static Dim a.s(10)
Not authorized
ImageThe happiness is a road...
Not a destination
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: Erase a static array

Post by Kaeru Gaman »

did you forget your password that you registered a new account?

try something like this:

Code: Select all

#TableSize = 10
Global x

Procedure TheArray()
  Static Dim a.s(#TableSize)
  For n=0 To #TableSize
    a(n) = ""
  Next
   
  If x = 1
    a(1) = "Hello!"
  Else
    a(2) = "Goodbye!"
  EndIf
   
  Debug a(1)
  Debug a(2)
  
EndProcedure

x + 1
TheArray()
x + 1
TheArray()
... or use a Fixed-String array, then you can erase the Memory directly...
oh... and have a nice day.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5522
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Erase a static array

Post by Kwai chang caine »

did you forget your password that you registered a new account?
Obviously....you have the eye at all :D
Nothing is forgotten :lol:

Yes i'm a prick :oops:
But i know, that i don't learn anything at everybody, when i say that :oops:

My UserName is "Kwai chang caine" is french forum.
So when the forum is changed, i try to connect with this name
And nothing works.
I have send several mails, but no answer :(

And today, i have see that my UserName in the US forum is "Kwaï chang caïne".
Then it's too late, i have create the new account.

Thanks for your answer, but i search a more "professionnal" method for do this.
I have thinking to erase the array with a loop of ""
But i say to me that they are surelly another way to erase it, more quickly, no ???? :roll:

Why we can erase a GLOBAL DIM with "0", and that's not works with STATIC ?? :roll:
ImageThe happiness is a road...
Not a destination
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: Erase a static array

Post by Kaeru Gaman »

the problem with STATIC is, it is only executed at first call, because it is meant to be ... static.

more professional? what the heck!
only having one command to do something does not at all mean it would be faster or better than a simple loop.

you need to have something that makes sure the strings behind the pointers are correctly freed, too.
if you use Fixstrings, the Stringdata is directly within the Array and you can just Zero the Memory to erase your strings.

so, a loop with string = "" is professional, just erasing the pointers would look more professional but produce a memleak and thus is less professional.
oh... and have a nice day.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5522
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Erase a static array

Post by Kwai chang caine »

Ok kaeru 8)
so, a loop with string = "" is professional, just erasing the pointers would look more professional but produce a memleak and thus is less professional.
It's just because that is my method....then i think it's not professionnal :lol: :oops:
And like i have never see a professional working, how can i know what is the good method :roll:

Thanks for your answer 8)
ImageThe happiness is a road...
Not a destination
harkon
Enthusiast
Enthusiast
Posts: 217
Joined: Wed Nov 23, 2005 5:48 pm

Re: Erase a static array [Resolved]

Post by harkon »

Or maybe like this

Code: Select all

Global x

Procedure TheArray()

Static Dim a.s(10)

ReDim a(0)
ReDim a(10)
 
If x = 1
  a(1) = "Hello!"
Else
  a(2) = "Goodbye!"
EndIf
 
Debug a(1)
Debug a(2)

EndProcedure

x + 1
TheArray()
x + 1
TheArray()
Should be quicker for larger arrays.
Missed it by that much!!
HK
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5522
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Erase a static array [Resolved]

Post by Kwai chang caine »

Thanks for your method.
Now i have the choice 8)

The method of kaeru and srod works too :wink:

Code: Select all

Global x

Procedure TheArray()

Static Dim a.s(10)
Dim a(10)

If x = 1
  a(1) = "Hello!"
Else
  a(2) = "Goodbye!"
EndIf

Debug a(1)
Debug a(2)

EndProcedure

x + 1
TheArray()
x + 1
TheArray()
ImageThe happiness is a road...
Not a destination
harkon
Enthusiast
Enthusiast
Posts: 217
Joined: Wed Nov 23, 2005 5:48 pm

Re: Erase a static array [Resolved]

Post by harkon »

I forgot about Srod's post,

Yup, that would be the one I'd use. :D
Missed it by that much!!
HK
Post Reply