Problem with un-selecting numbers for keno game(stumped)

Posted on 2013-11-26
Medium Priority
Last Modified: 2013-11-26
problemproblem problemHired a coder from FreeLancer a few month ago to write
Code for a keno game. Can no longer find him.
There are 80 numbers on the keno board.
The numbers are selected by dragging the mouse over the numbers.
this happens no matter which numbers are selected not just the first 5
In the jpg I have selected the first 5 numbers by dragging the mouse.
 The problem arrises when dragging to unselect the numbers.The wrong numbers are displayed in the cells. It works correctly when clicking the indivual cells to unselect them. but dragging displays the problem(see jpg)

this happens no matter which numbers are selected not just the first 5
I think it is inthe following code which is beyond my abilities.

Private Sub DeSelectCurrentBoard()
Dim iRow As Integer, iCol As Integer
    With flexBoardSelector
        If mCurrentBoardIndex > 0 Then
            CellFromIndex mCurrentBoardIndex, iRow, iCol
            .Row = iRow: .Col = iCol
            .CellBackColor = vbWhite
        End If
    End With

End Sub
Private Sub flexKenoBoard_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
Dim OverCentreX As Boolean, OverCentreY As Boolean, ValidMouseOver As Boolean
Dim thisIndex As Integer
With flexKenoBoard
        OverCentreX = Abs(Y - (.RowPos(.MouseRow) + (BOARD_CELL_WIDTH / 2))) < CELL_MOUSE_SENSITIVITY
        OverCentreY = Abs(X - (.ColPos(.MouseCol) + (BOARD_CELL_WIDTH / 2))) < CELL_MOUSE_SENSITIVITY
        ValidMouseOver = OverCentreX And OverCentreY
        If ValidMouseOver And mranddonenobet = False Then
            thisIndex = IndexFromCell(flexKenoBoard.MouseRow, flexKenoBoard.MouseCol)
            'Store the card value to available for reuse - KVS - v1.x
            clval = thisIndex
            UpdateNumber IndexFromCell(.MouseRow, .MouseCol), X, Y, False
        End If
    End With
End Sub

Private Sub flexKenoBoard_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim thisIndex As Integer

    If Button = vbLeftButton Then
        thisIndex = IndexFromCell(flexKenoBoard.MouseRow, flexKenoBoard.MouseCol)
        'Store the card value to available for reuse - KVS - v1.x
        clval = thisIndex
        mSelecting = Not KenoNumbers(thisIndex).Selected
        UpdateNumber thisIndex, X, Y, True
    End If

End Sub

Private Sub UpdateNumber(pindex As Integer, pX As Single, pY As Single, Optional pInitialiseDrag As Boolean = False)
Dim lRow As Integer, lCol As Integer, lBorderColour As Long, lForeColour As Long
Dim thisImage As StdPicture

    If mCurrentBoardIndex = 0 Then Exit Sub 'Check this KVS
    'to check Bet before selecting numbers - KVS - v1.8
'    If KenoBoards(mCurrentBoardIndex).Stake = 0 And KenoBoards(mCurrentBoardIndex).SelectedCount = 0 Then
'         MsgBox "No bet placed"
'         Exit Sub
'    End If
    If KenoBoards(mCurrentBoardIndex).SelectedCount = MAX_SELECTIONS And mSelecting Then
        Exit Sub
    End If
    If mranddonenobet = True Then
        If mSavedfileIsDirty = False Then
            mNewBetPlaced = True
            mSavedfileIsDirty = True 'To check Save or NOT
            Call Save_tofile_Write_INI
            If mIsDirty = False Then
                mNewBetPlaced = False
                Exit Sub 'User clicked Cancel
                mranddonenobet = False
                mNewBetPlaced = False
                Call Clear_gridCardStats
                pInitialiseDrag = False
            End If
        End If
    End If
    'KVS - v2.9.1
    If pInitialiseDrag Then
        flexKenoBoard.Drag vbBeginDrag
    End If
    If mSelecting = KenoNumbers(pindex).Selected Then
        'Nothing to do - item is already selected or unselected
        KenoNumbers(pindex).AssignedLetters = Replace(KenoNumbers(pindex).AssignedLetters, KenoBoards(mCurrentBoardIndex).Letter, vbNullString)
        'Set the selected Char to the variable - KVS - v1.x
        sel_text_val = KenoBoards(mCurrentBoardIndex).Letter
        CellFromIndex pindex, lRow, lCol
        If mSelecting Then
            lBorderColour = KenoBoards(mCurrentBoardIndex).Colour
            lForeColour = vbWhite
            KenoNumbers(pindex).AssignedLetters = KenoNumbers(pindex).AssignedLetters & KenoBoards(mCurrentBoardIndex).Letter
            KenoBoards(mCurrentBoardIndex).SelectedCount = KenoBoards(mCurrentBoardIndex).SelectedCount + 1
            Set thisImage = imgBlueSpot.Picture
            'As user have to make bet before selecting a number - KVS - v1.8
