Hi all, I used to use XOJO back when it was RealStudio in highscool. I now find myself stuck after many years without coding. I am trying to get a button to display one of two words at random in a textfield when pressed.
Example of how I want to function:
When I press the button the Textfield displays “Goodnight” or it could display “Good bye”
I have attached what I have, I remember using OR statements in highschool but that doesnt seem to work.
Also could I add up to 20 words that will be able to be selected for display in the textfiel?
Var strPhrases() As String // Initialize an Array
strPhrases=Array("Phrase 01","Phrase 02","Phrase 03","Phrase 04","Phrase 05") // Fill the Array with Values
tfTextField.Text = strPhrases(System.Random.InRange(0,4)) // Display a randomly selected Value from the Array in a TextField
I don’t see anything attached here and I am away from my dev machine at the moment, but you would want something like the following (100% untested).
On the button right click, Event Handler, and then select the “Pressed” event.
In that event add the following:
Var intRandom as Integer
intRandom = System.Random.InRange(0, 1)
If intRandom = 0 Then
tfTextField.Text = "Goodnight"
Else
tfTextField.Text = "Good bye"
End If
And if you also want to use the phrases in different phases of the day
Var strPhrases1() As String
strPhrases1=Array("Phrase 01","Phrase 02","Phrase 03","Phrase 04","Phrase 05")
Var strPhrases2() As String
strPhrases2=Array("Phrase 06","Phrase 07","Phrase 08","Phrase 09","Phrase 10")
Select Case DateTime.Now.Hour
Case 0 To 12
tfTextField.Text = strPhrases1(System.Random.InRange(0,4))
Else
tfTextField.Text = strPhrases2(System.Random.InRange(0,4))
End Select