Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Textbox check problem... 2

Status
Not open for further replies.

keeyean

MIS
Sep 29, 2001
32
US
say... i have 3 Forms..
Form1 have 3 textboxes...
Text1, Text2, Text3
Form2 have 3 textboxes...
Text1, Text2, Text3
Form3 have 3 textboxes...
Text1, Text2, Text3

what i want to do is a check that..all the 9 textboxes cannot have the same text..
e.g.) Form1.Text1.Text and Form3.Text2.Text are A.. then a msg will be pop up..
 
Here's a function that may help you out:

------------------------------
Private Function AnyBlankTextboxes(frm As Form) As Boolean
Dim ctl As Control

For Each ctl In frm.Controls
If TypeOf ctl Is TextBox Then
If ctl.Text = "" Then
AnyBlankTextboxes = True
Exit For
End If
End If
Next

End Function
--------------------------------

You can use that function like this:
--------------------------------
If AnyBlankTextboxes(Form1) = True Then
MsgBox "A textbox is blank"
End If
--------------------------------

Good luck!

-Mike Any man willing to sacrifice liberty for security deserves neither liberty nor security.

-Ben Franklin
 
my idea of ..how the program work is:
1.)the user enter the letter in textboxes in Form1, then click "Next" to Form2...
2.)in the "Next" i want to check are the letter in the textboxes been used in the other 2 forms(Form2, Form3).
3.)if no... then will go to Form2....., if yes.. then a msgbox will pop up..

wish you can follow what i trying to do ...:)
 
Oh, the SAME text, not BLANK text, sorry!

You may benefit from making those textboxes a control array on each form. If they were named txtNumbers(0 to 2) then you could do this:
----------------------
'In a module:
Public Function CheckForDuplicates(txt1 As Object, txt2 As Object, txt3 As Object) As Boolean
Dim Values(8) As String
Dim valCounter As Long
Dim indxCounter As Long
Dim tmpValue As String
Dim numDupesDetected As Integer

'Store all values into Values() array:
For valCounter = 0 To 8
Select Case valCounter
Case 0, 1, 2
Values(valCounter) = txt1(indxCounter).Text
Case 3, 4, 5
Values(valCounter) = txt2(indxCounter).Text
Case 6, 7, 8
Values(valCounter) = txt3(indxCounter).Text
End Select
indxCounter = indxCounter + 1
If indxCounter = 3 Then indxCounter = 0
Next valCounter

'Loop through the values, checking for duplicates:
For valCounter = 0 To 8
tmpValue = Values(valCounter)
For indxCounter = (valCounter + 1) To 8
If tmpValue = Values(indxCounter) Then
numDupesDetected = numDupesDetected + 1
End If
Next indxCounter
Next valCounter

CheckForDuplicates = numDupesDetected > 0

End Function

'USAGE:

Private Sub cmdGo_Click()
If CheckForDuplicates(Form1.txtNumbers, Form2.txtNumbers, Form3.txtNumbers) = True Then
MsgBox "Dupe detected."
End If
End Sub

Hope that works for u, and sorry 'bout the confusion!

-Mike




Any man willing to sacrifice liberty for security deserves neither liberty nor security.

-Ben Franklin
 
i have an error msg"Method or data member not found"...on the "Form1.txtNumbers" in Private Sub cmdGo_Click().. do i need to define this??
 
Hmmm...
Make sure your array is named txtNumbers, and that the function is expecting Objects, not TextBoxes. Post your code if you have any other trouble...

-Mike Any man willing to sacrifice liberty for security deserves neither liberty nor security.

-Ben Franklin
 
wooh.... it's work..
but how do i ignore the blank text?? coz if i have 2 blank textbox... it will consider duplicate too...
and... can i setfocus to the textbox which has duplicate letter??
 
1.) Change this line:
If tmpValue = Values(indxCounter) Then

to this:
If tmpValue = Values(indxCounter) And tmpValue <> &quot;&quot; Then

that will eliminate blank textboxes

2.) Setting focus to the offending textbox could get tricky in your case, since there are 3 separate control arrays on 3 different forms. If you examine the code above, you could change the function to return an integer indicating the index of the duplicate array element. Just return valCounter instead of incrementing numDupesDetected. The index returned should be 0-8, and you know that 0-2 is on Form1, 3-5 on Form2, and 6-8 on Form3. Then convert those numbers to indicate the control array element (i.e. if the function returns 7, you can find that Form3.txtNumbers(1) is the dupe). Problem is, if the user has minimized the form, setting focus to its textbox will not bring the form back into view. If the form is behind another form (not minimized), it will bring the right form to the front. Change the form's BorderStyle to 1 - Fixed Single to make sure it won't be minimized.

Good luck!

-Mike Any man willing to sacrifice liberty for security deserves neither liberty nor security.

-Ben Franklin
 
I was just browseing some of the topics. I Just wanted to say, that even though at this time I don't have a use for this, it was still a good reading experience. I'm sure it will help me down the line someday. :)
 
