Disappearance of the rectangle when the Timer finishes.

Artik

Active Member
Joined
Jun 5, 2012
Messages
286
I create a work schedule using graphical objects. Instead of laboriously inserting, for example, a value of 1 into multiple cells for a given worker, I drag a rectangle to the required size, and the values of 1 are inserted automatically in the cells where the object is located. In the solution, I used a stable Timer class written by Karl E. Peterson, which keeps track of when I have finished dragging the rectangle.
To schedule the working hours of a specific employee, there are two steps: 1. click with the LEFT mouse button on the specified rectangle to select it 2. change the size and/or position of the rectangle.
In the solution, I used a condition (in the Timer1_Timer procedure) that if the position and/or size of the rectangle was not changed within 10 seconds, after selecting the object, the Timer is turned off. I know that I could dispense with this condition, in which case the Timer would run indefinitely (until one of the workbook's events is detected), but I'm not sure I can predict all possible user behaviors to prevent Excel from crashing.

Problem description.
If, after selection, I grab a rectangle with the mouse and hold the mouse button down for more than 10 seconds, the Timer1_Timer event turns off the Timer. At this point, after releasing the mouse button, the rectangle "disappears" (becomes invisible) although it still exists on the sheet. Looking through the "Selection Pane" you can see that the object is not hidden, but is nevertheless invisible. When selecting an object from the list in the "Selection Pane", a "handicapped" rectangle (without filling) appears on the sheet. Strangely enough, when I click on another rectangle in the sheet, automagically this "handicapped" (but already with filling) appears on the sheet, but the values in the cells under the rectangle may not reflect its actual position and size. I tried various tricks with screen refresh, but it did not give positive results.
I am primarily interested in the root of the problem. What is the reason that the rectangle disappears? I would also appreciate if someone can find a solution to the problem (other than removing the condition from the Timer1_Timer procedure).

Schedule.xlsm

Artik
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Doesn't happen for me. Since we're using different pc's I suggest you look into what's different about your Excel & Windows versions and your bitness of Office. You probably should post that info when a lot of API's are used in your code and you're having issues.
I doubt it would be hardware related.
 
Upvote 0
Sorry for the delay. I was away for a few days.
When you grab an object with the mouse and hold for more than 10 sec the object returns to its position and is still visible. The problem starts when you CHANGE the size of the rectangle by grabbing one of the handles and holding down until 10 sec has elapsed.

Artik
 
Upvote 0
Now I see what you mean, and yes I was not doing that exactly. I plan to take a look later to see if I can figure out why. In the meantime, anyone else should feel free to dive in if they're willing to download your file. Some people just won't. I suppose you have 2 options at this point - don't hold the button down 10 seconds and it probably will be OK. The other might be to edit code to select another object because that seems to restore the "invisible" object. I quoted that because I suspect it is an issue of shape width and not visibility so you might look again at the code to see what governs the object width. Perhaps you could debug.print the shapes width or visibility properties as in
Debug.Print sheets("Arkusz1").shapes(1).width
to test the theory of width being 0 or being invisible. Have to run now...
 
Upvote 0
Ha, however, it is worth going away for a few days of rest.
Admittedly, I don't have the answer to why the rectangle disappears, but I do have the answer to how to make it not disappear. By the way, the code has simplified a bit. The change affects only the Timer1_Timer procedure. Here is its new form:
VBA Code:
Private Sub Timer1_Timer()
    Dim Shp As Object
    Dim rngProps As Range

    If Not Application.EnableEvents Then Application.EnableEvents = True

    On Error Resume Next
    Set Shp = Selection

    If TypeName(Shp) <> "Rectangle" Then Exit Sub

    If Timer1.TimeElapsed > 10 ^ 4 Then    '10 sek
        Application.Run "wksPlan.Timer_Off"
        Application.OnTime Now, "SaveShp"
    Else
        Set rngProps = wksListy.Range("tbl_Properties").Columns(2).Cells
        Set Shp = Shp.ShapeRange(1)

        If Round(Shp.Top, 2) <> rngProps(1).Value Or Round(Shp.Left, 2) <> rngProps(2).Value Or _
           Round(Shp.Height, 2) <> rngProps(3).Value Or Round(Shp.Width, 2) <> rngProps(4).Value Then
            Application.Run "wksPlan.Timer_Off"
            Application.OnTime Now, "SaveShp"
        End If
    End If
End Sub

Thank you for your willingness to help.

Artik
 
Upvote 0
Solution
Glad to see you have a solution. I was leaning towards Obj being a part of the problem, but found it impossible to deal with the msoButtonDown state when using the mouse to navigate through the application windows:
VBA Code:
 If Obj.State = msoButtonDown Then
      Obj.Execute    'snap off
 End If
You have edited the code substantially from what it was. Kudos to you for figuring it out.
BTW, I also found that stepping through the code and flipping back and forth between code and sheet windows tended to not make the shape disappear from view, but I didn't figure out why.
 
Upvote 0
While observing the code execution, I noticed that the problem started when the mouse button was released. I came to the conclusion that the SaveShp procedure needs to be called via OnTime, which will start it already in a new thread.

Artik
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,191
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top