Solved

selecting random numbers

Posted on 2013-12-15
12
273 Views
Last Modified: 2013-12-17
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
0
Comment
Question by:isnoend2001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
12 Comments
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39722320
Be back in a minute.
0
 

Author Comment

by:isnoend2001
ID: 39722508
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...
0
 
LVL 47

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 39722551
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

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 47

Expert Comment

by:Martin Liss
ID: 39722555
If you have any questions about this I'll be out for a couple of hours.
0
 

Author Closing Comment

by:isnoend2001
ID: 39722851
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.
Thanks for your help
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39722911
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

Open in new window

0
 

Author Comment

by:isnoend2001
ID: 39722977
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
0
 

Author Comment

by:isnoend2001
ID: 39722985
the previous function seems to work correctly
0
 
LVL 45

Expert Comment

by:aikimark
ID: 39723408
@MartinLiss

Did you mean to use the \ operator?
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39724483
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

Open in new window

0
 

Author Comment

by:isnoend2001
ID: 39724534
Perfect, thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question