TextBox issues

  • Thread starter Thread starter keithwaite
  • Start date Start date
K

keithwaite

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
 
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
 
Yea - int's are whole numbers so the number your entering is being rounded
 
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>
 
0.785398163397448 = radians??

Jaime

keithwaite said:
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.
 
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
 
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.


keithwaite said:
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.
 
Thanks for the info. I got it putting in the correct number now instead of a radians number.

Thanks,
Keith
 
Back
Top