SMOOTSARA Active Member Licensed User Longtime User Apr 19, 2021 #1 How can I print one of these 4 items by chance?? B4X: Dim str1() As String str1 = Array As String("no", "yes","ooo","test","yyy","nnn") Log(?????????) ? ?
How can I print one of these 4 items by chance?? B4X: Dim str1() As String str1 = Array As String("no", "yes","ooo","test","yyy","nnn") Log(?????????) ? ?
LucaMs Expert Licensed User Longtime User Apr 19, 2021 #2 Dim Index As Int = Rnd(0, str1.Length) Log(str1(Index)) Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Apr 19, 2021 #3 B4X: Dim str1() As String = Array As String("no", "yes","ooo","test","yyy","nnn") Dim str As String = str1(rnd(0, str1.Length)) Upvote 0
B4X: Dim str1() As String = Array As String("no", "yes","ooo","test","yyy","nnn") Dim str As String = str1(rnd(0, str1.Length))
LucaMs Expert Licensed User Longtime User Apr 19, 2021 #4 Erel said: B4X: Dim str1() As String = Array As String("no", "yes","ooo","test","yyy","nnn") Dim str As String = str1(rnd(0, str1.Length)) Click to expand... Mine is better ? Upvote 0
Erel said: B4X: Dim str1() As String = Array As String("no", "yes","ooo","test","yyy","nnn") Dim str As String = str1(rnd(0, str1.Length)) Click to expand... Mine is better ?
Star-Dust Expert Licensed User Longtime User Apr 19, 2021 #5 B4X: Dim str As String = Regex.Split(",","no,yes,ooo,test,yyy,nnn")(rnd(0, 6)) Upvote 0
udg Expert Licensed User Longtime User Apr 19, 2021 #6 Mine is better Click to expand... This one is even better B4X: Dim str1() As String = Array As String("no", "yes","ooo","test","yyy","nnn") Log(str1(rnd(0, str1.Length))) No unused vars (str and Index as from #2 and #3 above) .. Upvote 0
Mine is better Click to expand... This one is even better B4X: Dim str1() As String = Array As String("no", "yes","ooo","test","yyy","nnn") Log(str1(rnd(0, str1.Length))) No unused vars (str and Index as from #2 and #3 above) ..
LucaMs Expert Licensed User Longtime User Apr 19, 2021 #7 udg said: This one is even better B4X: Dim str1() As String = Array As String("no", "yes","ooo","test","yyy","nnn") Log(str1(rnd(0, str1.Length))) No unused vars (str and Index as from #2 and #3 above) .. Click to expand... I wrote that mine is better precisely because I used the variable Index which, in addition to being explanatory, is also "loggable" ? Upvote 0
udg said: This one is even better B4X: Dim str1() As String = Array As String("no", "yes","ooo","test","yyy","nnn") Log(str1(rnd(0, str1.Length))) No unused vars (str and Index as from #2 and #3 above) .. Click to expand... I wrote that mine is better precisely because I used the variable Index which, in addition to being explanatory, is also "loggable" ?
M Mahares Expert Licensed User Longtime User Apr 19, 2021 #8 If we are tabulating the number of ways, here is another: B4X: Dim MyList As List MyList.Initialize MyList.AddAll(Array ("no", "yes","ooo","test","yyy","nnn")) Log(MyList.Get(Rnd(0, MyList.Size))) Upvote 0
If we are tabulating the number of ways, here is another: B4X: Dim MyList As List MyList.Initialize MyList.AddAll(Array ("no", "yes","ooo","test","yyy","nnn")) Log(MyList.Get(Rnd(0, MyList.Size)))
Erel B4X founder Staff member Licensed User Longtime User Apr 19, 2021 #9 Quiz: What is the difference between: B4X: Dim MyList As List MyList.Initialize MyList.AddAll(Array ("no", "yes","ooo","test","yyy","nnn")) And: B4X: Dim MyList As List = Array ("no", "yes","ooo","test","yyy","nnn") ? Upvote 0
Quiz: What is the difference between: B4X: Dim MyList As List MyList.Initialize MyList.AddAll(Array ("no", "yes","ooo","test","yyy","nnn")) And: B4X: Dim MyList As List = Array ("no", "yes","ooo","test","yyy","nnn") ?
Star-Dust Expert Licensed User Longtime User Apr 19, 2021 #10 The second code generates an static collection and therefore it will no longer be possible to add or remove elements Last edited: Apr 19, 2021 Upvote 0
The second code generates an static collection and therefore it will no longer be possible to add or remove elements
Peter Simpson Expert Licensed User Longtime User Apr 19, 2021 #11 Star-Dust said: The second code generates an immutable list and therefore it will no longer be possible to add or remove elements Click to expand... You're quick on the draw today ? Upvote 0
Star-Dust said: The second code generates an immutable list and therefore it will no longer be possible to add or remove elements Click to expand... You're quick on the draw today ?
Star-Dust Expert Licensed User Longtime User Apr 19, 2021 #12 I would add that the array brings together data of the same type, while in the list you could put different data type Last edited: Apr 19, 2021 Upvote 0
I would add that the array brings together data of the same type, while in the list you could put different data type
M Mahares Expert Licensed User Longtime User Apr 19, 2021 #13 Erel said: What is the difference between: Click to expand... No difference to me. They are the same: B4X: MyList.Set(4, "erel") For Each s As String In MyList Log(s) Next The above works on both Upvote 0
Erel said: What is the difference between: Click to expand... No difference to me. They are the same: B4X: MyList.Set(4, "erel") For Each s As String In MyList Log(s) Next The above works on both
Erel B4X founder Staff member Licensed User Longtime User Apr 19, 2021 #14 Star-Dust said: I would add that the array brings together data of the same type, while in the list you could put different data type Click to expand... That's true if the array type is not Object (no type = Object). Mahares said: No difference to me. They are the same: Click to expand... Try: B4X: Dim MyList As List = Array ("no", "yes","ooo","test","yyy","nnn") MyList.Add("Mahares") Upvote 0
Star-Dust said: I would add that the array brings together data of the same type, while in the list you could put different data type Click to expand... That's true if the array type is not Object (no type = Object). Mahares said: No difference to me. They are the same: Click to expand... Try: B4X: Dim MyList As List = Array ("no", "yes","ooo","test","yyy","nnn") MyList.Add("Mahares")
LucaMs Expert Licensed User Longtime User Apr 19, 2021 #15 Star-Dust said: The second code generates an static collection and therefore it will no longer be possible to add or remove elements Click to expand... Yes but that is an old "story", so I'm thinking Erel means something else; or he forgot that he had already pointed that out to us ? Upvote 0
Star-Dust said: The second code generates an static collection and therefore it will no longer be possible to add or remove elements Click to expand... Yes but that is an old "story", so I'm thinking Erel means something else; or he forgot that he had already pointed that out to us ?
Erel B4X founder Staff member Licensed User Longtime User Apr 19, 2021 #16 I was referring to the old story... Upvote 0
LucaMs Expert Licensed User Longtime User Apr 19, 2021 #17 Erel said: I was referring to the old story... Click to expand... I am toooo old for that! ? Upvote 0
M Mahares Expert Licensed User Longtime User Apr 19, 2021 #18 Erel said: Try: B4X: Dim MyList As List = Array ("no", "yes","ooo","test","yyy","nnn") MyList.Add("Mahares") Click to expand... I was under the impression that when you use : MyList.set(.., you are actually removing and adding at the same time to come up with the 'replace'. Apparently, that is not the case with list. Upvote 0
Erel said: Try: B4X: Dim MyList As List = Array ("no", "yes","ooo","test","yyy","nnn") MyList.Add("Mahares") Click to expand... I was under the impression that when you use : MyList.set(.., you are actually removing and adding at the same time to come up with the 'replace'. Apparently, that is not the case with list.