Jump to content

Need help with script please


Ultima2
 Share

Recommended Posts

Hi Im having one problem with my script

#include <GUIConstants.au3>
#include <Math.au3>

$hMainGUI = GUICreate("Root of polynomials, Halley's Method",800,500)

GUISetBkColor(0x666666)
GUISetFont(9)

$tab = GUICtrlCreateTab(2, 2, 370, 24)

$tab2 = GUICtrlCreateTabItem("2nd Degree")
$exitbutton = GUICtrlCreateButton("Exit", 530, 400, 50, 50)
$A2value = GUICtrlCreateInput("",100,158,40,22)
$B2value = GUICtrlCreateInput("", 192, 158, 40, 22)
$C2value = GUICtrlCreateInput("", 277, 158, 40, 22)
$ok2button = GUICtrlCreateButton("Ok", 190, 230, 40, 40)
$iteration1 = GUICtrlCreateInput("", 312, 225, 35, 22)
GUICtrlCreateLabel("How many iterations?", 290, 200)
GUICtrlCreateLabel("X^2",140, 166)
GUICtrlCreateLabel("+",171, 162)
GUICtrlCreateLabel("X", 235, 166)
GUICtrlCreateLabel("+", 257, 162)
GUICtrlCreateLabel("Put in the form of ax^2 +bx +c", 107, 130)

$tab3 = GUICtrlCreateTabItem("3rd Degree")
$A3value = GUICtrlCreateInput("",100,158,40,22)
$B3value = GUICtrlCreateInput("", 192, 158, 40, 22)
$C3value = GUICtrlCreateInput("", 277, 158, 40, 22)
$D3value = GUICtrlCreateInput("", 358, 158, 40, 22)
$ok3button = GUICtrlCreateButton("Ok", 190, 230, 40, 40)
$iteration3 = GUICtrlCreateInput("", 312, 225, 35, 22)
GUICtrlCreateLabel("How many iterations?", 290, 200)
GUICtrlCreateLabel("X^3",140, 166)
GUICtrlCreateLabel("+",171, 162)
GUICtrlCreateLabel("X^2", 235, 166)
GUICtrlCreateLabel("+", 260, 162)
GUICtrlCreateLabel("X", 318, 166)
GUICtrlCreateLabel("+", 340, 162)
GUICtrlCreateLabel("Put in the form of ax^3 +bx^2 +cx + d", 107, 130)

Guisetstate()

Do
    $msg = GUIgetmsg()
    Select
        Case $msg = $ok2button
            Call("math")
        Case $msg = $GUI_EVENT_CLOSE or $msg = $exitbutton
            Exit
        Case $msg = $ok3button
            Call("math3")
    EndSelect
Until $msg = $GUI_EVENT_CLOSE or $msg = $exitbutton

Func math()
    $avalue = GuictrlRead($A2value)
    $bvalue = GUICtrlRead($B2value)
    $cvalue = GUIctrlread($C2value)
    $iteration = ceiling(abs(GUICtrlRead($iteration1)))
    $x = Random(0,5)
    $i = 0
    Do
        If $iteration > 200 Then
        MsgBox(0,"too much", "too much iterations, must be fewer than 200")
        Exitloop
        EndIf
    Do 
    $d = (($x)^2 + (1/($avalue))*($bvalue)*($x) + (1/($avalue))*$cvalue)
    $d1 = (2*($x)) + (1/($avalue))*($bvalue)
    $d2 = (2)
    $x = $x - (2*($d)*($d1))/(2*($d1)^2 - ($d)*($d2))
    $i = $i + 1
    Until $i = $iteration
    $z = (-1)*(($bvalue)*(1/($avalue)) + ($x))
        If abs((($avalue)*($x)^2 + ($bvalue)*($x) + $cvalue)) > 1e-7 Then
            MsgBox(0,"there is no real root", "no real root, or you've entered too few iterations")
        Else
        MsgBox(0,"The real roots are", $x&", "&$z)
        EndIf
    Until $i = $iteration

EndFunc
Func math3()
    $a3val = GuictrlRead($A3value)
    $b3val = GUICtrlRead($B3value)
    $c3val = GUIctrlread($C3value)
    $d3val = GUICtrlRead($D3value)
    $3iteration = ceiling(abs(GUICtrlRead($iteration3)))
    $3x = Random(0,5)
    $3i = 0
    $3z = 0
    Do
        If $3iteration > 200 Then
            MsgBox(0,"too much", "too much iterations, must be fewer than 200")
            Exitloop
        EndIf
        Do 
            $d = (($a3val)*($3x)^3 + ($b3val)*($3x)^2 + (($c3val)*($3x) + $d3val))
            $d1 = (3*($a3val)*($3x)^2 + 2*($b3val)*($3x) + $c3val)
            $d2 = (6*($a3val)*($3x) + 2*($b3val))
            $3x = $3x - (2*($d)*($d1))/(2*($d1)^2 - ($d)*($d2))
            $3i = $3i + 1
        Until $3i = $3iteration
        $3b3val = (1/($a3val))*($b3val) + $3x
        $3c3val = (1/($a3val))*($c3val) + ($3x)*($3b3val)
        $3x2 = Random(0,5)
        Do
            $3d = ($3x2)^2 + ($3b3val)*($3x2) + $3c3val
            $3d1 = 2*($3x2) + $3b3val
            $3d2 = 2
            $3x2 = $3x2 - (2*($3d)*($3d1))/(2*($3d1)^2 - ($3d)*($3d2))
            $3z = $3z + 1
        Until $3z = 30
                $3x3 = (-1)*($3b3val + $3x2)
        If abs((($a3val)*($3x)^3 + ($b3val)*($3x)^2 + (($c3val)*($3x) + $d3val))) > 1e-7 Then
            MsgBox(0,"there is no real root", "no real root, or you've entered too few iterations")
            ExitLoop
        Else
            MsgBox(0,"The real roots are", $3x, $3x2, $3x3)
        EndIf
    Until $3i = $3iteration
EndFunc

My problem is line 119, "MsgBox(0,"The real roots are", $3x, $3x2, $3x3)". For example, if I go to 3rd degree tab and enter a function and the iteration, then click the ok button, my script would stop and nothing happens. But if I delete the $3x2 and $3x3 from "MsgBox(0,"The real roots are", $3x, $3x2, $3x3)", everything works fine. I dont understand why, I believe I declared the variables $3x2 and $3x3, so why does my script does nothing when I click the ok button on the third degree tab? I cant seem to find where I went wrong in my script

PS: Nvm, found out what was wrong >_>. Didn't realize I separated them with a comma D:

Edited by Ultima2
Link to comment
Share on other sites

Help file quote on MsgBox:

MsgBox

--------------------------------------------------------------------------------

Displays a simple message box with optional timeout.

MsgBox ( flag, "title", "text" [, timeout [, hwnd]] )

Your MsgBox code:

MsgBox(0,"The real roots are", $3x, $3x2, $3x3)

As you can see you have added way too many parameters and your script can't work this way. You need to put all 3 values in a single parameter as you did previously:

MsgBox(0,"The real roots are", $3x&"  "&$3x2&"  "&$3x3)

Such mistakes can happen sometimes :)

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...