Solved

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

Posted on 2013-11-26
6
384 Views
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
            Else
                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
    Else
        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
        Else
            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
    Else
        '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

0
Comment
Question by:isnoend2001
  • 3
  • 3
6 Comments
 
LVL 12

Expert Comment

by:duttcom
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
0
 

Author Comment

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

Expert Comment

by:duttcom
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.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:isnoend2001
ID: 39679830
Thanks duttcom
I posted at another site and got this reply:
try changing
 flexKenoBoard.Text = clval
to
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
0
 
LVL 12

Accepted Solution

by:
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.
0
 

Author Closing Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now