Results 1 to 15 of 15

Thread: Calc a formula? (Math) [Resolved]

  1. #1

    Thread Starter
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972

    Calc a formula? (Math) [Resolved]

    would it be possible to calc formulas such like this one:

    v^2 = v0^2 + 2a (x-x0)

    in vb!?

    I would like to give the V, D0, X and X0 and the program would show me the value of "a"?
    Last edited by TDQWERTY; Nov 21st, 2004 at 04:46 PM.
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    you may want to put this in the MATH forum. You need to compute the value of A, and the equation computes nothing, as you can't assign a value to v^2. What you have would be v=SQR(rest of equation) to calculate the value of V.

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Go to Project|References and add a reference to Microsoft Script Control 1.0. Then

    VB Code:
    1. Dim objMSC As New MSScriptControl.ScriptControl
    2.    
    3.     objMSC.Language = "vbscript"
    4.     MsgBox objMSC.Eval("v^2 = v0^2 + 2a (x-x0)")

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    that will show what?

  5. #5

  6. #6
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Or you can solve for 'a', then fill the values:

    VB Code:
    1. 'first dim your variables.  use the correct type:
    2. 'dim these: v,vo,x,xo
    3.  
    4. msgbox (v^2-vo^2)/(2 * (x-xo))
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  7. #7

    Thread Starter
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972
    Originally posted by MartinLiss
    Go to Project|References and add a reference to Microsoft Script Control 1.0. Then

    VB Code:
    1. Dim objMSC As New MSScriptControl.ScriptControl
    2.    
    3.     objMSC.Language = "vbscript"
    4.     MsgBox objMSC.Eval("v^2 = v0^2 + 2a (x-x0)")
    I get an error:

    Syntax error on the equation line

    my code:

    VB Code:
    1. Dim v As Double
    2.     Dim v0 As Double
    3.     Dim a As Double
    4.     Dim x As Double
    5.     Dim x0 As Double
    6.     v = 1
    7.     v0 = 2
    8.     x = 0
    9.     x0 = 3
    10.  
    11. Dim objMSC As New MSScriptControl.ScriptControl
    12.     objMSC.Language = "vbscript"
    13.     MsgBox objMSC.Eval("v^2 = v0^2 + 2a (x-x0)")
    14.  
    15. ' also "v^2 = v0^2 + 2*a (x-x0)" isn't working    ---> type mismatch 'a'
    16.  
    17. ' when i use:
    18. 'MsgBox objMSC.Eval("v^2 = v0^2 + 2*a * (x-x0)")
    19.  
    20. 'the message is TRUE :ehh:

    Seems that this doesn't like much the '='
    It solves very well a simple expression
    Last edited by TDQWERTY; Nov 20th, 2004 at 08:01 PM.
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    I get a complie error. UDT not defined. MS Scripting Control.ocx is referenced, too.

  9. #9
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Read my post. Anyways, MSScript can't solve for equations. Either you make your own solver or you solve it yourself for the variable then implement it as a formula.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  10. #10
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    I got an error trying to create a new instance of ScriptControl. It never even got as far as the messagebox.

  11. #11
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Originally posted by dglienna
    I got an error trying to create a new instance of ScriptControl. It never even got as far as the messagebox.
    you are using this exact code?:
    Dim objMSC As New MSScriptControl.ScriptControl

    objMSC.Language = "vbscript"
    MsgBox objMSC.Eval("v^2 = v0^2 + 2a (x-x0)")

    when you do: Dim objMSC As New
    and hit space, does MSScriptControl show up in the list?
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  12. #12
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    nope. Form1, Global, and Project are among what is there...

    but it is present in \system32 ?

    it's in the project, and I've tried it with and without putting the control on my form1.

  13. #13

    Thread Starter
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972
    thanks BuggyProgrammer now i understand, first i have to simplify the equation in orther to get a=........ then it will do the job

    thx for te nice help!
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  14. #14
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    Any help for me using MSSCRIPT.ocx?

  15. #15
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Originally posted by dglienna
    nope. Form1, Global, and Project are among what is there...

    but it is present in \system32 ?

    it's in the project, and I've tried it with and without putting the control on my form1.
    Sorry for responding so late

    Are you checking it in the references or the tool box? It appears that you have added it as a control (which still works, just not creating it like a class).

    If you loaded it like a control, it will work like the code, except you need to place the control on the form:

    MSScriptControl1.Language="VBScript"
    MSScriptcontrol1.exec "msgbox ""hi"""
    Remember, if someone's post was not helpful, you can always rate their post negatively .

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