Interesting MOD Problem...

1. Senior Member
Join Date
Dec 1969
Posts
6,476

## Interesting MOD Problem...

msg = "" &#039;new messages to send<BR>maxMod = 100 &#039;Same size as array<BR>arrMessages(100) &#039;fixed array size<BR>LastMsgIn = 1274 &#039;running counter<BR>LastUserMsg = 1257 &#039;last message user got<BR><BR>For i = LastuserMsg to LastMsgIn<BR>msg = msg & arrMessages(i MOD maxMod)<BR>Next<BR><BR>Ok this works fine.<BR>I can not see a way to "Shrink" The array and Mod without some messages being lost or duplicated...<BR><BR>Lets say (LastMsgIn MOD maxMod) = 67<BR><BR>Now I could go<BR>Dim newArray(60)<BR>i = 0<BR> for t = 67 to 100<BR> newArray(0) = arrMessages(t)<BR> i = i+1<BR>Next<BR>arrMessages = newArray<BR><BR>I would have to start LastMsgIn all over again<BR>LastMsgIn = 0 <BR>maxMod = 60<BR> <BR>And force each user to take on the new LastMsgIn<BR>Easily done...<BR><BR>Thing is, copying the array and resizing it, and changing the MOD<BR><BR>I Dont see how messages wont be lost?<BR>I copied from 67 of the old array, made it 0 in new array<BR><BR>Somone may have gotten lastMsg of 60, therefor 7 messages were lost in the transfer<BR>If I had started copying at 60<BR>Then some users may see 7 duplicates<BR><BR>Increasing in size 60 to 100 is easy<BR>It&#039;s coming down the scale I cant figure out.<BR><BR>Anyone have any ideas?

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## You'll have to tell me...

...WHY you want to do this???<BR><BR>If you know that none of the messages from (say)<BR> LastMsgIn MOD maxMod<BR>to<BR> LastUserMsg MOD maxMod<BR>are needed any longer, then just assign NULL to those array elements:<BR><BR> For m = (LastMsgIn + 1) To (maxMod + LastUserMsg)<BR> arrMessages(m MOD maxMod) = Null<BR> Next<BR><BR>You *want* that to wrap around! To take your example, where the last message in is 1274 and the last one the user read was 1257: So you can wipe out array elements 76 to 99 and then from 00 to 57, yes? So bumping the 1257 by 100 (maxMod) allows that to happen!<BR><BR>ANYWAY...Now you will be wasting *AT MOST* 1600 bytes of memory. Whoopee. Waste away.<BR><BR>It would be a ROYAL PAIN to shrink the array and fix it so the user&#039;s message numbers still referred to the same messages.<BR><BR>But could it be done? I think so. But I wouldn&#039;t adjust any session variables; I&#039;d just add a "bias" via another app variable.<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
6,476

## The reason I wanted to

shrink this...<BR>ok, first, correct me if im wrong...<BR>But you cant just change an Application Array Elemenet directly can you?<BR>If i wanted to change Application("arrMsg") element # 200<BR><BR>Dim arrNew<BR>Application.Lock<BR>arrNew = Application("arrMsg")<BR>ArrNew(200) = "New Message"<BR>Application("arrMsg") = ArrNew<BR>Application.Unlock<BR><BR>Correct?<BR>I tried a few ways to update the app array directly and just got errors...<BR>Researched it and found you shouldnt work directly with an app array like that...<BR><BR>IF that is correct then thats why i want to shrink array...<BR><BR>IF i have 50 users at same time<BR>and have array at 200 messages<BR><BR>approx what 1 meg memory for array? (Roughly)<BR><BR>And If copying a 1 meg array size to another array, make change and copy it back<BR>uses more memory correct?<BR><BR>50 people, 5 second refresh rate thats 10 hits per second to lock, copy, addto, copy back, unlock<BR><BR>Could be a bit extensive no?<BR><BR>Thats why i was thinking<BR>1 to 10 users , arr(40)<BR>10 to 20 users , arr(80) <BR>20 to 30 users , arr(120) <BR>30 to 40 users , arr(160) <BR>40 to 50 users , arr(200) <BR><BR>Just to work with a better suited size...<BR>and as users deminish<BR>make array smaller to work with smaller amounts...<BR><BR>make sense?<BR>

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## ??? Never tested it...

...but I thought you could zap an app array directly.<BR><BR>What did you try?<BR><BR>Application.Lock<BR>Application("arrMs g")(200) = NewMessage<BR>Application.Unlock<BR><BR>What happens when you try that?<BR><BR>I *MUST* run. Late for music practice. Tomorrow.<BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
6,476

## RE: ??? Never tested it...

Yes getting late for me too...<BR>Will check back tomorrow...<BR><BR>Yes, I did try hard coding it as you did.<BR><BR>Application.Lock<BR>Application("arrMe ssage")(100) = "Testing"<BR>Application.Unlock<BR><BR>Gives no error.<BR>But does no update to that element...<BR><BR>Thats when i went searching, and read somewhere you cant or shouldn&#039;t work directly with an array in application scope.<BR>Should be copied, worked with, then copied back...<BR><BR>So given that, and amount of users im talking about<BR>you can appreciate my worrying a little bit.<BR><BR>Will pick it up tomorrow.<BR><BR>Thanks for the reply.

6. Senior Member
Join Date
Dec 1969
Posts
6,476

## RE: The reason I wanted to

Opps<BR>Read what you said, but it didnt imprint in my head till now...<BR><BR>What your saying is if i can have that array set to 1000 if i want<BR>and have then all set to Null...<BR>the array will still be small and easily managed...<BR><BR>Duh, should picked up on that right away...<BR><BR>But, what about changing an app array element directly...<BR><BR>The way Im doing it, copying to another array, change, then copy back<BR><BR>thats the proper way to do it right?<BR>Cause like i said, couldnt work directly with it before...<BR><BR>Ill pick it up tomorrow as well.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•