Error: Object or Block not set??/

Discussion in 'AutoCAD' started by nalsur8, Sep 9, 2004.

  1. nalsur8

    nalsur8 Guest

    error at Textbox1_Change()
    any guys can monitor this code what problem
    --------------------------
    Private mobjLine As Object
    Private Sub CommandButton1_Click()
    Dim ptPick(0 To 2) As Double
    Dim varStart As Variant
    Dim varEnd As Variant
    Const conErrgEtentityFailed = 2147352567
    On Error GoTo HandleErr
    Me.Hide
    ThisDrawing.Utility.GetEntity mobjLine, ptPick, _
    "Select Line Please"
    If mobjLine.EntityType <> acLine Then
    BadPick:
    MsgBox "No Line Seleted", vbExclamation + vbOKOnly
    Else
    With mobjLine
    varStart = .StartPoint
    varEnd = .EndPoint
    TextBox1.Text = Format(varStart(0), "0.000")
    TextBox2.Text = Format(varStart(1), "0.000")
    TextBox3.Text = Format(varStart(2), "0.000")
    TextBox4.Text = Format(varEnd(0), "0.000")
    TextBox5.Text = Format(varEnd(1), "0.000")
    TextBox6.Text = Format(varEnd(2), "0.000")
    ListBox1.ListIndex = .Color
    End With
    End If
    ExitHere:
    Me.Show
    Exit Sub
    HandleErr:
    Select Case Err
    Case conErrgEtentityFailed
    Resume BadPick
    Case Else
    MsgBox "Unexpected error " & Err.Number & ":" & _
    Err.Description, vbCritical
    Resume ExitHere
    Resume
    End Select

    End Sub

    Private Sub ListBox1_Click()
    mobjLine.Color = ListBox1.ListIndex
    mobjLine.Update
    End Sub

    Private Sub TextBox1_Change()
    Dim varStart As Variant
    varStart = mobjLine.StartPoint
    varStart(0) = TextBox1.Text
    mobjLine.StartPoint = varStart
    mobjLine.Update
    End Sub

    Private Sub TextBox2_Change()
    Dim varEnd As Variant
    varEnd = mobjLine.EndPoint
    varEnd(0) = TextBox2.Text
    mobjLine.EndPoint = varEnd
    mobjLine.Update

    End Sub

    Private Sub UserForm_Initialize()
    Dim Inst As Integer
    With ListBox1
    ..AddItem "By Block"
    ..AddItem "Red"
    ..AddItem "Yellow"
    ..AddItem "Green"
    ..AddItem "Cyan"
    ..AddItem "Blue"
    ..AddItem "Magenta"
    ..AddItem "white"
    For Inst = 8 To 255
    ..AddItem "Color" & CStr(Inst)
    Next Inst
    ..AddItem "By Layer"
    End With
    TextBox1.Text = "0.000"
    TextBox2.Text = "0.000"
    TextBox3.Text = "0.000"
    TextBox4.Text = "0.000"
    TextBox5.Text = "0.000"
    TextBox6.Text = "0.000"
    End Sub
     
    nalsur8, Sep 9, 2004
    #1
  2. Well use Validate or Exit as your event. When you load the form and set
    Textbox1's value to 0.000 a Change is firing and you have no object yet. Or
    re-code the Change event to test for the object first or toggle a boolean
    var when the commandbutton is clicked so the textbox knows to do what it
    needs to do.

    A general comment here is you should avoid using the change event on form
    controls. Change gets fired more often than you can imagine. In the future,
    pop a msgbox in your event and do a dry run of your form so you can see if
    you have the right event coded.

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Sep 9, 2004
    #2
  3. nalsur8

    Guest Guest

    ok thk Mike
     
    Guest, Sep 9, 2004
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.