'            If KenoBoards(mCurrentBoardIndex).Stake = 0 Then
'                cmdBetMore_Click
'            End If
            lBorderColour = vbWhite
            lForeColour = vbBlack
            KenoBoards(mCurrentBoardIndex).SelectedCount = KenoBoards(mCurrentBoardIndex).SelectedCount - 1
            Set thisImage = imgCellBG.Picture
            'Reset the value back - KVS - v1.x
            flexKenoBoard.Text = clval
        End If
        With flexKenoBoard
            .Row = lRow: .Col = lCol
            .RowSel = lRow: .ColSel = lCol
            Set .CellPicture = thisImage
            .Text = clval
            'If click, set the text to selected Char - KVS - v1.x
            If mSelecting Then .Text = sel_text_val
            .CellBackColor = lBorderColour
            .CellForeColor = lForeColour
        End With
        KenoNumbers(pindex).Selected = mSelecting
        flexStatus.TextMatrix(KenoBoards(mCurrentBoardIndex).Index, 2) = IIf(KenoBoards(mCurrentBoardIndex).SelectedCount > 0, KenoBoards(mCurrentBoardIndex).SelectedCount, vbNullString)
        'To load flexonecard when clicking the letter for which numbers are selected already - KVS - V1.6
            If FlexOneCard.Visible = True And flexStatus.TextMatrix(KenoBoards(mCurrentBoardIndex).Index, 1) <> "" Then
                Call flexoncecard_upd(flexStatus.TextMatrix(KenoBoards(mCurrentBoardIndex).Index, 1), mCurrentBoardIndex, KenoBoards(mCurrentBoardIndex).SelectedCount)
                'lblRuns.Caption = 0 'KVS - v2.6
                gridCardStats.TextMatrix(5, 1) = 0
            End If
         PlaySoundData SoundSelect(0), 0, SND_MEMORY Or SND_ASYNC Or SND_NODEFAULT
    End If
    If getCardCountSelected >= 2 Then
        Call ShowOneCard
        'Its showing ALL flex grid while selcting the numbers for the first letter - KVS - V1.6
        'Call ShowAllCards
        'Added to show flexgrip for single card selection - KVS - V1.6
        Call ShowOneCard
    End If
    Call DisplayCardsPlayed
End Sub

Private Function getCardCountSelected() As Integer
    Dim i As Integer
    Dim lCount As Integer
    lCount = 0
    For i = 1 To 20
        If KenoBoards(i).SelectedCount > 0 Then
            lCount = lCount + 1
        End If
    Next i

Open in new window

Question by:isnoend2001
  • 3
  • 3
LVL 12

Expert Comment

ID: 39679764
I can't quite see where it might be, but your problem looks like one that is caused by the programmer fogetting that the index number of a first column or row is actually 0, not 1.

When the numbers are de-selected, they are being reset to one number higher because they are being counted from 1 not 0, therefore the first cell becomes 1+1 = 2 instead of 0+1 = 1

Author Comment

ID: 39679789
Thanks for the reply, I think you are probably right, but i am stumped as what needs changing
LVL 12

Expert Comment

ID: 39679816
I feel your pain - it can be hard to work out what someone else had in mind and the approach they have taken.

Can you provide any more code or the actual page/app code itself? That would make it easier to follow what the code does and therefore find where the incorrect starting number is used.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 39679830
Thanks duttcom
I posted at another site and got this reply:
try changing
 flexKenoBoard.Text = clval
flexKenoBoard.Text = clval - 1
this seems to have fixed the dragging accross cols,
but not accross rows
I will attach the form
I really do appreciate the helpKeno.zip
LVL 12

Accepted Solution

duttcom earned 2000 total points
ID: 39679883
Okay, I think I know why this is happening, but without being able to run the code to test it, I can't say for sure exactly where to fix it.

The code uses .MouseRow and MouseCol to determine where the mouse pointer is. From what I understand, MouseRow and MouseCol return the absolute(?) row number, not the indexed one, ie. if you have a ten by ten grid, the indexed rows and columns would be numbered 0-9, but MouseRow and MouseCol would treat that grid as 1-10

If you go back to the original code (without the suggested change above), there will be  references to MouseRow and MouseCol that will need to have 1 subtracted from them.

Author Closing Comment

ID: 39679914
Thanks for taking the time to troubleshoot this problem. I will try your suggestions, hopefully I can get past this issue

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

755 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