Help fixing pic resize code

Started by sdaspenberg, March 07, 2011, 08:19:03 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

bobsupercow

sdaspenberg,

Everyone has to start somewhere. Paul was simply encouraging you to keep working at it since all the pieces you needed were there. You are in the right place. This forum is an excellent resource, but none of us can expect to always get full solutions posted in reply all of the time. After all, coding this stuff is what some people do for a living and it's not often you get that for free. That said, hopefully this will help you understand some of the concepts a little better.

Const = Constant which is a value that can not be changed after it is initialized. I used these to define your starting locations and spacing so that they can easily be modified in the future.

Basically this code loops through each of the shapes and sets the location = the current value of the x,y location variables. When it is done moving the shape, it increments the x value. It continues doing this until it reaches the special case that it has moved enough shapes to fill a row. "maxItemsPerRow" 

In the event that it is this special case, it does the following before moving to the next shape:
Resets the row counter = 1
Resets the xVal to its starting value (in this case = 2.1747)
Decrements the yVal by the vSpacing Constant.

This will work with any number of shapes. Hopefully that makes some more sense now. Good Luck with it.

I would suggest, since you're just beginning with programming that you add my above comments to the code as inline comments using the apostrophe ' character at the beginning of the line.


Sub ResizePics()
        Const startXVal = 2.1747
        Const startYVal = 9.2945
        Const width = 2.8398
        Const height = 2.1299
        Const hSpacing = 3.1633
        'You have yet to specify your vertical spacing.
        Const vSpacingModifier = 0.38
        Const vSpacing = height + vSpacingModifier
        Const maxItemsPerRow = 5
       
        Dim vsoShape As Visio.Shape
        Dim counter As Integer
        Dim xVal As Integer, yVal As Integer
       
        xVal = startXVal
        yVal = startYVal
        counter = 1
       
        For Each vsoShape In Application.ActiveWindow.Page.Shapes
            If vsoShape.CellsSRCExists(visSectionObject, visRowXFormOut, visXFormPinX, True) Then
                vsoShape.CellsSRC(visSectionObject, visRowXFormOut, visXFormPinX).FormulaU = xVal & " in"
                vsoShape.CellsSRC(visSectionObject, visRowXFormOut, visXFormPinY).FormulaU = yVal & " in"
                vsoShape.CellsSRC(visSectionObject, visRowXFormOut, visXFormWidth).FormulaU = width & " in"
                vsoShape.CellsSRC(visSectionObject, visRowXFormOut, visXFormHeight).FormulaU = height & " in"
                vsoShape.CellsSRC(visSectionObject, visRowXFormOut, visXFormLocPinX).FormulaU = "Width*0.5"
                vsoShape.CellsSRC(visSectionObject, visRowXFormOut, visXFormLocPinY).FormulaU = "Height*0.5"
                counter = counter + 1
                If counter > maxItemsPerRow Then
                    xVal = startXVal
                    yVal = yVal - vSpacing
                    counter = 1
                Else
                    xVal = xVal + hSpacing
                End If
            End If
        Next vsoShape
End Sub

sdaspenberg

bobsupercow,
thank you for all your help. I didn't mean to come across so angry in my response to Paul. I appreciate his help and yours. I know everyone doesn't have time to spell things out for me. But I do appreciate those that have helped me.