Custom types drives me nuts – this ca n't be happening… can it?

Johnny Rosenberg <[email protected]> Mon, 15 Aug 2011 14:31:42 +0200
Newsgroups gmane.comp.openoffice.devel.api
Message-ID <CADo7T4d=ZCW-a=byH3pXo1+d7T9S3GeB2qD-UWFmBQwV9GJ-hA@mail.gmail.com>
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 above
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 known
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
=09
'	Here's where I calculate the values for DiceFreq by going through
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 & ": " & DiceFreq(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 & ": " & DiceFreq(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 & ": " & DiceFreq(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).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