TextBox issues

Discussion in 'AutoCAD' started by keithwaite, Jan 13, 2004.

  1. keithwaite

    keithwaite Guest

    I have a TextBox on a Form. The text box accepts Numeric data. When I enter in a number like 2.5 or any number that has a Decimal point in it the number gets round down or up.
    2.25 changes to 2.0 and 2.75 changes to 3.0.

    This is the code I have.
    '<begin code>
    Private Sub cmdChamferDisSet_Click()
    UserForm1.Hide
    ' Set the value for CHAMFERA
    Dim AsysVarName As String
    Dim AsysVarData As Variant
    Dim ADataType As Integer
    Dim AintData As Integer
    AsysVarName = "CHAMFERA"
    AintData = tbFirstCD.Text
    AsysVarData = AintData ' Integer data
    ThisDrawing.SetVariable AsysVarName, AsysVarData
    ' Set the value for CHAMFERB
    Dim BsysVarName As String
    Dim BsysVarData As Variant
    Dim BDataType As Integer
    Dim BintData As Integer
    BsysVarName = "CHAMFERB"
    BintData = tbSecondCD.Text
    BsysVarData = BintData ' Integer data
    ThisDrawing.SetVariable BsysVarName, BsysVarData
    ''
    Dim sysVarName As String
    Dim varData As Variant
    sysVarName = "CHAMFERA"
    varData = ThisDrawing.GetVariable(sysVarName)
    tbFirstCD.Text = varData
    sysVarName = "CHAMFERB"
    varData = ThisDrawing.GetVariable(sysVarName)
    tbSecondCD.Text = varData
    UserForm1.Show
    End Sub
    '<end code>

    What causes this? Why is it rounding the number instead of keeping the number I am putting into the text box?

    Thanks for your help,
    Keith
     
    keithwaite, Jan 13, 2004
    #1
  2. It was because of variables being declared as integers instead of doubles.
    I've simplified the code below.
    ------------------------------------------------------------
    Private Sub cmdChamferDisSet_Click()
    Dim dblData As Double
    UserForm1.Hide
    ' Set the value for CHAMFERA
    dblData = tbFirstCD.Text
    ThisDrawing.SetVariable "CHAMFERA", dblData
    ' Set the value for CHAMFERB
    dblData = tbSecondCD.Text
    ThisDrawing.SetVariable "CHAMFERB", dblData
    'Reset Textboxes
    dblData = ThisDrawing.GetVariable("CHAMFERA")
    tbFirstCD.Text = dblData
    dblData = ThisDrawing.GetVariable("CHAMFERB")
    tbSecondCD.Text = dblData
    UserForm1.Show
    End Sub
     
    Nathan Taylor, Jan 14, 2004
    #2
  3. keithwaite

    thenrich01 Guest

    Yea - int's are whole numbers so the number your entering is being rounded
     
    thenrich01, Jan 14, 2004
    #3
  4. keithwaite

    keithwaite Guest

    The code worked GREAT. Thanks.
     
    keithwaite, Jan 14, 2004
    #4
  5. keithwaite

    keithwaite Guest

    What about with Angles? CHAMFERD is for the Angles for the Chamfer commands Angle. When I type in a angle i.e. 45 the number that reports back in the TextBox is 0.785398163397448 instead of 45. Is it something with my code.

    Here is the code:
    '<begin code>
    Private Sub cmdLthAngleSet_Click()
    UserForm2.Hide
    ' Set the value for CHAMFERC
    Dim CsysVarName As String
    Dim CsysVarData As Variant
    Dim CDataType As Integer
    Dim CintData As Integer
    CsysVarName = "CHAMFERC"
    CintData = tbLengthFL.Text
    CsysVarData = CintData ' Integer data
    ThisDrawing.SetVariable CsysVarName, CsysVarData
    ' Set the value for CHAMFERD
    Dim DsysVarName As String
    Dim DsysVarData As Variant
    Dim DDataType As Integer
    Dim DintData As Integer
    DsysVarName = "CHAMFERD"
    DintData = tbAngleFL.Text
    DsysVarData = DintData ' Integer data
    ThisDrawing.SetVariable DsysVarName, DsysVarData

    ' Enter New values in textbox
    sysVarName = "CHAMFERC"
    varData = ThisDrawing.GetVariable(sysVarName)
    tbLengthFL.Text = varData
    Dim CDsysVarName As String
    Dim CDvarData As Variant
    CDsysVarName = "CHAMFERD"
    CDvarData = ThisDrawing.GetVariable(CDsysVarName)
    tbAngleFL.Text = CDvarData
    UserForm2.Show
    End Sub
    '<end code>
     
    keithwaite, Jan 14, 2004
    #5
  6. keithwaite

    Jaime Guest

    0.785398163397448 = radians??

    Jaime

    commands Angle. When I type in a angle i.e. 45 the number that reports back
    in the TextBox is 0.785398163397448 instead of 45. Is it something with my
    code.
     
    Jaime, Jan 14, 2004
    #6
  7. keithwaite

    keithwaite Guest

    What do you mean by Radians?? Units in drawing are set to Decimal Degrees. It could be something with my DIM statements that is causeing this. That is the only thing I can think of. It could be some other setting in AutoCAD that is causing it also. I am not sure what is causing it.

    Keith
     
    keithwaite, Jan 14, 2004
    #7
  8. It doesn't matter how your units are configured. All of AutoCAD's programming
    interfaces return angles in radians. You must convert them to your units of
    choice for display. Take a look at the AngleToString method of the Utility
    object.


    could be something with my DIM statements that is causeing this. That is the
    only thing I can think of. It could be some other setting in AutoCAD that is
    causing it also. I am not sure what is causing it.
     
    Chuck Gabriel, Jan 14, 2004
    #8
  9. keithwaite

    keithwaite Guest

    Thanks for the info. I got it putting in the correct number now instead of a radians number.

    Thanks,
    Keith
     
    keithwaite, Jan 14, 2004
    #9
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.