Results 1 to 4 of 4

Thread: draw a few functions graphics

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2011
    Posts
    53

    draw a few functions graphics

    Hi friends,

    I want to ask a question. There are fifty mathematical functions in my programme ( (x^2),(x^3), sinx,cosx.. etc. )Apart from these, there is a button called "+".


    When I click "+" button, I will chose some of functions. For example ( sinx, cosx,tanx) The last function will be "sinx+cosx+tanx"

    or

    I will click "+" button and after that I will click (x^2),(x^3),(x^4). The function will be (x^2)+(x^3)+(x^4)

    This is what I want but I can't do this.

    How can I do this?

    Thanks

  2. #2
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: draw a few functions graphics

    I guess you are programming a calculator, to do that, you need to save the state of + button in a module level variable and when you press other function button, check the state of + button and act according it.

    Here is a sample
    vb Code:
    1. Private mblnPlusPressed As Boolean
    2. Private mdblResult As Double
    3. Private x As Long
    4.  
    5. Private Sub Command1_Click()
    6.     ' this is + button
    7.     mblnPlusPressed = Not mblnPlusPressed
    8. End Sub
    9.  
    10. Private Sub Command2_Click()
    11.     ' this is (x^2) button
    12.     If mblnPlusPressed = True Then
    13.         mdblResult = mdblResult + (x ^ 2)
    14.     Else
    15.         mdblResult = (x ^ 2)
    16.     End If
    17.     ' show mdblResult
    18.     Me.Caption = mdblResult
    19. End Sub
    20.  
    21. Private Sub Command3_Click()
    22.     ' this is (x^3) button
    23.     If mblnPlusPressed = True Then
    24.         mdblResult = mdblResult + (x ^ 3)
    25.     Else
    26.         mdblResult = (x ^ 3)
    27.     End If
    28.     ' show mdblResult
    29.     Me.Caption = mdblResult
    30. End Sub
    31.  
    32. Private Sub Form_Load()
    33.     x = 2
    34. End Sub



  3. #3
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: draw a few functions graphics

    Not too sure I understand what you want, but if, for instance you have the Functions in a ListBox you can build up the 'equation' like this
    Code:
    Private strSign As String
    
    Private Sub cmdAdd_Click()
    txtEquation.Text = ""
    strSign = " + "
    End Sub
    
    Private Sub Form_Load()
    txtEquation.Text = ""
    List.Clear
    List.AddItem "Sin(X)"
    List.AddItem "Cos(X)"
    List.AddItem "Tan(X)"
    List.AddItem "(X^2)"
    List.AddItem "(X^3)"
    List.AddItem "(X^4)"
    End Sub
    
    Private Sub List_Click()
    Dim intI As Integer
    If strSign <> "" And List.ListIndex >= 0 Then
        If txtEquation.Text <> "" Then
            txtEquation.Text = txtEquation.Text & strSign & List.List(List.ListIndex)
        Else
            txtEquation.Text = List.List(List.ListIndex)
        End If
    End If
    End Sub
    Just click on cmdAdd then click on each item in the ListBox you want in the 'equation' and you will see the result in txtEquation

  4. #4

    Thread Starter
    Member
    Join Date
    Oct 2011
    Posts
    53

    Re: draw a few functions graphics

    There are 8 command buttons
    X^2
    X^3
    x^4
    Tan(x)
    Sin(x)
    Cos(x)
    +
    Draw


    First, I will click "+" button. And after that I will click buttons above which I want ( for example: (x^2),(x^3),(x^4) ) Finally I will click the "Draw" button. The function will be (x^2)+(x^3)+(x^4). It will draw this function's graphic.

    This is what I want

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width