PDA

View Full Version : id/count of a created shape/sheet and taken by the maus click(OnAction) are different



ivan.kamenec
11-18-2013, 04:54 PM
The name:
id/count of a shape(Excel sheet) from the creation and taken by the maus click(OnAction) are different/not compatible;

rem.: nearly not understandable, my fault or a system property/why? (below/2.b);
rem.: the comprehensive test by two macros ma04/ma05, s. chapter 5/enclosure;
kai/131118/00

the specification/description:
1. PC environment:
Windows 7 Proffesional/Ms Office 2010 Proffesional

2. the goal
general: there are (general) two posibilities of a shapes(Excel) identification after a mouse click on the object/shape
which were created e.g. by a Shapes.AddLine and equiped with a .name and an onAction proporties;
a) by .name,
– but the user must keep the whole control of its value;
b) by id/count:
– the id/count automatically specified/controlled by a creation, but not compatible with an id/onAction (maus click);
– question: nearly not understandable, my fault or a system property/why/how to solve it?

3. the task status:
– the short description, only the main steps; s. the chapter 4;
– the comprehensive test code by two macros ma04 (creation)/ma05(onAction), s. the chapter 5;

4. the general description
there are two possibilities

while the Shapes.name ("myName") of the shape specified within the shape creation/Shapes.AddLine
by .Name = "myName", then confirmed through the functions ObjShape.Count/ObjShape(count).Name.
(all in the step 4.a creation)
is the same with the one obtained after mouse click on the object/shape in the sub/On Action (ma05)
ObjShapes.Shapes(Application.Caller).Name;
– the same is not valid for the ObjShapes.id, see below 2. the manual choice;


4.a the creation; the function ok


Set ObjLine = ObjSheet.Shapes.AddLine(x1, y1, x2, y2)
stTx1 = stTx0 & Format(inIn0, "00000")

With ObjLine
.Name = stTx1
End With

ObjLine.OnAction = "Ma05"

' checks of the function: name/id.count
inIn2 = ObjShape.Count
stTx2 = ObjShape(inIn2).Name

the result:

.name: stTx2 = stTx1: ok
.id/cont: inIn2: automatically control: id.count(actual) = id.count(previouse/last) + 1 : ok

4.b the onAction utilisation/sub ma05


' .name: stTx0:
stTx0 = ObjSheet.Shapes(Application.Caller).Name
' id.count: inIn0, inIn1/below: usually(not always) + 1 higher; why?
inIn0 = ObjSheet.Shapes(Application.Caller).ID
inIn1 = ObjSheet.Shapes.Range(Array(stTx0)).ID

' shapes object indication by a manual choice
' by .stTx0 = .name: right, ok
ObjSheet.Shapes.Range(Array(stTx0)).Select
' by id/count: in/in0/inIn1: ????, not ok
ObjSheet.Shapes(inIn0).Select

' but with the inIn2 value taken from ad 4.a (here the manual input) is ok,
' but it differs from inIn0/inIn2 (??!!)
ObjSheet.Shapes(inIn2).Select

the steps of the example:
1. creation/2. the manual choice


5 the whole test example
5.1 sub ma04: Creation of a group of lines, log (both in an excel activeSheet); all ok;

a) the shapes/line name:
– input: stTX1: full by user
– result: stTx2 (confirmed after the creation) = stTx1
b) id.count of the shapes/object
– input: automatick: next to actual state: id.count(actual) = id.count(previous) + 1
– result: inIn2 confirmed after the creation;

rem.: all in an active Excel sheet

Sub Ma04()

Public stTx0 As String
Public stTx1 As String
Public stTx2 As String
Public inIn0 As Integer
Public inIn1 As Integer
Public inIn2 As Integer

Public ObjObj As Object
Public ObjSheet As Object
Public ObjShape As Object
Public ObjLine As Shape

Public inLn0 As Integer
Public inSp0 As Integer

Set ObjObj = ActiveWorkbook
Set ObjSheet = ObjObj.ActiveSheet
Set ObjShape = ObjSheet.Shapes

stTx0 = "aa"
inIn0 = 1000

dx = 20
dy = 12
x1 = 22
y1 = 100

inLn0 = 10

a10:
' dy = 12
x1 = x1 + dx
x2 = x1 + 50
y1 = y1 + dy
y2 = y1

inLn0 = inLn0 + 1
inSp0 = 10
inIn0 = inIn0 + 1

Cells(inLn0, inSp0).Value = x1
Cells(inLn0, inSp0 + 1).Value = x2
Cells(inLn0, inSp0 + 2).Value = y1
Cells(inLn0, inSp0 + 3).Value = y2

Cells(inLn0, inSp0 + 4).Value = stTx0
Cells(inLn0, inSp0 + 5).Value = inIn0

Set ObjLine = ObjSheet.Shapes.AddLine(x1, y1, x2, y2)
stTx1 = stTx0 & Format(inIn0, "00000")

With ObjLine
.Name = stTx1

End With

ObjLine.Line.ForeColor.RGB = RGB(0, 255, 0)
ObjLine.Line.Visible = msoTrue
ObjLine.Line.Weight = 2
ObjLine.Line.Visible = msoTrue
ObjLine.Line.Style = msoLineSingle

ObjLine.OnAction = "Ma05"

' the results: name/id.count
inIn2 = ObjShape.Count
stTx2 = ObjShape(inIn2).Name

Cells(inLn0, inSp0 + 6).Value = inIn2
Cells(inLn0, inSp0 + 7).Value = stTx2

if inIn0 > 1005 then goto a20

GoTo a10

a20:

Stop
Exit Sub
End Sub

5.2 sub ma05: manual Choice of the shape: automaick ma05: onAction from creation
description:
a) shape name:
– stTx0: matches to the actual choice; ok
b) id.count:
– inIn0, inIn1 usually/not alwayes by + 1 higher then actual state: why?
– inIn2: manual setting of the choice (ok)


sub ma05()
'
Stop
Set ObjObj = ActiveWorkbook
Set ObjSheet = ObjObj.ActiveSheet

' stTx0:
stTx0 = ObjSheet.Shapes(Application.Caller).Name
' inIn0, inIn1: alwayes + 1 higher; why?
inIn0 = ObjSheet.Shapes(Application.Caller).ID
inIn1 = ObjSheet.Shapes.Range(Array(stTx0)).ID

' shapes indication of a manual choice
' right, ok
ObjSheet.Shapes.Range(Array(stTx0)).Select
' ????, not ok
ObjSheet.Shapes(inIn0).Select

stop
' inIn2 = ... id.count (manual input of a chosed shape): good result, ok
ObjSheet.Shapes(inIn2).Select


Exit Sub

End Sub

SamT
11-20-2013, 08:20 AM
Rez bump