# selecting random numbers

I am getting ready to start the randomize which selects 20 random numbers of the 80.
I need to know if a selected number is hit. In looking at your code i cannot determine  which numbers have been selected so i can determine if it is a selected number.
How can i determine selected numbers ?

This question is a follow up to http:Q_28317825.html
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Older than dirtCommented:
Be back in a minute.
Author Commented:
Hi MartinLiss in looking at the prev coders code i found this
If .CellPicture = imgblastrk Then
'
for me
If .CellPicture = imgSelNotHit Then   '
This might work. What do you think ?
Maybe i don't need the number in the cell 'just if it selected and hit.
Testing...
Older than dirtCommented:
Add this function in one of your modules. It assumes that the grid you are interested in is flexCleo in frmCleo but that is easily changed.

Usage: If you want to find out if, say, number 21 is selected then

If IsSelected(21) Then...
``````Public Function IsSelected(intNumber As Integer) As Boolean
'new 6
Dim intRow As Integer
Dim intCol As Integer

Select Case intNumber
Case 1 To 10
intRow = 0
Case 11 To 20
intRow = 1
Case 21 To 30
intRow = 2
Case 31 To 40
intRow = 3
Case 41 To 50
intRow = 4
Case 51 To 60
intRow = 5
Case 61 To 70
intRow = 6
Case 61 To 80
intRow = 7
End Select

intCol = intNumber Mod 10 - 1
If intCol = -1 Then
intCol = 9
End If

With frmCleo.flexCleo
.Row = intRow
.Col = intCol
.RowSel = intRow
.ColSel = intCol
If .CellForeColor = vbYellow Then
IsSelected = True
End If
End With
End Function
``````

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Older than dirtCommented:
Author Commented:
thanks
Works perfect
Seems ee doesn't like questions to individuals. Glad you answered and i did not have to do tons of explaining to get someone else in tune. After 638 questions over 10 years, not many have given this much help. after 45 yrs of roofing i wish i had about 20 in vb.
Older than dirtCommented:
Your very welcome. Below is a slightly improved version of the function. Regarding the title of your question, I believe I've seen other questions of the "For John Smith" type, but in any case I'm pretty sure that a title like "For MartinLiss - selecting random numbers" would be acceptable.

``````Public Function IsSelected(intNumber As Integer) As Boolean
'new 6
Dim intRow As Integer
Dim intCol As Integer

' The use of / yields whole numbers
intRow = (intNumber - 1) / 10

intCol = intNumber Mod 10 - 1
If intCol = -1 Then
intCol = 9
End If

With frmCleo.flexCleo
.Row = intRow
.Col = intCol
.RowSel = intRow
.ColSel = intCol
If .CellForeColor = vbYellow Then
IsSelected = True
End If
End With
End Function
``````
Author Commented:
Thanks MartinLiss seems your last post did not work on this:
MsgBox IsSelected(20)
Seems only the last column.
I did  not test the previous function on the last column
will do more testing
Author Commented:
the previous function seems to work correctly
Commented:
@MartinLiss

Did you mean to use the \ operator?
Older than dirtCommented:
Did you mean to use the \ operator?
Yes I did, nice catch.

isnoend2001, try this.

``````Public Function IsSelected(intNumber As Integer) As Boolean
'new 6
Dim intRow As Integer
Dim intCol As Integer

' The use of \ yields whole numbers
intRow = (intNumber - 1) \ 10

intCol = intNumber Mod 10 - 1
If intCol = -1 Then
intCol = 9
End If

With frmCleo.flexCleo
.Row = intRow
.Col = intCol
.RowSel = intRow
.ColSel = intCol
If .CellForeColor = vbYellow Then
IsSelected = True
End If
End With
End Function
``````
Author Commented:
Perfect, thanks
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.