Page 1 of 1

Erase a static array [Resolved]

Posted: Wed Sep 16, 2009 10:15 am
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)

Re: Erase a static array

Posted: Wed Sep 16, 2009 10:45 am
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

Re: Erase a static array

Posted: Wed Sep 16, 2009 10:56 am
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:

Re: Erase a static array

Posted: Wed Sep 16, 2009 11:09 am
by Kaeru Gaman

Code: Select all

Dim ArrayLetter(0)
... is this what you want?

Re: Erase a static array

Posted: Wed Sep 16, 2009 11:10 am
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)

Re: Erase a static array

Posted: Wed Sep 16, 2009 11:24 am
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

Re: Erase a static array

Posted: Wed Sep 16, 2009 12:10 pm
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...

Re: Erase a static array

Posted: Wed Sep 16, 2009 12:55 pm
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:

Re: Erase a static array

Posted: Wed Sep 16, 2009 1:39 pm
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.

Re: Erase a static array

Posted: Wed Sep 16, 2009 2:05 pm
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)

Re: Erase a static array [Resolved]

Posted: Wed Sep 16, 2009 4:46 pm
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.

Re: Erase a static array [Resolved]

Posted: Wed Sep 16, 2009 7:09 pm
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()

Re: Erase a static array [Resolved]

Posted: Wed Sep 16, 2009 9:20 pm
by harkon
I forgot about Srod's post,

Yup, that would be the one I'd use. :D