Microsoft Small Basic

Program Listing: XHD450-0
'Challenge of the Month - February 2014 math challenge by NaochanON XHD450 -0
Controls.ButtonClicked=graph_View
init()

Sub Graph_View
crossline()
a= Controls.GetTextBoxText(box[1])
b= Controls.GetTextBoxText(box[2])
c= Controls.GetTextBoxText(box[3])
d= Controls.GetTextBoxText(box[4])
Xstart=Controls.GetTextBoxText(box[5])
XEnd=Controls.GetTextBoxText(box[6])
Xstep=Controls.GetTextBoxText(box[7])
GraphicsWindow.PenColor="White"
ans=""
NN=0
For x=xstart To xend Step xstep
Y= a*X*X*X+b*X*X+C*X+d '<----------- +
GraphicsWindow.DrawEllipse(x*10+GW/2,GH/2-y,2,2)
anscheck()
EndFor
endsub

Sub anscheck
PM= y/math.Abs(Y)
NN=NN+1
If NN>2 and PM0*PM=-1 Then
ans= ans+"X= "+(X+X0)/2+" : "
Controls.SetTextBoxText(box[0],ans)
ElseIf Y=0 then '<-----------
ans= ans+"X= "+X+" : " '<-----------
Controls.SetTextBoxText(box[0],ans) '<-----------
EndIf
X0=X
PM0=PM
EndSub

Sub init
GW=800
GH=600
GraphicsWindow.Width=GW
GraphicsWindow.Height=GH
GraphicsWindow.BackgroundColor="darkgreen"
VL="1=1;2=8;3=-15;4=-55;5=-15;6=10;7=0.01" ' <-------
GraphicsWindow.BrushColor="Red"
box[0]=Controls.AddTextBox(GW/2+5,50)
Controls.SetSize(box[0],300,20)
For i=1 To 4
box[i]=Controls.AddTextBox(120,20+i*25)
Controls.SetSize(box[i],60,20)
Controls.SetTextBoxText(box[i],VL[i])
EndFor
For j=5 To 7
box[j]=Controls.AddTextBox(250,20+(j-4)*25)
Controls.SetSize(box[j],60,20)
Controls.SetTextBoxText(box[j],VL[j])
EndFor
GraphicsWindow.FontSize=25
btn= Controls.AddButton("Calc",120,150)
crossline()
EndSub

Sub crossline
GraphicsWindow.BrushColor="darkgreen"
GraphicsWindow.FillRectangle(0,0,GW,GH)
GraphicsWindow.PenColor="Yellow""
GraphicsWindow.PenWidth=2
GraphicsWindow.DrawLine(0,GH/2,GW,GH/2)
GraphicsWindow.DrawLine(GW/2,0,GW/2,GH)
GraphicsWindow.BrushColor="Yellow"
GraphicsWindow.FontSize=12
LBL="1=a;2=b;3=c;4=d;5=Start;6=End;7=step"
For i=1 To 4
GraphicsWindow.DrawText(100,20+i*25,LBL[i])
EndFor
For j=5 To 7
GraphicsWindow.DrawText(200,20+(j-4)*25,LBL[j])
EndFor
GraphicsWindow.DrawText(GW/2-60,55,"Answer ")
GraphicsWindow.FontSize=25
GraphicsWindow.DrawText(90,10," Y= aX^3+bX^2+CX+d ") '<------- +
endsub