Click here to Skip to main content
15,614,138 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please help me,
i'm using,
I have label1-label9 and button1 - button9

if I click the button1 ,then I want to shuffle the label.text randomly expect label1

if I click button 1 and button 5 then shuffle the label.text expect label1 & label 5

What I have tried:

Dim list = New List(Of String) From {lable1, label2,label3,label4,label5..."}
Dim rnd As New Random()
Dim shuffled = list.OrderBy(Function (x) rnd.Next()).ToList()
Updated 23-Mar-21 21:28pm
Maciej Los 23-Mar-21 15:48pm    

1 solution

If you would like to "remove" items from list which will not be used in shuffle, use Enumerable.Except Method (System.Linq) | Microsoft Docs[^]

Assuming that Button1 refers to Label1, Button2 refers to Label2 and so on... all buttons should refer to the same event - like this:
Private Sub Button_Click(sender As Object, e As EventArgs)
    Dim sName As String = DirectCast(sender, Button).Name 'Or Text
    sName = sName.Replace("Button", "Label")
    shuffled = list.Except(ignorelist).OrderBy(Function(x) rnd.Next()).ToList()
    'further instructions
End Sub

I'd suggest to declare list and ignorelist at the top of form's module.

Note: what happens when ignorelist will contain the same items as list?
Share this answer
Member 15115429 24-Mar-21 3:41am    
I must use Button and labe1, here button text will be 1,2..9 and label text will be category name..
i can click any button & corresponding label name should be same, other label name should shuffle

for example
1st time when i click button 5 & second time ciick button 2
labels name will shuffel except label 5 and label 2
Maciej Los 24-Mar-21 3:53am    
I did understand it earlier. The code provided by my is doing exactly what you said.
Member 15115429 24-Mar-21 4:17am    
thanks for your reply.
can u send me the code..
Member 15115429 24-Mar-21 6:01am    
Hi Maciej

Thanks for ur response..
iam basically designer..& also know programming
it will be great if you send me the project

its very urgent for me

Thanks lot

Member 15115429 24-Mar-21 23:57pm    
Hi Maciej..
Please help me in this
how to declare list and ignorelist is string?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900