Sep 17, 2015 Replies: 2 Welcome to the future! Code: Copy 'Return a random object from the specified object array. Sub RandomStuff(ObjectArray() As Object) As Object Return ObjectArray(Rnd(0, ObjectArray.Length)) End Sub Usage (B4J): Before: Code: Copy ... Dim Color As Paint Dim c = Rnd(0, 5) as int Select c Case 0 Color = fx.Colors.Red Case 1 Color = fx.Colors.Green Case 2 Color = fx.Colors.Blue Case 3 Color = fx.Colors.Yellow Case 4 Color = fx.Colors.Gray End Select cvs.DrawCircle(300, 200, 100, Color, True, 1) ... Now: Code: Copy Dim Color() As Object Color = Array As Object(fx.Colors.Red, fx.Colors.Green, fx.Colors.Blue, fx.Colors.Yellow, fx.Colors.Gray) cvs.DrawCircle(300, 200, 100, RandomStuff(Color), True, 1) I hope the code is self-explanatory. Last edited: Sep 17, 2015 Click to expand...
Welcome to the future! Code: Copy 'Return a random object from the specified object array. Sub RandomStuff(ObjectArray() As Object) As Object Return ObjectArray(Rnd(0, ObjectArray.Length)) End Sub Usage (B4J): Before: Code: Copy ... Dim Color As Paint Dim c = Rnd(0, 5) as int Select c Case 0 Color = fx.Colors.Red Case 1 Color = fx.Colors.Green Case 2 Color = fx.Colors.Blue Case 3 Color = fx.Colors.Yellow Case 4 Color = fx.Colors.Gray End Select cvs.DrawCircle(300, 200, 100, Color, True, 1) ... Now: Code: Copy Dim Color() As Object Color = Array As Object(fx.Colors.Red, fx.Colors.Green, fx.Colors.Blue, fx.Colors.Yellow, fx.Colors.Gray) cvs.DrawCircle(300, 200, 100, RandomStuff(Color), True, 1) I hope the code is self-explanatory.
I inakigarm Well-Known Member Licensed User Longtime User Sep 17, 2015 #2 Maybe Code: Copy Colors is Code: Copy Color in code ?
wonder Expert Licensed User Longtime User Sep 17, 2015 #3 inakigarm said: Maybe "Colors" is "Color" in code? Click to expand... Yes, yes, yes, sorry - my mistake. Corrected.
inakigarm said: Maybe "Colors" is "Color" in code? Click to expand... Yes, yes, yes, sorry - my mistake. Corrected.