Hello

How do i reset 2 textbox text of out four textbox at random avoiding a textbox whose text = 'A'

for clarification.

i have

Textbox1.text = "B"
Textbox2.text = "C"
Textbox3.text = "A"
Textbox4.text = "D"

how do i set an empty value "" to any two textbox at random avoiding the textbox whose text is "A"

Thanks

Recommended Answers

All 4 Replies

Try this...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim t(4) As TextBox
        t(0) = Me.TextBox1
        t(1) = Me.TextBox2
        t(2) = Me.TextBox3
        t(3) = Me.TextBox4
        Dim cindex As Integer = 0
        For i As Integer = 0 To 3
            If t(i).Text.Trim = "A" Then
                cindex = i
            End If
        Next
        Dim j As Integer = 0
        Dim r As Integer = 0
        Dim rn As New Random
        Dim f As Integer = 999
        While (1)
            r = rn.Next(4)
            If r <> cindex And r < 4 And f <> r Then
                t(r).Text = ""
                f = r
                j += 1
                If j > 1 Then
                    Exit Sub
                End If
            End If
        End While
    End Sub
commented: you are great +0

thanks a million.. i appreciate ur help

If it helps please give reputation and mark the thread as solved...

ok. done

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.