?
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
Medium Priority
?
237 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
22 Comments
 
LVL 50

Expert Comment

by:Martin Liss
ID: 39833085
I'm looking at it now.
0
 
LVL 50

Expert Comment

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

by:isnoend2001
ID: 39833232
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 50

Expert Comment

by:Martin Liss
ID: 39833252
When I click the numbers rapidly VB may think I'm dragging.
0
 
LVL 50

Accepted Solution

by:
Martin Liss earned 2000 total points
ID: 39833852
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
ID: 39833958
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
ID: 39833987
project uploaded
For-EE2-4-14.zip
0
 
LVL 50

Expert Comment

by:Martin Liss
ID: 39837248
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
ID: 39837419
Thanks Martinliss
I am replying to your email now. I will be back
0
 

Author Comment

by:isnoend2001
ID: 39837539
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
 
LVL 50

Expert Comment

by:Martin Liss
ID: 39837563
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
ID: 39837611
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 50

Expert Comment

by:Martin Liss
ID: 39837655
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
ID: 39837675
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
ID: 39837688
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
ID: 39839591
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 50

Expert Comment

by:Martin Liss
ID: 39839609
Private mbytData As Byte

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

Expert Comment

by:Martin Liss
ID: 39839638
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
ID: 39839639
Thanks
0
 

Author Comment

by:isnoend2001
ID: 39839698
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 50

Expert Comment

by:Martin Liss
ID: 39839880
It seems to fix the problem

That's good:)
0

Featured Post

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!

Question has a verified solution.

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

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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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

809 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