hmm.. i'm not very sure about the setFocus problem...below is the code i try to check the duplicated number....but... it doesn't work...so.....

For valCounter = 0 To 2
If CheckForDuplicates(Form1.txtNumbers, Form2.txtNumbers, Form3.txtNumbers) = True Then
MsgBox &quot;Dupe detected.&quot;
Form1.txtNumbers(valCounter).SetFocus
Exit Sub
End If
Next valCounter

thanz you again...:)
 
i still can't find a way to solve the setfocus problem .. can someone give me a guide??
 
valCounter still needs to count to 8, not 2. That does not necessarily give you the index you need, but it will contain information you can use to get the index. If a duplicate is detected, and valCounter is 6, you can find which textbox contains the duplicate text. If valCounter is 0, 1, or 2, you know the problem is on the first form. If it is 3, 4, or 5, problem is on 2nd form, and so on. You can find this out kind of like this:

------------------------------
Dim DupeTextBox as TextBox

Select Case valCounter
Case 0, 1, 2
DupeTextBox = Form1.txtNumbers(valCounter)

Case 3, 4, 5
DupeTextBox = Form2.txtNumbers(valCounter - 3)

Case 6, 7, 8
DupeTextBox = Form3.txtNumbers(valCounter - 6)

End Select

DupeTextBox.SetFocus
----------------------------

I used valCounter in the above code, but if you changed the function to return valCounter, use the variable name that holds that return value, not valCounter.
Does that make sense?

-Mike
Any man willing to sacrifice liberty for security deserves neither liberty nor security.

-Ben Franklin
 
'Loop through the values, checking for duplicates:
For valCounter = 0 To 11
tmpValue = Values(valCounter)
For indxCounter = (valCounter + 1) To 11
If tmpValue = Values(indxCounter) And tmpValue <> &quot;&quot; Then
numDupesDetected = numDupesDetected + 1
'To hold the return value
HoldNumber= indxCounter
End If
Next indxCounter
Next valCounter

CheckForDuplicates = numDupesDetected > 0
dim DupeTextBox As TextBox
Select Case HoldNumber
Case 0, 1, 2
DupeTextBox = Form1.txtNumbers(HoldNumber)
Case 3, 4, 5
DupeTextBox = Form2.txtNumbers(HoldNumber- 3)
Case 6, 7, 8
DupeTextBox = Form3.txtNumbers(HoldNumber- 6)
End Select

End Function


Private Sub Command1_Click()
If CheckForDuplicates(Form1.txtNumbers, Form2.txtNumbers, Form3.txtNumbers) = True Then
MsgBox &quot;Dupe detected.&quot;
DupeTextBox.SetFocus
Exit Sub
End If
Form1.Hide
Form2.Show
End Sub

am i do it right?? coz it doesn't work..
i think the problem is the value of &quot;DupeTextBox&quot;.. coz it read the DupeTextBox=Nothing...
 
For valCounter = 0 To 11? Did you add another 3 textboxes? I'm going to assume you've placed them on Form4...

----------------------------------
Private Function CheckForDuplicates(txt1 as Object, txt2 as Object, txt3 as Object, txt4 as Object) as Integer

'Store all values into Values() array:
For valCounter = 0 To 8
Select Case valCounter
Case 0, 1, 2
Values(valCounter) = txt1(indxCounter).Text
Case 3, 4, 5
Values(valCounter) = txt2(indxCounter).Text
Case 6, 7, 8
Values(valCounter) = txt3(indxCounter).Text
Case 9, 10, 11
Values(valCounter) = txt4(indxCounter).Text
End Select
indxCounter = indxCounter + 1
If indxCounter = 3 Then indxCounter = 0
Next valCounter

For valCounter = 0 To 11
tmpValue = Values(valCounter)
For indxCounter = (valCounter + 1) To 11
If tmpValue = Values(indxCounter) And tmpValue <> &quot;&quot; Then
CheckForDuplicates = valCounter 'found dupe, return valCounter
Exit Function 'and get out
End If
Next indxCounter
Next valCounter
End Function

Private Sub Command1_Click()
Dim ReturnValue as Integer

ReturnValue = CheckForDuplicates(Form1.txtNumbers, Form2.txtNumbers, Form3.txtNumbers, Form4.txtNumbers)

Select Case ReturnValue

Case 0, 1, 2
Form1.txtNumbers(ReturnValue).SetFocus
Case 3, 4, 5
Form2.txtNumbers(ReturnValue- 3).SetFocus
Case 6, 7, 8
Form3.txtNumbers(ReturnValue- 6).SetFocus
Case 9, 10, 11
Form4.txtNumbers(ReturnValue - 9).SetFocus

End Select

End Sub

Hope that does it!

-Mike

Any man willing to sacrifice liberty for security deserves neither liberty nor security.

-Ben Franklin
 
no.. this doesn't work ... it can't check the duplicated letter too...:(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top