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

Posted on 2013-11-26
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.
Industry Leaders: 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!


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
LVL 12

Accepted Solution

duttcom earned 500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

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