2 Replies Latest reply on Jan 16, 2018 12:51 AM by msj_

    Resizing and repositioning symbols on selection

    msj_

      Hi all,

       

      I have a number of XYPlots and Trends which have the naming formats:

      scatter_cu_1     scatter_pa_1     scatter_pp_1  (the numbers on the end indicate that they are stacked together and need to zoom in/out at same time)

      trend_cu_1     trend_pa_1     trend_pp_1

       

      I am currently using the following codes to resize and reposition of them together, using public variables pos_t_top & pos_t_left for trends and pos_s_top & pos_s_left for scatter plots (XYplots)

      The problem is that if I zoom in on two different sets of plots, the second zooming script will override the previously saved public variables for positions. How can I move the large symbol back in place before enlarging the selected symbol?

       

      Dim WithEvents sctr_plots As XYPlot

      Dim WithEvents trnds As trend

      Public pos_s_top As Integer

      Public pos_s_left As Integer

      Public pos_t_top As Integer

      Public pos_t_left As Integer

       

      Private Sub Display_SelectionChange()
          Dim symb As Symbol
         
          For Each symb In SelectedSymbols
              If symb.Type = pbSymbolXYPlot Then 'for scatter
                  Set sctr_plots = symb
              ElseIf symb.Type = pbSymbolTrend Then 'for trends
                  Set trnds = symb
              End If
          Next symb

      End Sub

       

      Private Sub sctr_plots_Click(ByVal lvarX As Long, ByVal lvarY As Long)

          'Find all 3 scatter plots in the same set to zoom in/out together

          'Zoom in to 1000x1000 if it is 100x100, vice versa

          Dim scatter As Symbol

          Dim j As Integer

         

          j = VBA.Mid(sctr_plots.Name, 12)

          For Each scatter In Symbols

              With scatter

              If .Type = pbSymbolXYPlot And .Height = 1000 Then

                  .Height = 100:     .Width = 100:     .Top = pos_s_top:     .Left = pos_s_left

              ElseIf .Type = pbSymbolXYPlot And VBA.Mid(.Name, 12) = j And .Height = 100 Then

                  pos_s_top = .Top 'save current position top

                  pos_s_left = .Left 'save current position left

                  .Height = 1000:    .Width = 1000:    .Top = 13000:    .Left = -14700

              End If

              End With

          Next scatter

          SelectedSymbols.Remove 1

      End Sub

       

      Trend_click is similar to the click event code above, except for width is 200/2000 for zooming in and out.

        • Re: Resizing and repositioning symbols on selection
          knightk

          Just quickly looking at it, my gut feeling is you need a couple more variables, a Boolean to know that something was previously zoomed in and which number it was, so if you click a new trend and your new TrendAlreadyZoomed (or similar!) Boolean is true, then get the number of the current zoomed trends and run the code that is in sctr_click (I would separate this out to another sub that takes value j, so if your Boolean is true you want to run it twice, once with j as your saved integer, and second with the integer of the current clicked symbol, otherwise just run it once with the latter). Does that make sense?

            • Re: Resizing and repositioning symbols on selection
              msj_

              Thanks for those directions. I defined a public boolean and public integer All trends and XYplots with the same integer suffix now zoom in and out together.

              The only problem is that in case of resetting project, any saved public variables gets cleared. During normal use it's fine.

               

               

              Private Sub Display_Open()
                  zoomed_in = False ' default Boolean as false, there is also private sub to call zoom_out() before close and save of display
              End Sub

               

               

              Private Sub Display_SelectionChange()
                  With SelectedSymbols.Item(1)
                  If .Height = 1000 Then
                      Call zoom_out
                      zoomed_in = False
                      SelectedSymbols.RemoveAll
                      Exit Sub
                  ElseIf .Type = pbSymbolXYPlot And .Height = 100 Then
                      zoom_num = VBA.Mid(.Name, 12)
                  ElseIf .Type = pbSymbolTrend And .Height = 100 Then
                      zoom_num = VBA.Mid(.Name, 10)
                  Else
                      Exit Sub
                  End If
                  End With
                 
                  Call zoom_out
                  Call zoom_in(zoom_num)
                  zoomed_in = True
                  SelectedSymbols.RemoveAll

              End Sub

               

               

               

              Sub zoom_out()
                  Dim symb As Symbol

                  For Each symb In Symbols
                      With symb
                      If .Type = pbSymbolTrend And .Height = 1000 Then
                          .Height = 100: .Width = 200: .Top = pos_t_top: .Left = pos_t_left
                      ElseIf .Type = pbSymbolXYPlot And .Height = 1000 Then
                          .Height = 100: .Width = 100: .Top = pos_s_top: .Left = pos_s_left
                      End If
                      End With
                  Next symb
              End Sub

               

               

              Sub zoom_in(zoom_num As Integer)
                  Dim symb As Symbol

                  For Each symb In Symbols
                      With symb
                      If .Type = pbSymbolTrend And VBA.Mid(.Name, 10) = zoom_num Then
                          .Height = 1000: .Width = 2000: pos_t_top = .Top: pos_t_left = .Left: .Top = 13000: .Left = -12900
                      ElseIf .Type = pbSymbolXYPlot And VBA.Mid(.Name, 12) = zoom_num Then
                          .Height = 1000: .Width = 1000: pos_s_top = .Top: pos_s_left = .Left: .Top = 13000: .Left = -14700
                      End If
                      End With
                  Next symb
              End Sub