Docsity

Demo Program One Probabilistic Simulation | ECE 5800, Assignments of Electrical and Electronics Engineering

Toggle sidebar
bg1
ECE 5800
Severance
Demo Program One
Probabilistic Simulation
Option Explicit
Dim N65 As Integer
Dim N10 As Integer
Dim N25 As Integer
Dim Number As Integer
Private Sub cmExecute_Click( )
Dim K As Integer
Dim Weight As Integer
Dim Random As Single
If Len(txt10.Text) > 0 Then
If Len(txt25.Text) > 0 Then
If Len(txt65.Text) > 0 Then
If Len(txtNumber.Text) > 0 Then
For K = 1 To Number
Random = Rnd
If Random > 0.25 Then
If Random < 0.35 Then
Weight = N10
Else
Weight = N65
End If
Else
Weight = N25
End If
lstBox.AddItem CStr(K) & " " & CStr(Weight)
Next K
Else
MsgBox "There must be a number of iterations"
txtNumber.SetFocus
End If
Else
MsgBox "How many 65 pound boxes are there?"
txt65.SetFocus
End If
Else
MsgBox "How many 25 pound boxes are there?"
txt25.SetFocus
End If
Else
MsgBox "How many 10 pound boxes are there?"
txt10.SetFocus
End If
End Sub
pf3

Partial preview of the text

Download Demo Program One Probabilistic Simulation | ECE 5800 and more Assignments Electrical and Electronics Engineering in PDF only on Docsity!

ECE 5800

Severance

Demo Program One

Probabilistic Simulation

Option Explicit Dim N65 As Integer Dim N10 As Integer Dim N25 As Integer Dim Number As Integer

Private Sub cmExecute_Click( ) Dim K As Integer Dim Weight As Integer Dim Random As Single

If Len(txt10.Text) > 0 Then If Len(txt25.Text) > 0 Then If Len(txt65.Text) > 0 Then If Len(txtNumber.Text) > 0 Then For K = 1 To Number Random = Rnd If Random > 0.25 Then If Random < 0.35 Then Weight = N Else Weight = N End If Else Weight = N End If lstBox.AddItem CStr(K) & " " & CStr(Weight) Next K Else MsgBox "There must be a number of iterations" txtNumber.SetFocus End If Else MsgBox "How many 65 pound boxes are there?" txt65.SetFocus End If Else MsgBox "How many 25 pound boxes are there?" txt25.SetFocus End If Else MsgBox "How many 10 pound boxes are there?" txt10.SetFocus End If

Private Sub cmdClear_Click( ) lstBox.Clear End Sub

Private Sub cmdExit_Click( ) End End Sub

Private Sub txt10_LostFocus( ) If Len(txt10.Text) > 0 Then If IsNumeric(txt10.Text) Then If Int(CSng(txt10.Text)) = CSng(txt10.Text) Then If CStr(txt10.Text) > 0 Then N10 = CInt(txt10.Text) Else MsgBox "There must be a positive number, please!" End If Else MsgBox "You can't have a fraction here!" End If Else MsgBox "Must be a numeric quantity, please!" End If End If End Sub

Private Sub txt25_LostFocus( ) If Len(txt25.Text) > 0 Then If IsNumeric(txt25.Text) Then If Int(CSng(txt25.Text)) = CSng(txt25.Text) Then If CStr(txt25.Text) > 0 Then N25 = CInt(txt25.Text) Else MsgBox "There must be a positive number, please!" End If Else MsgBox "You can't have a fraction here!" End If Else MsgBox "Must be a numeric quantity, please!" End If End If