Programmer_n
04-13-2016, 05:38 AM
Friends,
The following code creates a random sentence every time it runs. Is there an elegant way of achieving the same?
It is too hard-coded. I would like to declare the s(5) as an array and call it from the array. By this way, I can bring in more random elements into the sentence.
Sub Randomsentence()
Dim MyText As String
Dim s(5) As String
Dim i As Integer
s(1) = "open."
s(2) = "closed."
s(3) = "broken."
s(4) = "fixed."
MyText = "The door is "
i = Int(4 * Rnd())
Selection.TypeText MyText & s(i)
End Sub
The following code creates a random sentence every time it runs. Is there an elegant way of achieving the same?
It is too hard-coded. I would like to declare the s(5) as an array and call it from the array. By this way, I can bring in more random elements into the sentence.
Sub Randomsentence()
Dim MyText As String
Dim s(5) As String
Dim i As Integer
s(1) = "open."
s(2) = "closed."
s(3) = "broken."
s(4) = "fixed."
MyText = "The door is "
i = Int(4 * Rnd())
Selection.TypeText MyText & s(i)
End Sub