Solved

For MartinLiss Question on the project i uploaded  http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_28354481.html

Posted on 2014-02-03
23
224 Views
Last Modified: 2014-02-06
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_28354481.html
I hope you can help me with this.
As i stated before I am trying to use code a coder i hired to write this new project. Most is over my head. See the attached rtf file
keno-problems.zip
0
Comment
Question by:isnoend2001
  • 12
  • 10
23 Comments
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
I'm looking at it now.
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
When I open the saved game, frmCleoBonus opens. Is that supposed to happen?

Another problem that I've seen in your project and that is that sometimes when I select a number, two numbers are selected. Does that happen to you?

A general problem is that you have many dead ( = unused) variables and procedures in your code which makes it more difficult to maintain.
0
 

Author Comment

by:isnoend2001
Comment Utility
Thanks for your help
When I open the saved game, frmCleoBonus opens. Is that supposed to happen?
No. seems i remember that happening, don't remember why or how i fixed it

Another problem that I've seen in your project and that is that sometimes when I select a number, two numbers are selected. Does that happen to you?
2 numbers should only be selected by dragging. I will check

A general problem is that you have many dead ( = unused) variables and procedures in your code which makes it more difficult to maintain.
Yes and a lot of subs, functions, this comes from me coping the hired coders code

Should i upload the latest code-project?
0
 

Author Comment

by:isnoend2001
Comment Utility
Another problem that I've seen in your project and that is that sometimes when I select a number, two numbers are selected. Does that happen to you?
2 numbers should only be selected by dragging. I will check

This does not happen to me
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
When I click the numbers rapidly VB may think I'm dragging.
0
 
LVL 45

Accepted Solution

by:
Martin Liss earned 500 total points
Comment Utility
I've found the solution to the problem you described where lblMarked gets reset. To fix it add lines 31 to 34 in this code in frmCleo.
'---------------------------------------------------------------------------------------
' Procedure : UpdateNumber
' DateTime  : 12/18/2013 09:08
' Author    : Robert Moore
' Purpose   :
'---------------------------------------------------------------------------------------
'
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


   On Error GoTo UpdateNumber_Error

   If KenoBoards(mCurrentBoardIndex).SelectedCount = MAX_SELECTIONS And mSelecting Then
        Exit Sub
    End If
 
 
    If pInitialiseDrag Then
        flexCleo.Drag vbBeginDrag
    End If
           
    CellFromIndex pindex, lRow, lCol
    
    If mSelecting = KenoNumbers(pindex).Selected Then
     'Nothing to do - item is already selected or unselected
    Else
       If mSelecting Then
          Set thisImage = imgSelNotHit.Picture
          'new
          If Val(lblMarked.Caption) > 0 Then
            KenoBoards(mCurrentBoardIndex).SelectedCount = Val(lblMarked.Caption)
          End If
          
          KenoBoards(mCurrentBoardIndex).SelectedCount = KenoBoards(mCurrentBoardIndex).SelectedCount + 1
          
          With flexCleo
            .Row = lRow
            .Col = lCol
            .RowSel = lRow
            .ColSel = lCol
            Set .CellPicture = thisImage
            .CellForeColor = vbYellow
          End With
          
          
           ' select the same cells in frmcleobonus
'           With frmCleoBonus.flexCleoBonus
'           .Row = lRow
'            .Col = lCol
'            .RowSel = lRow
'            .ColSel = lCol
'            Set .CellPicture = frmCleoBonus.imgChoosen
'            .CellForeColor = vbYellow
'            End With
'          gBonusRow = iRow
'          gBonusCol = iCol
       Else
          Set thisImage = imgCellBG.Picture 'reset to unselected
          KenoBoards(mCurrentBoardIndex).SelectedCount = KenoBoards(mCurrentBoardIndex).SelectedCount - 1
          mUnSeletedNumber = True 'rm12-18-13
          With flexCleo
            .Row = lRow
            .Col = lCol
            .RowSel = lRow
            .ColSel = lCol
            Set .CellPicture = thisImage
            .CellForeColor = vbWhite
            
          End With
       End If
       
       lblMarked.Caption = "" & KenoBoards(mCurrentBoardIndex).SelectedCount
       mNumberofSpotsSelected = KenoBoards(mCurrentBoardIndex).SelectedCount
       'mNumberofSpotsSelected = Val(lblMarked)
       gintSelected = Val(lblMarked)
       KenoNumbers(pindex).Selected = mSelecting
       UpdateFlexStatus 'rm12-18-13
    End If

   On Error GoTo 0
   Exit Sub

UpdateNumber_Error:

    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure UpdateNumber of Form frmCleo"
    
End Sub

Open in new window


I highlighted frmCleo above because you may not realize it but frmKeno seems to be an almost exact (it could be exact) copy of frmCleo. Why has that been done rather than just adding code to frmCleo to do whatever special thing(s) you do in frmKeno?

Should i upload the latest code-project?
Yes, make the change above and then upload it again.

Finally you'll find my email address in my profile. Send me an email because I'd like to talk with you offline.
0
 

Author Closing Comment

by:isnoend2001
Comment Utility
Thanks

I added the code you provided to

Sub UpdateNumber
it seems a lot closer however unselecting marked numbers seems to need tweaking.
I will upload the version i am coding now.
0
 

Author Comment

