Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Trying to undo labels


I am writing a macro which loads in a picture and makes a "cross"
wherever the user clicks on the picture. I don't know how many times
they will click, so I use the following code to make 2 labels, 1
vertical and 1 horizontal, which intersect in the middle to make a
cross.

HorHold = HorHold + 1
Set Lbl = Controls.Add("Forms.Label.1", "lblLabel" & HorHold,
True)
With Lbl
..Top = Y
..Left = X - 6
..Height = 1
..Width = 12
..BorderStyle = 1
..BorderColor = vbRed
End With

'for the second part of the "X", we need to give it a unique name
'so we use VertHold which starts at 900 and won't intersect
HorHold

VertHold = VertHold + 1
Set Lbl = Controls.Add("Forms.Label.1", "lblLabel" & VertHold,
True)
With Lbl
..Top = Y - 6
..Left = X
..Height = 12
..Width = 1
..BorderStyle = 1
..BorderColor = vbRed
End With


This works great. I also want to be able to undo any mistakes. I put an
"Undo" button on the userform with the following code:

'now we have to clear off the red X

Controls("lblLabel" & HorHold).Visible = False
Controls("lblLabel" & VertHold).Visible = False

HorHold = HorHold - 1
VertHold = VertHold - 1


The idea is that each time they hit "Undo", they can "step back" over
all their marks and undo them.

Here is my problem: this works at first, but not later. That is, say I
click 4 times and the last 2 are mistakes. So, I hit "Undo" twice, and
each time the cross disappears just like it is supposed to. So, now I
have only 2 crosses on the image. Then, I click twice more to make two
more crosses. However, if I hit "undo" nothing happens! Then, I hit
"undo" again and nothing happens. However, when I hit it a third time,
mark #2 disappears! So, it seems to be stepping backwards like it
should, but it doesn't erase the first two NEW marks, but when I step
back far enough I can erase marks that have never been erased.

Sorry if this is confusing, it's a difficult thing to explain. Any
ideas?


--
timspier
------------------------------------------------------------------------
timspier's Profile: http://www.excelforum.com/member.php...o&userid=32090
View this thread: http://www.excelforum.com/showthread...hreadid=521439

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Trying to undo labels

I think problem is that you are not deleting the controls just making them
invisible BUT you sre decrementing the counters HorHold + VertHold as if they
were deleted.

I changed your Undo code to use additional counters/pointer variables for
the Undo process as follows

Private Sub UNDOButn_Click()
UndoH = HorHold
UndoV = VertHold
If (UndoH 0) And (UndoV 0) Then
KeepGoing = True
While KeepGoing And UndoH 0
If Controls("lblLabel" & UndoH).Visible Then
KeepGoing = False
Else
UndoH = UndoH - 1
UndoV = UndoV - 1
End If
Wend
If Not KeepGoing Then
Controls("lblLabel" & UndoH).Visible = False
Controls("lblLabel" & UndoV).Visible = False
End If
'HorHold = HorHold - 1
'VertHold = VertHold - 1
End If
End Sub

Seems to work

HTH
"timspier" wrote:


I am writing a macro which loads in a picture and makes a "cross"
wherever the user clicks on the picture. I don't know how many times
they will click, so I use the following code to make 2 labels, 1
vertical and 1 horizontal, which intersect in the middle to make a
cross.

HorHold = HorHold + 1
Set Lbl = Controls.Add("Forms.Label.1", "lblLabel" & HorHold,
True)
With Lbl
.Top = Y
.Left = X - 6
.Height = 1
.Width = 12
.BorderStyle = 1
.BorderColor = vbRed
End With

'for the second part of the "X", we need to give it a unique name
'so we use VertHold which starts at 900 and won't intersect
HorHold

VertHold = VertHold + 1
Set Lbl = Controls.Add("Forms.Label.1", "lblLabel" & VertHold,
True)
With Lbl
.Top = Y - 6
.Left = X
.Height = 12
.Width = 1
.BorderStyle = 1
.BorderColor = vbRed
End With


This works great. I also want to be able to undo any mistakes. I put an
"Undo" button on the userform with the following code:

'now we have to clear off the red X

Controls("lblLabel" & HorHold).Visible = False
Controls("lblLabel" & VertHold).Visible = False

HorHold = HorHold - 1
VertHold = VertHold - 1


