|
-
Feb 11th, 2012, 03:56 AM
#1
Thread Starter
Member
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
-
Feb 11th, 2012, 05:36 AM
#2
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:
Private mblnPlusPressed As Boolean Private mdblResult As Double Private x As Long Private Sub Command1_Click() ' this is + button mblnPlusPressed = Not mblnPlusPressed End Sub Private Sub Command2_Click() ' this is (x^2) button If mblnPlusPressed = True Then mdblResult = mdblResult + (x ^ 2) Else mdblResult = (x ^ 2) End If ' show mdblResult Me.Caption = mdblResult End Sub Private Sub Command3_Click() ' this is (x^3) button If mblnPlusPressed = True Then mdblResult = mdblResult + (x ^ 3) Else mdblResult = (x ^ 3) End If ' show mdblResult Me.Caption = mdblResult End Sub Private Sub Form_Load() x = 2 End Sub
-
Feb 11th, 2012, 05:39 AM
#3
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
-
Feb 11th, 2012, 06:57 AM
#4
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|