Notifications
Clear all

Verificar se mais de 2 TextBox são iguais

4 Posts
2 Usuários
0 Reactions
955 Visualizações
(@bilokas)
Posts: 168
Reputable Member
Topic starter
 

Como verificar se 3 textbox ou mais tem o conteúdo igual?

 
Postado : 27/02/2014 11:30 am
(@gtsalikis)
Posts: 2373
Noble Member
 

A sua pergunta está um pouco genérica:

if textbox1.value = textbox2.value and textbox1.value = textbox3.value then Msgbox "os três textbox têm o mesmo valor"

 
Postado : 27/02/2014 11:44 am
(@bilokas)
Posts: 168
Reputable Member
Topic starter
 

no caso se eu tivesse uma 4ª textbox, ficaria assim:

if textbox1.value = textbox2.value and textbox1.value = textbox3.value and textbox1.value = textbox4.value then Msgbox "os quatro textbox têm o mesmo valor"

Ou seja, sempre comparo com a 1ª textbox usando o And?

 
Postado : 27/02/2014 12:06 pm
(@gtsalikis)
Posts: 2373
Noble Member
 

se vc quiser que todas sejam iguais, pode ser, porque:

se a textbox 1 for igual a textbox 2, qualquer uma que vc pegar vai representar as 2.

Outra opção, caso vc tenha várias (não testei pq não tenho o modelo da tua plan):

Dim i as integer, Counter as integer

Counter = 0
For i = 2 to 4 'tente usar o comando: textbox.count
If not textbox1.value = textbox&i.value then counter = counter + 1
Next i
If Counter = 0 then msgbox "todas as textbox têm o mesmo valor"

Ou essa (não testada)

Dim tb as control, Counter as integer

Counter = 0
For each tb in Me.Controls
If not textbox1.value = tb.value then counter = counter + 1
Next tb
If Counter = 0 then msgbox "todas as textbox têm o mesmo valor"

 
Postado : 27/02/2014 12:41 pm