Autres calcul de position d’écart left top qui déraille

patricktoulon

XLDnaute Barbatruc
Bonjour a tous
pour calendar je suis en train de faire un patch qui me permettra de respecter les positions en forcant une marge left et top

sauf que dans l'exemple qui suit ( 2 userforms simple) le calcul ne fait pas la différence en - ou +

le calcul additionne tout le temps ??????????????????:oops:🤔🤔🤔🤔🤔🤔

  1. ouvrez l'userform ,cliquez sur le bouton rouge
  2. le userform2 s'affiche replacez le en coin haut et gauche de B3
  3. et recliquez sur le bouton rouge du uf1

j'ai tout essayé même avec sgn rien y fait c'est un truc de fou
 

Pièces jointes

  • test calcul position.xlsm
    22.4 KB · Affichages: 15
Solution
allez on garde comme ça
merci a tous
VB:
Private Sub showW_Click()
    With uf2
        Dim L1#, T1#, OperX&, OperY&
        If Not .Visible Then
            ddecx = 0: ddecy = 0    '1er lancement
            .StartUpPosition = 0
            With ActiveWindow
                PtoPx = (.ActivePane.PointsToScreenPixelsY(72) - .ActivePane.PointsToScreenPixelsY(0)) / 72    'coeff point to pixel
                Z = .Zoom / 100
                L1 = (.ActivePane.PointsToScreenPixelsX(Int([b3].Left)) / PtoPx) * Z    'placement partie mobile
                T1 = .ActivePane.PointsToScreenPixelsY(Int([b3].Top)) / PtoPx * Z
            End With
            .Left = L1
            .Top = T1
            .Show 0
            ddecx = L1
            ddecy...

fanch55

XLDnaute Barbatruc
Salut Patrick,
En XL2019, tout semble fonctionner comme tu l'attends .
pt.gif
 

patricktoulon

XLDnaute Barbatruc
re
bonjour @fanch55
ben non puisque les textbox reçoivent la nouvelle position hors c'est la différence entre la première position et la 2d qui devrait atterrir dans les textboxs
je dirais même pire il additionne au lieu de soustraire selon le cas
si j'ai mon uf2 a 123 de left et que le repositionne à 128 de left je devrait avoir dans ddecx 5
si j'ai mon uf2 a 128 de left et que le repositionne à 123 de left je devrait avoir dans ddecx -5
hors dans les deux sens il additionne j'obtiens 133
 

fanch55

XLDnaute Barbatruc
re
bonjour @fanch55
ben non puisque les textbox reçoivent la nouvelle position hors c'est la différence entre la première position et la 2d qui devrait atterrir dans les textboxs
je dirais même pire il additionne au lieu de soustraire selon le cas
si j'ai mon uf2 a 123 de left et que le repositionne à 128 de left je devrait avoir dans ddecx 5
si j'ai mon uf2 a 128 de left et que le repositionne à 123 de left je devrait avoir dans ddecx -5
hors dans les deux sens il additionne j'obtiens 133
Si je comprend bien, les textbox doivent avoir la différence entre les deux dernières positions ?
 

patricktoulon

XLDnaute Barbatruc
c'est bon @fanch55 avait raison la remise a zero n’était pas au bon endroit
et je pleure misère depuis une heure 😅😅😅😅
maintenant effectivement selon si en positif ou negatif il faut soustraire ou additionner me reste a aménager le sgn
j'ai essayé ça mais non 😂ca marche pas dans tout les sens

VB:
Private Sub showW_Click()
     With uf2
        Dim L1#, T1#

        If Not .Visible Then
          ddecx = 0: ddecy = 0 '1er lancement
     .StartUpPosition = 0
            With ActiveWindow
                PtoPx = (.ActivePane.PointsToScreenPixelsY(72) - .ActivePane.PointsToScreenPixelsY(0)) / 72    'coeff point to pixel
                Z = .Zoom / 100
                L1 = (.ActivePane.PointsToScreenPixelsX(Int([b3].Left)) / PtoPx) * Z    'placement partie mobile
                T1 = .ActivePane.PointsToScreenPixelsY(Int([b3].Top)) / PtoPx * Z
            End With
            .Left = L1
            .Top = T1
            .Show 0
            ddecx = L1
            ddecy = T1
        Else
               
              operx = Sgn(uf2.Left - CDbl(ddecx))
              opery = Sgn(uf2.Top - CDbl(ddecy))
            
            ddecy = (opery * uf2.Top) - CDbl(ddecy)
            ddecx = (operx * uf2.Left) - CDbl(ddecx)
        End If
    End With
End Sub
 

patricktoulon

XLDnaute Barbatruc
oui je sais ça @Dranreb
j'aurai voulu faire avec sgn mais je n'ai pas l'inversion
je fait facon neuneu
VB:
Private Sub showW_Click()
     With uf2
        Dim L1#, T1#

        If Not .Visible Then
          ddecx = 0: ddecy = 0 '1er lancement
     .StartUpPosition = 0
            With ActiveWindow
                PtoPx = (.ActivePane.PointsToScreenPixelsY(72) - .ActivePane.PointsToScreenPixelsY(0)) / 72    'coeff point to pixel
                Z = .Zoom / 100
                L1 = (.ActivePane.PointsToScreenPixelsX(Int([b3].Left)) / PtoPx) * Z    'placement partie mobile
                T1 = .ActivePane.PointsToScreenPixelsY(Int([b3].Top)) / PtoPx * Z
            End With
            .Left = L1
            .Top = T1
            .Show 0
            ddecx = L1
            ddecy = T1
        Else
              
              'operx = Sgn(uf2.Left - CDbl(ddecx))
              'opery = Sgn(uf2.Top - CDbl(ddecy))
            
            'ddecy = uf2.Top + (opery * CDbl(ddecy))
            'ddecx = uf2.Left + (operx * CDbl(ddecx))
        
        If uf2.Left < CDbl(ddecx) Then operx = "-"
         ddecx = operx & Abs(uf2.Left - CDbl(ddecx))
        If uf2.Top < CDbl(ddecy) Then opery = "-"
        ddecy = opery & Abs(uf2.Top - CDbl(ddecy))
      
        
        
        
        End If
    End With
End Sub
 

patricktoulon

XLDnaute Barbatruc
allez on garde comme ça
merci a tous
VB:
Private Sub showW_Click()
    With uf2
        Dim L1#, T1#, OperX&, OperY&
        If Not .Visible Then
            ddecx = 0: ddecy = 0    '1er lancement
            .StartUpPosition = 0
            With ActiveWindow
                PtoPx = (.ActivePane.PointsToScreenPixelsY(72) - .ActivePane.PointsToScreenPixelsY(0)) / 72    'coeff point to pixel
                Z = .Zoom / 100
                L1 = (.ActivePane.PointsToScreenPixelsX(Int([b3].Left)) / PtoPx) * Z    'placement partie mobile
                T1 = .ActivePane.PointsToScreenPixelsY(Int([b3].Top)) / PtoPx * Z
            End With
            .Left = L1
            .Top = T1
            .Show 0
            ddecx = L1
            ddecy = T1
        Else
            OperX = Sgn(uf2.Left - CDbl(ddecx)): ddecx = OperX * (Abs(uf2.Left - CDbl(ddecx)))
            OperY = Sgn(uf2.Top - CDbl(ddecy)): ddecy = OperY * (Abs(uf2.Top - CDbl(ddecy)))
        End If
    End With
End Sub
 

Statistiques des forums

Discussions
312 231
Messages
2 086 455
Membres
103 216
dernier inscrit
LoshR7