by:isnoend2001
Comment Utility
project uploaded
For-EE2-4-14.zip
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
I can't get over wanting to fix the problem I described in post ID: 39833232. I believe you can reproduce the problem if you select a number and then quickly release the mouse while still moving the cursor. That would be easy to fix using the flexCleo's MouseUp event but for some reason that event doesn't fire when the mouse is release. Let me know if you can reproduce the problem and if you can would you be willing to have the code changed so that the "dragging" only happens when the Right mouse button is clicked?
0
 

Author Comment

by:isnoend2001
Comment Utility
Thanks Martinliss
I am replying to your email now. I will be back
0
 

Author Comment

by:isnoend2001
Comment Utility
Thanks MartinLiss
I don't have that problem, but it seems that clicking and dragging on frmKeno is smoother.
I copied the code from it, don't see why it is different. you can open that form from frmCleo
by clicking the the button 20 Card keno top left of form
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
Here are some suggestions for improving your code.

Naming variables and controls
Note that this is the way I name them and while it's not the only way, it is probably the most popular way. You can choose some other way if you like, but the important thing is to be consistent. When you name a variable properly you should be able to tell three things at a glance:
1. Where the variable is defined (doesn't apply to controls)
2. What type of variable or control it is
3. What the variable or control is for (at least in general)

My variables look like this
stttxxxxxxxxxxxxxxx

where 's' is the scope of the variable, 'ttt' is the type and 'xxx' is the descriptive name. Some examples are:

1) intSelectedCount: Here the "g" indicates that the variable is defined in a code module and hence has global scope. Variables defined in code modules are normally defined as Public.  The "int" (which is always all lower case) indicates that the variable is defined as Integer. Some other possibilities are:
str = String
lng = Long
dbl = Double
cur = Currency
etc.
and for controls
lbl = Label
frm = Form
fra = Frame
grd = some type of grid ("flex" is fine and actually may be better)
txt = Textbox
etc.

b = Boolean. Sometimes "is" is used for readability. For example If isSelected Then blah

2) mbValueSelected: The "m" indicates that the variable is defined at the top of a form module. Variables of this type should always be defined as Private. (Dim is functionally the same as Private but it's use for form-level variables is frowned on).

3) intCount: The lack of a g or m prefix indicates that the variable is local to the Sub or Function where it is defined.

Formatting Code
Properly formatting code makes the code much easier to follow. Consider the following small coder snippet.
      If mSessionRunsMade = False Then
      lblCredit = gCleoNewGameCredits 'no runs made so load start credits to lblcredit
      lblBet = 0
      If Not InStr(lblCredit, "$") Then
      lblCredit = CreditMode1String(lblCredit, mBetMode)
       Else
        lblCredit = CreditMode0String(lblCredit, mBetMode)
        End If
     End If

Open in new window

As is it's not too difficult to follow but at first glance it does take a second or two to understand what's going one and seconds can add up. Here is the same code properly formatted and I think you'll agree it's easier to follow.
      If mSessionRunsMade = False Then
        lblCredit = gCleoNewGameCredits 'no runs made so load start credits to lblcredit
        lblBet = 0
        If Not InStr(lblCredit, "$") Then
            lblCredit = CreditMode1String(lblCredit, mBetMode)
        Else
            lblCredit = CreditMode0String(lblCredit, mBetMode)
        End If
     End If

Open in new window

0
 

Author Comment

by:isnoend2001
Comment Utility
thanks for the info MartinLiss
Just noticed that if in auto play mode and a win is adding up(rotating Labels-Sound) then
the next run starts before the labels are done rotating so i need to make a boolean for the next run to wait until win is added up
After reading you information
I am thinking mbolWaitforWintoFinish as boolean
m for form level
bol for boolean
What do you think ?
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
I've never seen "bol" used for Boolean and I think "b" is better but as long as you are consistent it's OK. I also think that mbolWaitingforWintoFinish or mbolRotationFinished would be better because it would "read" better as in

If mbolWaitingorWintoFinish Then...

or

If mbolRotationFinished Then...
0
 

Author Comment

by:isnoend2001
Comment Utility
Thanks
i also think b is better
btw:
Every one of my functions, subs will have error handlers and line numbers before project is done
0
 

Author Comment

by:isnoend2001
Comment Utility
What do you think of this:
Sub StartCleo()
 Dim Replay As Boolean
Restart:
  If mbWaitforWinToFinish = True Then
    Do Until mbWaitforWinToFinish = False
    DoEvents
loop
  End If
0
 

Author Comment

by:isnoend2001
Comment Utility
Hi MartinLiss
I am in the process of renaming variables and formatting code
How would you name this form level variable ?
Dim sndData() As Byte
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
Private mbytData As Byte

"Data" could be changed to something more meaningful.
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
Sub StartCleo()
 Dim Replay As Boolean
Restart:
  If mbWaitforWinToFinish = True Then
    Do Until mbWaitforWinToFinish = False
Is there some more code here? There should be.
    DoEvents
loop
  End If
0
 

Author Comment

by:isnoend2001
Comment Utility
Thanks
0
 

Author Comment

by:isnoend2001
Comment Utility
I put that as a stall to wait
When auto play was going i noticed that on a win the win labels rotate the amount
of the win and play a sound. I noticed that the next randomize would start selecting numbers
before the numbers were done rotating so i put this after the timer was done rotating the labels:
mbWaitforWinToFinish = False
It seems to fix the problem
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
It seems to fix the problem

That's good:)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 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

10 Experts available now in Live!

Get 1:1 Help Now