Re: Custom types drives me nuts – t his can't be happening… can it?

Andrew Douglas Pitonyak <[email protected]> Tue, 16 Aug 2011 17:58:48 -0400
Newsgroups gmane.comp.openoffice.devel.api
Message-ID <[email protected]>
Oh my goodness! It is always something small that wastes hours of time.

On 08/15/2011 08:48 AM, Johnny Rosenberg wrote:
> Okej, forget this, I solved it. Immediately after I sent this I found
> the problem! All I needed to do to find it out was probably to write
> about it somewhere=E2=80=A6
>
> I found the problem when I did a search in all modules for my type
> =E2=80=9DDieStatistics=E2=80=9D. I found it in a module called =E2=80=9D=
Experiment=E2=80=9D which is
> Swedish for =E2=80=9DExperiments=E2=80=9D in this case.
>
> I did some tests in that module a few days ago, before I declared
> DiceFreq as an array of DieStatistics, so DiceFreq was declared
> globally twice:
>
> Module Experiment:
> Global DiceFreq As DieStatistics
>
>
> Module P:
> Private DiceFreq(1) As DieStatistics
>
> After removing the Experiment ones, everything worked as expected.
>
> Phew, what a relief=E2=80=A6 I thought I was crazy there for a few minu=
tes=E2=80=A6!
>
>
> And I usually don't top post, but in this case I thought it could be
> appropriate, since the text below suddenly became very unimportant.
>
>
> Best regards
>
> Johnny Rosenberg
> =E3=82=B8=E3=83=A7=E3=83=8B=E3=83=BC=E3=83=BB=E3=83=AD=E3=83=BC=E3=82=BC=
=E3=83=B3=E3=83=90=E3=83=BC=E3=82=B0
>
>
> 2011/8/15 Johnny Rosenberg<[email protected]>:
>> I was editing some code I have, actually a game with dice and stuff,
>> but that doesn't matter, I suppose.
>>
>> So I ran into a problem, and I copied the troubling part of the code
>> to a separate document for test driving.
>> However, the test code runs perfectly, but not within the game of mine=
!
>>
>> I ran the game on another computer but another version of
>> OpenOffice.org (actually the first computer runs LibreOffice 3.3.3),
>> but the results were exactly the same.
>>
>> Here's the test code. I have a message box after almost every
>> statement so I can see what happens. I added some extra comments in
>> the code.
>>
>> REM  *****  BASIC  *****
>>
>> Option Explicit
>> Option Compatible
>>
>> Type DieStatistics
>>         Value As Integer
>>         Count As Integer
>> End Type
>>
>> ' The variable DiceFreq, declared below this comment, tells us which
>> two die values that are most frequent. For example, if the six dice
>> are 133455,
>> ' DiceFreq will contain:
>> ' DiceFreq(0).Value: 5 (the most common value is 5)
>> ' DiceFreq(0).Count: 2 (2 dice have the value 5)
>> ' DiceFreq(1).Value: 3 (the second most common value is 3 =E2=80=93 in=
 this
>> case there are two of both 3 and five, but higher value has priority)
>> ' DiceFreq(1).Count: 2 (2 dice have the value 3)
>> ' This makes it very easy for us to calculate things later,
>> calculations that are not present in this short example though.
>> Private DiceFreq(1) As DieStatistics '
>>
>>
>> Sub Test0
>> '       NDice tells us how many there are of each die value. In the ab=
ove
>> example, NDice(4)=3D1, since there are 1 die with the value 4.
>>         Dim NDice(1 To 6) As Integer, i As Integer
>>
>> '       Here we set the values of NDice for an example where this is k=
nown
>> to fail, that is what NDice would contain if the dice were 112345
>> '       NDice(1)=3D2, NDice(2)=3D1 and so on.
>>         For i=3D2 To 5
>>                 NDice(i)=3D1
>>         Next i
>>         NDice(1)=3D2
>>
>> '       Here's where I calculate the values for DiceFreq by going thro=
ugh
>> NDice from 6 to 1.
>>         For i=3D6 To 1 Step -1
>>                 If NDice(i)>DiceFreq(0).Count Then
>>                         DiceFreq(1).Count=3DDiceFreq(0).Count
>>                         DiceFreq(1).Value=3DDiceFreq(0).Value
>>                                 MsgBox DiceFreq(0).Value&  ": "&  Dice=
Freq(0).Count&  " st."&  Chr(13)&  _
>>                                 DiceFreq(1).Value&  ": "&  DiceFreq(1)=
.Count&  " st."
>>                         DiceFreq(0).Count=3DNDice(i)
>>                         DiceFreq(0).Value=3Di
>>                                 MsgBox DiceFreq(0).Value&  ": "&  Dice=
Freq(0).Count&  " st."&  Chr(13)&  _
>>                                 DiceFreq(1).Value&  ": "&  DiceFreq(1)=
.Count&  " st."
>>                 ElseIf NDice(i)>DiceFreq(1).Count Then
>>                         DiceFreq(1).Count=3DNDice(i)
>>                         DiceFreq(1).Value=3Di
>>                                 MsgBox DiceFreq(0).Value&  ": "&  Dice=
Freq(0).Count&  " st."&  Chr(13)&  _
>>                                 DiceFreq(1).Value&  ": "&  DiceFreq(1)=
.Count&  " st."
>>                 EndIf
>>         Next i
>>         MsgBox "Final reults:"&  String(2,Chr(13))&  DiceFreq(0).Value=
&  ":"
>> &  DiceFreq(0).Count&  _
>>          " st."&  Chr(13)&  DiceFreq(1).Value&  ": "&  DiceFreq(1).Cou=
nt&  " st."
>> End Sub
>>
>>
>> Now, while this works perfectly as a stand-alone subroutine, it
>> doesn't work in the game. What happens in the game is that everytime I
>> change the value of DiceFreq(i).Value or DiceFreq(i).Count, BOTH
>> instances are changed, for example if I set DiceFreq(0).Value to 5,
>> DiceFreq(1).Value is also set to 5 and I just can't figure out why!
>>
>> In the game the corresponding subroutine is called from another
>> module, but I simulated that too in my test, but still it ONLY fails
>> in the game.
>>
>> I can upload my game document (the debug version) somewhere if needed.
>>
>> What on earth could possibly cause this? I'm just out of ideas!
>>
>> Help=E2=80=A6?
>>
>>
>> Kind regards
>>
>> Johnny Rosenberg
>> =E3=82=B8=E3=83=A7=E3=83=8B=E3=83=BC=E3=83=BB=E3=83=AD=E3=83=BC=E3=82=BC=
=E3=83=B3=E3=83=90=E3=83=BC=E3=82=B0
>>

--=20
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
Info:  http://www.pitonyak.org/oo.php

--=20
-----------------------------------------------------------------
To unsubscribe send email to [email protected]
For additional commands send email to [email protected]
with Subject: help