473,324 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Checking if multiple textboxes have equal value??

How can i check if multiple textboxes have the same value??
Sure, i can do a bazillion if and else commands, but im sure it can be done in some easier way.

For example, i have 3 (lets say three to make it easy atm) textboxes where the user inputs a value in each, and it checks if any of these are equal to eachother?

This is something that i have been wondering about for quite some time =)
Nov 7 '06 #1
7 7412
willakawill
1,646 1GB
How can i check if multiple textboxes have the same value??
Sure, i can do a bazillion if and else commands, but im sure it can be done in some easier way.

For example, i have 3 (lets say three to make it easy atm) textboxes where the user inputs a value in each, and it checks if any of these are equal to eachother?

This is something that i have been wondering about for quite some time =)
Hi. You can use the Select Case test which would be easier to read but it would only return the first equality and ignore the rest. You would need n - 1 Select blocks for n textboxes. e.g. 4 textboxes...
Expand|Select|Wrap|Line Numbers
  1. Select Case CInt(txt1.Text)
  2.    Case CInt(txt2.Text)
  3.        blah blah blah
  4.    Case CInt(txt3.Text)
  5.       blah blah blah
  6.    Case CInt(txt4.Text)
  7.       blah blah blah
  8. End Select
  9.  
  10. Select Case CInt(txt2.Text)
  11.    Case CInt(txt3.Text)
  12.       blah blah blah
  13.    Case CInt(txt4.Text)
  14.       blah blah blah
  15. End Select
  16.  
  17. Select Case CInt(txt3.Text)
  18.    Case CInt(txt4.Text)
  19.       blah blah blah
  20. End Select
  21.  
Nov 7 '06 #2
Killer42
8,435 Expert 8TB
Hi. You can use the Select Case test which would be easier to read but it would only return the first equality and ignore the rest. You would need n - 1 Select blocks for n textboxes. e.g. 4 textboxes...
Blah blah blah... :)
If the textboxes are in an array then you could use a couple of nested loops. The advantage is that the code is not dependent on the number of controls. This isn't tested, just typed straight here, but I'm thinking something like
Expand|Select|Wrap|Line Numbers
  1. Dim I as Long, J as long
  2. ' Assuming number of textboxes is in variable Count...
  3. For I = 1 to Count - 1
  4.   For J = I + 1 to Count
  5.     If TextBox(J) = TextBox(I) Then
  6.       ' They are equal - do something.
  7.     End If
  8.   Next
  9. Next
Note, the I + 1 prevents you from repeating the same comparisons. Wouldn't do any harm, it's just inefficient. Note also, I've started my numbering from 1, but in fact constrol arrays normally start with index = 0. I just hate numbering from zero. :)
Nov 7 '06 #3
Thanks alot, the arrays worked great :D
Nov 8 '06 #4
How can I find out how many textboxes I have? Can you count them during runtime?
Nov 24 '06 #5
Killer42
8,435 Expert 8TB
How can I find out how many textboxes I have? Can you count them during runtime?
If you mean the number of them in the array, you can just retrieve it from the .Count property. For example, if the text boxes are called Text1, then Text1.Count will tell you the number of occurences. Keep in mind that by default, the indexes start from 0, so if .Count is 3 for instance, then they will be numbered from 0 to 2.

If you mean the number of textboxes in general on the form, then while there are probably better ways, you could try this sample code I just threw into a form in a test project.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Click()
  2.   Dim c As Control, i As Long
  3.   For Each c In Me.Controls
  4.     If TypeOf c Is TextBox Then
  5.       Debug.Print "Here's one: "; c.Name
  6.       i = i + 1
  7.     End If
  8.   Next
  9.   Debug.Print "Found "; Format(i); ' text box(es).'
  10. End Sub
Nov 25 '06 #6
willakawill
1,646 1GB
How can I find out how many textboxes I have? Can you count them during runtime?
Of course the easy way is to look at the form and count them :)
Nov 25 '06 #7
Killer42
8,435 Expert 8TB
Of course the easy way is to look at the form and count them :)
Of course, but it's so primitive. :)
Nov 25 '06 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Drew | last post by:
I have a db table like the following, UID, int auto-increment RegNo Person Relation YearsKnown Now here is some sample data from this table,
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
21
by: jacob navia | last post by:
Many compilers check printf for errors, lcc-win32 too. But there are other functions that would be worth to check, specially memset. Memset is used mainly to clear a memory zone, receiving a...
19
by: nitro_punk85 | last post by:
I'm working on a project for my c++ class and I am having trouble comparing one string to two others using the or operator. It looks something like this: if(answer3 == answer1 || answer2) Is...
9
by: D. Shane Fowlkes | last post by:
(ASP.NET 2 / VB) Question - How can I write a If statement to see if a control (textbox) actually exists on a page? Upon page_load, a certain control may or may not be visible on the page so I...
4
neo008
by: neo008 | last post by:
Hi all, Finally gave up and putting it here. I am new to visual basic stucked up with an error- Run time errors.'-2147217887 (8004021)': Multiple-step operation generated errors. check each...
3
by: pipeme | last post by:
Hi I am using Access 2003 and I have a form with 120 textboxes in a grid layout. Depending on a selection made in a combo box, I want to change the visibility of certain textboxes in the grid. ...
9
by: RayDube | last post by:
Hello Gents, I want to be able to reward my members with credits, banner advertisements, text advertisements and even cash, but on a partially manual basis. I created a page where I could...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.