Converting to Slope and Angle

Discussion in 'AutoCAD' started by Max, Jun 12, 2004.

  1. Max

    Max Guest

    Hi

    I am trying to figure out how to make a VBA routine converter

    I have the form functional but I am trying to figure out the correct syntax.

    In my form I am trying to figure out how to convert %grade Slope ie; 4/100
    (4%)
    to Angle Degrees 2.2906100.

    To get the Angle Degrees you are using ARCTANGENT

    ..04ATAN = 2.2906100

    so

    in my command button


    Private Sub CommandButton1_Click()
    If TextBox1.Text = "" Then
    TextBox1.Text = TextBox2.Text * 1.0936
    Else
    TextBox2.Text = TextBox1.Text * 0.9144
    End If
    End Sub


    (the * 1.0936 and * 0.9144 is my example for converting Imperial/Metric for
    Yards)

    Thanks for the help!
     
    Max, Jun 12, 2004
    #1
  2. Max

    wivory Guest

    So what's not working?

    Regards

    Wayne Ivory
    IT Analyst Programmer
    Wespine Industries Pty Ltd
     
    wivory, Jun 14, 2004
    #2
  3. Max

    Max Guest

    Hi Wayne

    Trying to figure out the correct syntax so what I have been trying is
    this....

    Private Sub CommandButton1_Click()
    If TextBox1.Text = "" Then
    TextBox1.Text = TextBox2.Text * ATAN
    Else
    TextBox2.Text = TextBox1.Text * TAN
    End If
    End Sub


    but its erroring out at the ATAN.....

    Not sure if i am way off here....
     
    Max, Jun 14, 2004
    #3
  4. Max

    David Urban Guest

    ATAN is not a valid function. check the VBA help for derived Math
    Functions. I think you are looking for the Cotan which is 1/tan(x).

    David Urban
     
    David Urban, Jun 14, 2004
    #4
  5. Max

    Max Guest

    Hi

    Thanks I tried it and it seems to be keep erroring out at the 1/tan(x) point


    Private Sub CommandButton1_Click()
    If TextBox1.Text = "" Then
    TextBox1.Text = TextBox2.Text * 1/tan(x)
    Else
    TextBox2.Text = TextBox1.Text * 1
    End If
    End Sub
     
    Max, Jun 14, 2004
    #5
  6. The .Text property returns a string value. You can't use that value to do
    math with until you use the VAL() function to convert it to a number. The
    FORMAT() function turns a number into a string.

    You're going to need something more like this...

    Private Sub CommandButton1_Click()

    If TextBox1.Text = "" Then
    TextBox1.Text = Format(Atn(Val(TextBox2.Text)))
    Else
    TextBox2.Text = Format(Tan(Val(TextBox1.Text)))
    End If

    End Sub

    HTH,
    James
     
    James Belshan, Jun 14, 2004
    #6
  7. Max

    wivory Guest

    Looks mostly right James, except I think David was correct in that Max wants Cotangent rather than Arctangent, so the procedure would be:

    Private Sub CommandButton1_Click()

    If TextBox1.Text = "" Then
    TextBox1.Text = Format(1/Tan(Val(TextBox2.Text)))
    Else
    TextBox2.Text = Format(Tan(Val(TextBox1.Text)))
    End If

    End Sub

    Regards

    Wayne Ivory
    IT Analyst Programmer
    Wespine Industries Pty Ltd
     
    wivory, Jun 16, 2004
    #7
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.