The idea is that each time they hit "Undo", they can "step back" over
all their marks and undo them.

Here is my problem: this works at first, but not later. That is, say I
click 4 times and the last 2 are mistakes. So, I hit "Undo" twice, and
each time the cross disappears just like it is supposed to. So, now I
have only 2 crosses on the image. Then, I click twice more to make two
more crosses. However, if I hit "undo" nothing happens! Then, I hit
"undo" again and nothing happens. However, when I hit it a third time,
mark #2 disappears! So, it seems to be stepping backwards like it
should, but it doesn't erase the first two NEW marks, but when I step
back far enough I can erase marks that have never been erased.

Sorry if this is confusing, it's a difficult thing to explain. Any
ideas?


--
timspier
------------------------------------------------------------------------
timspier's Profile: http://www.excelforum.com/member.php...o&userid=32090
View this thread: http://www.excelforum.com/showthread...hreadid=521439


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Trying to undo labels

My code doesn't take account of your mechanism for initial value of VertHold
= 900
I presumed the lables were named differently and both incremented from Zero

Nick

"timspier" wrote:


I am writing a macro which loads in a picture and makes a "cross"
wherever the user clicks on the picture. I don't know how many times
they will click, so I use the following code to make 2 labels, 1
vertical and 1 horizontal, which intersect in the middle to make a
cross.

HorHold = HorHold + 1
Set Lbl = Controls.Add("Forms.Label.1", "lblLabel" & HorHold,
True)
With Lbl
.Top = Y
.Left = X - 6
.Height = 1
.Width = 12
.BorderStyle = 1
.BorderColor = vbRed
End With

'for the second part of the "X", we need to give it a unique name
'so we use VertHold which starts at 900 and won't intersect
HorHold

VertHold = VertHold + 1
Set Lbl = Controls.Add("Forms.Label.1", "lblLabel" & VertHold,
True)
With Lbl
.Top = Y - 6
.Left = X
.Height = 12
.Width = 1
.BorderStyle = 1
.BorderColor = vbRed
End With


This works great. I also want to be able to undo any mistakes. I put an
"Undo" button on the userform with the following code:

'now we have to clear off the red X

Controls("lblLabel" & HorHold).Visible = False
Controls("lblLabel" & VertHold).Visible = False

HorHold = HorHold - 1
VertHold = VertHold - 1


The idea is that each time they hit "Undo", they can "step back" over
all their marks and undo them.

Here is my problem: this works at first, but not later. That is, say I
click 4 times and the last 2 are mistakes. So, I hit "Undo" twice, and
each time the cross disappears just like it is supposed to. So, now I
have only 2 crosses on the image. Then, I click twice more to make two
more crosses. However, if I hit "undo" nothing happens! Then, I hit
"undo" again and nothing happens. However, when I hit it a third time,
mark #2 disappears! So, it seems to be stepping backwards like it
should, but it doesn't erase the first two NEW marks, but when I step
back far enough I can erase marks that have never been erased.

Sorry if this is confusing, it's a difficult thing to explain. Any
ideas?


--
timspier
------------------------------------------------------------------------
timspier's Profile: http://www.excelforum.com/member.php...o&userid=32090
View this thread: http://www.excelforum.com/showthread...hreadid=521439


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Trying to undo labels


Plugged it in, seems to work. Thanks a ton!


--
timspier
------------------------------------------------------------------------
timspier's Profile: http://www.excelforum.com/member.php...o&userid=32090
View this thread: http://www.excelforum.com/showthread...hreadid=521439

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007 text labels in category axis - missing labels Boris Charts and Charting in Excel 3 December 5th 08 04:33 PM
How do i create labels so, could only move and type in labels only kloniki Excel Discussion (Misc queries) 1 April 12th 08 06:04 AM
Icons __AND__ labels?! How do I get rid of toolbar LABELS! shamblinthru New Users to Excel 2 March 19th 07 09:19 PM
UNDO - how many times can I UNDO? Jane Excel Worksheet Functions 2 May 19th 05 03:03 AM
Why is my undo function in Excel only can undo the last 1 or 2 ch. 1111111111111111111111111111111111111111 Excel Worksheet Functions 1 November 24th 04 11:13 AM


All times are GMT +1. The time now is 06:10 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"