Textbox Update

Discussion in 'AutoCAD' started by stck2mlon, Feb 16, 2005.

  1. stck2mlon

    stck2mlon Guest

    I am creating an app that allows the user to select an object by press the select object button and then I want the objects length to populate the txtLineLength textbox. I can't seem to figure this out...Please brains help!

    Private Sub UserForm_Initialize()
    txtLineLength.Value = ""
    txtStreetName.Value = ""
    txtStreetWidth.Value = ""
    txtNeighborhood.Value = ""
    End Sub

    Private Sub cmdSelect_Click()
    Me.Hide
    Unload frmLineLength

    Dim returnobj As Object
    Dim entbasepnt As Variant
    Dim entLength As String

    frmLineLength.txtLineLength.Text = ""
    ThisDrawing.Utility.GetEntity returnobj, entbasepnt, "Select Line: "
    entLength = returnobj.Length
    entLength = ThisDrawing.Utility.RealToString(entLength, acArchitectural, 4)

    'MsgBox (entLength)

    frmLineLength.Show
    frmLineLength.txtLineLength.SetFocus
    frmLineLength.txtLineLength.Text = entLength

    End Sub

    Private Sub cmdUpdate_Click()

    'This Section Is Complete
    Dim Linelength As String
    Dim StreetName As String
    Dim StreetWidth As String
    Dim Neighborhood As String

    Linelength = Trim(txtLineLength.Value)
    StreetName = Trim(txtStreetName.Value)
    StreetWidth = Trim(txtStreetWidth.Value)
    Neighborhood = Trim(txtNeighborhood.Value)

    ThisDrawing.SendCommand ("setvar" & vbCr & "attdia" & vbCr & 0 & vbCr)
    ThisDrawing.SendCommand ("-insert" & vbCr & "tag_street" & vbCr & "1" & vbCr & "1" & vbCr & "1" & vbCr & "0" & vbCr _
    & Linelength & vbCr & StreetName & vbCr & StreetWidth & vbCr & Neighborhood & vbCr)
    ThisDrawing.SendCommand ("setvar" & vbCr & "attdia" & vbCr & 1 & vbCr)

    Unload Me

    End Sub

    'Unloads Dialog and Exits Quietly
    Private Sub cmdCancel_Click()

    txtLineLength.Value = ""
    txtStreetName.Value = ""
    txtStreetWidth.Value = ""
    txtNeighborhood.Value = ""

    Unload Me
    End Sub
     
    stck2mlon, Feb 16, 2005
    #1
  2. stck2mlon

    Tom Roberts Guest

    Hi

    In the cmdSelect_Click() event you are showing the form before the textbox
    is updated
    Assuming it is a modal form no more code is executed until the modal form is
    dismissed

    A couple of other things you might want to consider:
    Your don't need to reference the form when you are referring to controls on
    a form from code within said form
    --> txtLineLength.Text = frmLineLength.txtLineLength.Text

    You don't need to set focus to the text box to update the text value

    You need to handle the scenario of the User selecting an entity that does
    not have a Length property

    And most importantly you need to stop using the SendCommand function. It may
    be working OK in this situation but almost everyone on this newsgroup will
    agree that it should be avoided if possible.
    Use the SetVariable method to change system variables and use the
    InsertBlock method to add a blockref

    --
    Regards
    Tom Roberts
    __________________________
    MechWest Design & Drafting
    Perth, Western Australia
     
    Tom Roberts, Feb 16, 2005
    #2
  3. stck2mlon

    stck2mlon Guest

    I want the end user to be able to fill in the Street Information and then select the object or select the object then fill in the information. I am not sure how to do this though. Any help would be greatly appreciated.
     
    stck2mlon, Feb 16, 2005
    #3
  4. stck2mlon

    Oberer Guest

    Tom Roberts gave you some excellent advice stck2mlon.

    Your second request is a little vague here. Where is the user filling in the "street information". Are you talking xdata? using a DB to store info?
     
    Oberer, Feb 16, 2005
    #4
  5. stck2mlon

    stck2mlon Guest

    No sir, it is simply a textbox that pops up and allows the user to select a line "street" and then they fill in address and neighborhhod then when they update a block is inserted witht the attributes filled in. Does this make sense?
     
    stck2mlon, Feb 16, 2005
    #5
  6. stck2mlon

    Oberer Guest

    Are you still having trouble getting the length to appear on the form after you select the line?

    i've made a few changes that may help...

    Code:
    Option Explicit
    
    Private Sub UserForm_Initialize()
    txtLineLength.Value = ""
    txtStreetName.Value = ""
    txtStreetWidth.Value = ""
    txtNeighborhood.Value = ""
    End Sub
    
    Private Sub cmdSelect_Click()
    Me.Hide
    '''Unload frmLineLength
    
    Dim returnobj As Object
    Dim entbasepnt As Variant
    Dim entLength As String
    
    frmLineLength.txtLineLength.Text = ""
    ThisDrawing.Utility.GetEntity returnobj, entbasepnt, "Select Line: "
    If TypeOf returnobj Is AcadLine Then
    entLength = CStr(returnobj.length)
    Else
    ThisDrawing.Utility.Prompt returnobj.ObjectName & " selected. Please select a line:"
    AcadApplication.Update
    End If
    '''entLength = ThisDrawing.Utility.RealToString(entLength, acArchitectural, 4)
    
    'MsgBox (entLength)
    
    Me.Show
    '''Me.txtLineLength.SetFocus
    Me.txtLineLength.Value = entLength
    
    End Sub
    
    Private Sub cmdUpdate_Click()
    
    'This Section Is Complete
    Dim Linelength As String
    Dim StreetName As String
    Dim StreetWidth As String
    Dim Neighborhood As String
    Dim vAttDIA As Variant
    Dim oBlkRef As AcadBlockReference
    Dim strBlockName As String
    Dim dblBlockScale As Double
    Dim vBlockAttributes As Variant
    Dim vIP As Variant
    
    strBlockName = "tag_street"
    dblBlockScale = 1
    vAttDIA = ThisDrawing.GetVariable("ATTDIA")
    
    Linelength = Trim(txtLineLength.Value)
    StreetName = Trim(txtStreetName.Value)
    StreetWidth = Trim(txtStreetWidth.Value)
    Neighborhood = Trim(txtNeighborhood.Value)
    
    ''ThisDrawing.SendCommand ("setvar" & vbCr & "attdia" & vbCr & 0 & vbCr)
    'WHERE DO YOU INSERT YOUR BLOCK??
    'you'll also need to test for blank values in your text boxes before inserting the block
    'INSERT BLOCK
    vIP = ThisDrawing.Utility.GetPoint(, "Pick Insertion Point For Block: ")
    Set oBlkRef = ThisDrawing.ModelSpace.InsertBlock(vIP, strBlockName, dblBlockScale, dblBlockScale, dblBlockScale, 0)
    ' Get attributes to update
    vBlockAttributes = oBlkRef.GetAttributes
    
    'updating this variant will update your block attributes
    vBlockAttributes(0) = StreetName
    vBlockAttributes(1) = StreetWidth
    vBlockAttributes(2) = Neighborhood
    '''ThisDrawing.SendCommand ("-insert" & vbCr & "tag_street" & vbCr & "1" & vbCr & "1" & vbCr & "1" & vbCr & "0" & vbCr _
    '''& Linelength & vbCr & StreetName & vbCr & StreetWidth & vbCr & Neighborhood & vbCr)
    ''ThisDrawing.SendCommand ("setvar" & vbCr & "attdia" & vbCr & 1 & vbCr)
    ThisDrawing.SetVariable "ATTDIA", vAttDIA
    Unload Me
    
    End Sub
    
    'Unloads Dialog and Exits Quietly
    Private Sub cmdCancel_Click()
    
    '''txtLineLength.Value = ""
    '''txtStreetName.Value = ""
    '''txtStreetWidth.Value = ""
    '''txtNeighborhood.Value = ""
    
    Unload Me
    End Sub
    
     
    Oberer, Feb 16, 2005
    #6
  7. stck2mlon

    Oberer Guest

    apologies stck2mlon, i missed a subtle code/logic error.

    orig code:
    frmLineLength.Show
    frmLineLength.txtLineLength.SetFocus
    frmLineLength.txtLineLength.Text = entLength

    this needs to be: (you need to show the form AFTER you update it)
    me.txtLineLength.SetFocus
    me.txtLineLength.Text = entLength
    me.Show

    the "me" qualifier is optional btw, as is the fully qualified control reference...
     
    Oberer, Feb 16, 2005
    #7
  8. stck2mlon

    stck2mlon Guest

    I get an autocad main window invisible error.
     
    stck2mlon, Feb 16, 2005
    #8
  9. do you need to hide your form before a get call?
    me.hide
     
    Paul Richardson, Feb 16, 2005
    #9
  10. stck2mlon

    stck2mlon Guest

    Everything works great in ADT2005 but in ADT3.3 the following gets a type mismatch error:

    entLength = ThisDrawing.Utility.RealToString(entLength, acArchitectural, 4)
     
    stck2mlon, Feb 17, 2005
    #10
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.