"Function droll(dtype as Integer) as Integer 'valid dice type ? If (dtype<1)Or(dtype>100) Then droll = 0 Exit Function End If 'set result column num Dim column as Integer 'result column num Dim roll as Integer 'roll result roll = 0 If (dtype>=1)And(dtype<=9) Then column = 1 ElseIf (dtype>=10)And(dtype<=99) Then column = 2 ElseIf dtype=100 Then column = 3 EndIf 'roll Do until (roll>=1)And(roll<=dtype) roll = val(mid(str(rand()),2,column)) Loop droll = roll End Function "