Friday, November 12, 2010

Friday, November 12 2010

Here is a program I wrote around a quick and easy way to get the required number of steps for a flight of stairs


Public Class Form1
Dim totalRise As Double
Dim idealNumberOfSteps As Double
Dim idealDivisor As Integer


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
totalRise = CDbl(TextBox1.Text)
idealDivisor = setDivisor()

idealNumberOfSteps = totalRise / idealDivisor

MessageBox.Show(idealNumberOfSteps & " / " & Math.Round(idealNumberOfSteps, 0))


End Sub

Private Function setDivisor()
If RadioButton1.Checked = True Then
idealDivisor = 6
Else
idealDivisor = 7
End If
Return idealDivisor

End Function
End Class


Here is an expanded version of the program



Public Class Form1
Dim totalRise As Double
Dim idealNumberOfSteps As Double
Dim idealDivisor As Integer
Dim idealHeight As Double
Dim idealRun As Double


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
totalRise = CDbl(TextBox1.Text) * 12

idealDivisor = setDivisor()

idealNumberOfSteps = totalRise / idealDivisor

idealHeight = setIdealHeight(totalRise, idealNumberOfSteps)


idealRun = 26 - (idealHeight * 2)
idealRun = Math.Round(idealRun, 2)


Call showIdeal(idealNumberOfSteps)

Call showIdealSpecifics(idealHeight, idealRun)



End Sub

Private Function setDivisor()
If RadioButton1.Checked = True Then
idealDivisor = 6
Else
idealDivisor = 7
End If
Return idealDivisor

End Function

Private Function setIdealHeight(ByVal totalRise, ByVal idealNumberOfSteps)
Dim ideal As Double
ideal = totalRise / Math.Round(idealNumberOfSteps, 0)
idealHeight = Math.Round(idealHeight, 2)
Return ideal

End Function

Private Sub showIdeal(ByVal idealNumberOfSteps)
showData.Text = ""

showData.Text += "In an ideal world, you would have " & idealNumberOfSteps & " stairs." & vbCrLf
showData.Text += "If the rise of the staircase is not an issue, we would recommend having " & Math.Round(idealNumberOfSteps, 0) & " stairs" & vbCrLf


End Sub

Private Sub showIdealSpecifics(ByVal idealHeight, ByVal idealRun)
showData.Text += vbCrLf & "If you use our recommended number of stairs, the height of each stair would be " & idealHeight & " inches."
showData.Text += "The ideal run, or width of each stair, would be " & idealRun & " inches"



End Sub
End Class

No comments: