Input2points x1, y1, x2, y2 OutputLinearEquation 'input 2 points' x and y coordinates Function Input2points(x1, y1, x2, y2) x1=Inputbox("Please enter the X coordinate for pointA:", "X coordinate for pointA") y1=Inputbox("Please enter the Y coordinate for pointA:", "Y coordinate for pointA") x2=Inputbox("Please enter the X coordinate for pointB:", "X coordinate for pointB") y2=Inputbox("Please enter the Y coordinate for pointB:", "Y coordinate for pointB") 'wrong input: non-numeric character or no character was entered If IsNumeric(x1) = false or IsNumeric(y1) = false or IsNumeric(x2) = false or IsNumeric(y2) = false then Msgbox "Non-numeric character or no character was entered." & vbCrLf & "Click [OK] to enter the coordinates for the 2 points again." Input2points x1, y1, x2, y2 'wrong input: the 2 points should not be the same ElseIf x1=x2 and y1=y2 then Msgbox "PointA(" & x1 & "," & y1 & ") and pointB(" & x2 & "," & y2 & ") are the same." & vbCrLf & "Click [OK] to enter the coordinates for the 2 points again." Input2points x1, y1, x2, y2 End if End Function 'caculate the linear equation y=mx+b which joins the 2 points Function OutputLinearEquation Dim orim, orib, m, b If x1<>x2 then orim=(y2-y1)/(x2-x1) orib=y1-orim*x1 'use 2 decimals places in the output linear equationn m=FormatNumber(orim,2) b=FormatNumber(orib,2) If y1<>y2 then 'normal case: y=mx+b If m<>1 and m<>-1 and b>0 then Msgbox "The linear equation joins " & "pointA(" & x1 & "," & y1 & ") and pointB(" & x2 & "," & y2 & ") is" & vbCrLf & "y=" & m & "x+" & b 'special case: y=mx+0 should be displayed as y=mx Elseif m<>1 and m<>-1 and b=0 then Msgbox "The linear equation joins " & "pointA(" & x1 & "," & y1 & ") and pointB(" & x2 & "," & y2 & ") is" & vbCrLf & "y=" & m & "x" 'special case: y=mx+-b should be displayed as y=mx-b Elseif m<>1 and m<>-1 and b<0 then Msgbox "The linear equation joins " & "pointA(" & x1 & "," & y1 & ") and pointB(" & x2 & "," & y2 & ") is" & vbCrLf & "y=" & m & "x" & b 'special case: y=1x+b should be displayed as y=x+b Elseif m=1 and b>0 then Msgbox "The linear equation joins " & "pointA(" & x1 & "," & y1 & ") and pointB(" & x2 & "," & y2 & ") is" & vbCrLf & "y=x+" & b 'special case: y=1x+0 should be displayed as y=x Elseif m=1 and b=0 then Msgbox "The linear equation joins " & "pointA(" & x1 & "," & y1 & ") and pointB(" & x2 & "," & y2 & ") is" & vbCrLf & "y=x" 'special case: y=1x+-b should be displayed as y=x-b Elseif m=1 and b<0 then Msgbox "The linear equation joins " & "pointA(" & x1 & "," & y1 & ") and pointB(" & x2 & "," & y2 & ") is" & vbCrLf & "y=x" & b 'special case: y=-1x+b should be displayed as y=-x+b Elseif m=-1 and b>0 then Msgbox "The linear equation joins " & "pointA(" & x1 & "," & y1 & ") and pointB(" & x2 & "," & y2 & ") is" & vbCrLf & "y=-x+" & b 'special case: y=-1x+0 should be displayed as y=-x Elseif m=-1 and b=0 then Msgbox "The linear equation joins " & "pointA(" & x1 & "," & y1 & ") and pointB(" & x2 & "," & y2 & ") is" & vbCrLf & "y=-x" 'special case: y=-1x+-b should be displayed as y=-x-b Elseif m=-1 and b<0 then Msgbox "The linear equation joins " & "pointA(" & x1 & "," & y1 & ") and pointB(" & x2 & "," & y2 & ") is" & vbCrLf & "y=-x" & b End If 'special case: horizontal line Else Msgbox "The linear equation joins " & "pointA(" & x1 & "," & y1 & ") and pointB(" & x2 & "," & y2 & ") is" & vbCrLf & "y=" & y1 End If Else 'special case: vertical line Msgbox "The linear equation joins " & "pointA(" & x1 & "," & y1 & ") and pointB(" & x2 & "," & y2 & ") is" & vbCrLf & "x=" & x1 End if End Function