June 25, 2024, 05:52:17 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


ISTRINGS

Started by Andy, November 22, 2015, 03:15:24 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

Hi,

Just been helping Brian with some coding, and it's working well as far as I can see, but I have a question about ISTRINGs.

In this code, I'm using two dimensional array istrings like this:

ISTRING x[5000,1000] - for example.

As far as I understand things, the above means "room" for 5000 characters, and possibly 1000 entries.

When I'm moving data to the istrings I am doing this:

for cd ......
x[5000,cd] = x[5000,cd] + y$
next cd .....

where - cd is the entry, y$ (string) is the data being added into the istring.

Now I know there are 18 strings to be added to each x[5000,cd].

So by my calculations the istring could be set to:
18 x 255 =  4590.

But 5000 is not enough, and there is data loss, why?

I have to set the istring character length to a much larger number.

As I said, the code works, but it does not make sense to me why when I calculate the maximum size
and add a little, it is too small.

Anyone any ideas please?

Thanks,
Andy.

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

billhsln

First [5000,1000] = 5,000,000 characters of storage.

Addressing ISTRINGs is a little funny. Normally you put 1 character in each spot, but ISTRINGs with multi dimensions, like what you have, can be accessed like:

def name:string
def sn[14,256]:istring
sn[0,c] = Name
print sn[0,c]

string = 255 characters as max, but just in case you need 1 character for the null character to end the string (\0).

Hope this helps a little,
Bill
When all else fails, get a bigger hammer.

LarryMc

Andy, your premiss that you have a 2-dim array is wrong

The solution to problems lie here

http://www.ionicwind.com/forums/index.php?topic=1650.msg15239#msg15239

Bill, your example is correct
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Yes, silly me!

I have however found the problem, and unvailed another question.

Firstly, the problem was that later in the code the istring was being referenced with the wrong character size, which caused data loss.

So the istring is now set to x[5000,3000].

18 x 256 = 4608 - so 5000 is enough for this.

And all instances in the code are now x[5000,......

Secondly, if I change the reference to the istring to say x[4999,....... - this causes data loss, likewise if the istring is changed to a larger number x[5001,..... this also causes data loss.

Obviously the istring should always be the same value everywhere in the code, but why when you change the value of the istring should it cause data loss?

Just for curiosity's sake.

Thanks,
Andy.

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

Not sure I understand what you are meaning by
And all instances in the code are now x[5000,......
Since you are saying this
So the istring is now set to x[5000,3000].
then I have to assume that somewhere in your program you have this
ISTRING x[5000,3000]
which means you have created an array which can hold 3000 elements and each element can hold an ISTRING that is up to 5000 characters long.
normally speaking that is the last time you see the 5000.
and like a standard array in IWB, once you dimension an array there is no REDIM command so you should never be changing it..

So, if you want to store some text in the 5th element of the array it would be written
x[0,4]="Mary had a little lamb"
likewise, to print the 5th element would be
PRINT x[0,4]

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Thanks Larry for clearing things up for me.

Looks like I was having a "senior" moment if you understand me.

I just got completely confused and couldn't see the wood for the trees.

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

Quote from: andy1966 on November 26, 2015, 03:54:28 AM
....I was having a "senior" moment if you understand me.

I just got completely confused and couldn't see the wood for the trees.
Are you kidding? My life is one continuous "senior" moment!  :o
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library