Results 1 to 4 of 4

Thread: cannot create shapes at runtime. **RESOLVED**

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982

    cannot create shapes at runtime. **RESOLVED**

    This code originated from a post by toughcoder, I have modified it a little.

    The bit I can't work out is I am getting an error message 'Object variable or with block variable not set.

    Code:
    Option Explicit
    
    Dim blnDrawing As Boolean
    Dim x1 As Single, y1 As Single
    Dim Shape2 As Shape
    
    Private Sub Form_Load()
    '    Shape2.FillStyle = vbFSTransparent
    '    Shape2.FillColor = 0
    '    Shape2.BorderStyle = 1
    '    Shape2.BorderWidth = 1
    End Sub
    
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        x1 = X
        y1 = Y
        Shape2.Left = x1
        Shape2.Top = y1
        blnDrawing = True
    End Sub
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If blnDrawing = True Then
            Shape2.Width = X - x1
            Shape2.Height = Y - y1
    
        End If
    End Sub
    
    Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        blnDrawing = False
        Shape2.FillStyle = vbFSSolid
        Shape2.FillColor = vbRed
        Shape2.BorderColor = vbRed
    End Sub
    Any ideas.
    Last edited by davidrobin; Mar 13th, 2003 at 07:45 AM.

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    You need to set the Shape object to something before you can reference it.
    VB Code:
    1. Set Shape2 = Controls.Add("VB.Shape","Control" & Controls.Count)

    Do that before you attempt to set any of the shape's properties.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    And in the mouse move event, set the control to visible
    VB Code:
    1. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.     If blnDrawing = True Then
    3.         Shape2.Width = X - x1
    4.         Shape2.Height = Y - y1
    5.         Shape2.Visible = True '[COLOR=red]<--- Added[/COLOR]
    6.     End If
    7. End Sub

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982
    Thanks MarkT,

    The visible bit was confusing me, I couldn't tell if it was working or not.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width