Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Region Includes
- #include <GUIConstantsEx.au3>
- #include <StaticConstants.au3>
- #EndRegion Includes
- #Region GUI
- Local $ValCoefficient[7]
- $Form1 = GUICreate("Regola di Ruffini")
- $Label1 = GUICtrlCreateLabel("Numero di Coefficienti:"&@CRLF&@CRLF&@CRLF&" Valore dei Coefficienti:", 32, 8)
- $List1 = GUICtrlCreateCombo ("3", 150, 5)
- GUICtrlSetData(-1, "4|5|6")
- For $i = 1 To 6
- $ValCoefficient[$i] = GUICtrlCreateInput("", 45*$i, 70, 40, 20)
- Next
- $Label2 = GUICtrlCreateLabel ("Divisore: x-", 32, 110)
- $Input7 = GUICtrlCreateInput("", 90, 107, 41, 21)
- $Button1 = GUICtrlCreateButton("Costruisci tabella", 160, 100, 120, 35)
- $Button2 = GUICtrlCreateButton("Calcola!", 300, 100, 70, 35)
- GUICtrlSetState ($Button2, $GUI_DISABLE)
- GUISetState(@SW_SHOW)
- #EndRegion GUI
- #Region Global Vars
- Global $Cicle
- Global $InputFirstLine
- Global $InputScndLine
- Global $InputThrdLine
- Global $Graphic
- Global $PoltResLabel
- #EndRegion Global Vars
- #Region Program Cicle
- While 1
- $nMsg = GUIGetMsg()
- Switch $nMsg
- Case $GUI_EVENT_CLOSE
- Exit
- Case $Button1
- If Not $Cicle = 0 Then
- For $i = 1 To UBound ($InputFirstLine)-1
- GUICtrlDelete ($InputFirstLine[$i])
- Next
- For $i = 1 To UBound ($InputScndLine)-1
- GUICtrlDelete ($InputScndLine[$i])
- Next
- For $i = 1 To UBound ($InputThrdLine)-1
- GUICtrlDelete ($InputThrdLine[$i])
- Next
- For $i = 1 To UBound ($Graphic)-1
- GUICtrlDelete ($Graphic[$i])
- Next
- GUICtrlDelete ($PoltResLabel)
- EndIf
- Dim $DividLab
- GUICtrlDelete ($DividLab)
- $Read = _ReadInput ()
- For $i = 1 To GUICtrlRead ($List1)
- If $Read[$i] = "" Then
- $Complete = False
- ExitLoop
- Else
- $Complete = True
- EndIf
- Next
- If $Complete = False Then
- MsgBox (48, "Errore", "Inserire i Coefficienti!")
- GUICtrlSetState ($Button2, $GUI_DISABLE)
- ElseIf GUICtrlRead ($Input7) = "" Then
- MsgBox (48, "Errore", "Inserire il Divisore!")
- Else
- $DividLab = GUICtrlCreateLabel ("Dividendo = " & _Dividendo(GUICtrlRead ($List1)) & @CRLF& "Divisore = x-" & GUICtrlRead ($Input7), 20, 150)
- _CreateGraph ()
- _CreateInLineInput ()
- GUICtrlSetState ($Button2, $GUI_ENABLE)
- EndIf
- $Cicle = $Cicle + 1
- Case $Button2
- _Calc ()
- $PoltResLabel = GUICtrlCreateLabel ("Risultato: " & _GetResultPoly (), 10, 375)
- EndSwitch
- WEnd
- #EndRegion Program Cicle
- #Region Funcs
- Func _Dividendo ($NumFact)
- $Read = _ReadInput ()
- Local $Dividendo
- For $i = 1 To $NumFact-1
- $Dividendo = $Dividendo & $Read[$i] & "x^" & $NumFact-$i & "+"
- Next
- $Dividendo = $Dividendo & $Read[$NumFact]
- Return $Dividendo
- EndFunc
- Func _ReadInput ()
- Local $Ret[8]
- For $i = 1 To 6
- $Ret[$i] = GUICtrlRead ($ValCoefficient[$i])
- Next
- Return $Ret
- EndFunc
- Func _CreateGraph ()
- Local $Read = GUICtrlRead ($List1) -1
- Global $Graphic[5]
- $Graphic[1] = GUICtrlCreateGraphic (60, 250, 1, 110)
- GUICtrlSetColor (-1, 0x000000)
- $Graphic[2] = GUICtrlCreateGraphic (100+16*$Read+24*($Read-1)-4, 250, 1, 110)
- GUICtrlSetColor (-1, 0x000000)
- $Graphic[3] = GUICtrlCreateGraphic (25, 322, 35, 1)
- GUICtrlSetColor (-1, 0x000000)
- $Graphic[4] = GUICtrlCreateGraphic (60, 322, 65+30*$Read+12*($Read-1), 1)
- GUICtrlSetColor (-1, 0x000000)
- EndFunc
- Func _CreateInLineInput ()
- $NumCoeff = GUICtrlRead ($List1)+1
- Global $InputFirstLine[$NumCoeff]
- Global $InputScndLine[$NumCoeff]
- Global $InputThrdLine[$NumCoeff]
- For $i = 1 To $NumCoeff-2
- $InputFirstLine[$i] = GUICtrlCreateInput ($Read[$i], 30+$i*40, 250, 30, 20)
- Next
- $InputFirstLine[$NumCoeff-1] = GUICtrlCreateInput ($Read[$i], 42+$i*40, 250, 30, 20)
- $InputScndLine[1] = GUICtrlCreateInput (GUICtrlRead ($Input7), 25, 290, 30, 20)
- For $i = 2 To $NumCoeff-2
- $InputScndLine[$i] = GUICtrlCreateInput ("", 30+$i*40, 290, 30, 20)
- Next
- $InputScndLine[$NumCoeff-1] = GUICtrlCreateInput ("", 42+$i*40, 290, 30, 20)
- For $i = 1 To $NumCoeff-2
- $InputThrdLine[$i] = GUICtrlCreateInput ("", 30+$i*40, 330, 30, 20)
- Next
- $InputThrdLine[$NumCoeff-1] = GUICtrlCreateInput ("", 42+$i*40, 330, 30, 20)
- EndFunc
- Func _Calc ()
- GUICtrlSetData ($InputThrdLine[1], $Read[1])
- $NumCoeff = GUICtrlRead ($List1)
- For $i = 1 To $NumCoeff-1
- GUICtrlSetData ($InputScndLine[$i+1], GUICtrlRead ($Input7)*GUICtrlRead ($InputThrdLine[$i]))
- GUICtrlSetData ($InputThrdLine[$i+1], GUICtrlRead ($InputFirstLine[$i+1])+GUICtrlRead ($InputScndLine[$i+1]))
- Next
- EndFunc
- Func _GetResultPoly ()
- $NumCoeff = GUICtrlRead ($List1)
- Local $Ret
- Local $Array[$NumCoeff+1]
- For $i = 1 To $NumCoeff
- $Array[$i] = GUICtrlRead ($InputThrdLine[$i])
- Next
- For $i = 1 To $NumCoeff-1
- $Ret = $Ret & $Array[$i] & "x^" & $NumCoeff-$i & "+"
- Next
- $Ret = $Ret & $Array[$NumCoeff-1] & " Resto:" & $Array[$NumCoeff]
- Return $Ret
- EndFunc
- #EndRegion Funcs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement