|
' ユーザ定義型を使ったサンプル(かなり適当)
Option Explicit
Private Type Dice
Value As Integer ' 目
Count As Integer ' 回数
End Type
Public Sub Test()
Dim CSVData() As String
Dim DiceInfo(5) As Dice ' サイコロの情報
Dim i As Long
Dim swapped As Boolean
Dim temp As Dice
' 初期化
For i = LBound(DiceInfo) To UBound(DiceInfo)
DiceInfo(i).Value = i + 1
Next
' カンマ区切りに配列に設定
CSVData = Split("1,1,1,1,2,2,2,3,3,5,6,6", ",")
' 振り分け
For i = LBound(CSVData) To UBound(CSVData)
DiceInfo(CInt(CSVData(i)) - 1).Count = _
DiceInfo(CInt(CSVData(i)) - 1).Count + 1
Next
' 回数による降順並び替え(バブルソート)
Do
swapped = False
For i = LBound(DiceInfo) To UBound(DiceInfo) - 1
If DiceInfo(i).Count < DiceInfo(i + 1).Count Then
swapped = True
' 入れ替え
temp = DiceInfo(i)
DiceInfo(i) = DiceInfo(i + 1)
DiceInfo(i + 1) = temp
End If
Next
Loop Until swapped
' イミディエイトウィンドウに表示
For i = LBound(DiceInfo) To UBound(DiceInfo)
Debug.Print CStr(i + 1) & "位:"; DiceInfo(i).Value
Next
End Sub
|
|