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

Johnny Rosenberg <[email protected]> Mon, 15 Aug 2011 14:48:31 +0200
Newsgroups gmane.comp.openoffice.devel.api
Message-ID <CADo7T4ergPQpONruTxUvTtHz3+fCNpdcFcigyD1G0jeWXJYfNg@mail.gmail.com>
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=9DExp=
eriment=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 minutes=
=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 =C2=A0***** =C2=A0BASIC =C2=A0*****
>
> Option Explicit
> Option Compatible
>
> Type DieStatistics
> =C2=A0 =C2=A0 =C2=A0 =C2=A0Value As Integer
> =C2=A0 =C2=A0 =C2=A0 =C2=A0Count 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 th=
is
> 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
> ' =C2=A0 =C2=A0 =C2=A0 NDice tells us how many there are of each die valu=
e. In the above
> example, NDice(4)=3D1, since there are 1 die with the value 4.
> =C2=A0 =C2=A0 =C2=A0 =C2=A0Dim NDice(1 To 6) As Integer, i As Integer
>
> ' =C2=A0 =C2=A0 =C2=A0 Here we set the values of NDice for an example whe=
re this is known
> to fail, that is what NDice would contain if the dice were 112345
> ' =C2=A0 =C2=A0 =C2=A0 NDice(1)=3D2, NDice(2)=3D1 and so on.
> =C2=A0 =C2=A0 =C2=A0 =C2=A0For i=3D2 To 5
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0NDice(i)=3D1
> =C2=A0 =C2=A0 =C2=A0 =C2=A0Next i
> =C2=A0 =C2=A0 =C2=A0 =C2=A0NDice(1)=3D2
>
> ' =C2=A0 =C2=A0 =C2=A0 Here's where I calculate the values for DiceFreq b=
y going through
> NDice from 6 to 1.
> =C2=A0 =C2=A0 =C2=A0 =C2=A0For i=3D6 To 1 Step -1
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0If NDice(i)>DiceFr=
eq(0).Count Then
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0DiceFreq(1).Count=3DDiceFreq(0).Count
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0DiceFreq(1).Value=3DDiceFreq(0).Value
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0MsgBox DiceFreq(0).Value & ": " & Dic=
eFreq(0).Count & " st." & Chr(13) & _
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0DiceFreq(1).Value & ": " & DiceFreq(1=
).Count & " st."
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0DiceFreq(0).Count=3DNDice(i)
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0DiceFreq(0).Value=3Di
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0MsgBox DiceFreq(0).Value & ": " & Dic=
eFreq(0).Count & " st." & Chr(13) & _
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0DiceFreq(1).Value & ": " & DiceFreq(1=
).Count & " st."
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ElseIf NDice(i)>Di=
ceFreq(1).Count Then
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0DiceFreq(1).Count=3DNDice(i)
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0DiceFreq(1).Value=3Di
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0MsgBox DiceFreq(0).Value & ": " & Dic=
eFreq(0).Count & " st." & Chr(13) & _
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0DiceFreq(1).Value & ": " & DiceFreq(1=
).Count & " st."
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0EndIf
> =C2=A0 =C2=A0 =C2=A0 =C2=A0Next i
> =C2=A0 =C2=A0 =C2=A0 =C2=A0MsgBox "Final reults:" & String(2,Chr(13)) & D=
iceFreq(0).Value & ": "
> & DiceFreq(0).Count & _
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 " st." & Chr(13) & DiceFreq(1).Value & ": " &=
 DiceFreq(1).Count & " 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
-----------------------------------------------------------------
To unsubscribe send email to [email protected]
For additional commands send email to [email protected]
with Subject: help