'Journal of Online Mathematics and Its Applications 'Volume 7, December 2007 ' 'Write Your Own Excel Mathlets 'Christoph Maier 'Visual Basic Code for the Macros Sub move_right() '----------------------------------------------- ' move_right Macro ' moves Xo right by .02 ' Keyboard Shortcut: Ctrl+Shift+R '---------------------------------------------- ' Get the current value of Xo ' the value in critical cell d2 current = Range("d2").Value ' ' assign a value of 0.02 to delta delta = 0.02 ' ' Add delta to Xo if Xo + delta <= 8.01 If current + delta <= 8.01 Then Range("d2").Value = current + delta End If End Sub Sub move_left() '------------------------------------------------------- ' move_left Macro ' moves Xo left by .02 ' Keyboard Shortcut: Ctrl+Shift+L '------------------------------------------------------- ' Get the current value of Xo ' the value in critical cell d2 current = Range("d2").Value ' ' assign a value of 0.02 to delta delta = 0.02 ' ' Add delta to Xo if Xo - delta >= -.01 If current - delta >= -0.01 Then Range("d2").Value = current - delta End If End Sub Sub choose_x_value() ' '---------------------------------------------------- ' choose_x_value macro ' allows the user to skip to a desired x-value ' Macro recorded 7/16/04 ' Keyboard shortcut Ctrl+g '---------------------------------------------------- ' Set prompt. Message = "Go to x (rounded to the nearest .02) = ? " ' Set title. Title = "Choose x-value" ' Display message and title. myvalue = InputBox(Message, Title) ' 'Round myvalue to the nearest .02 roundedvalue = Round(myvalue / 2, 2) * 2 If (Abs(roundedvalue - myvalue) > 0.0000005) Then x = MsgBox("Your value was rounded to the nearest .02", vbOKOnly, "Warning") myvalue = roundedvalue End If ' ' If x-value is between 0 and 8 (inclusive) change x-value ' in cell D2 to desired value If (myvalue >= 0 And myvalue <= 8) Then Range("D2").Value = myvalue End If End Sub