Solved

easy array question

Posted on 2000-03-22
19
190 Views
Last Modified: 2010-05-02
I have an array of 32 textboxes

txtName(0)
txtName(1)
TxtName(2).....TxtName(31)

Objective:If one(or many) of these textboxes' backcolor is yellow, then it should open form1 else it should open form 2.

This is my current code but it will only work(shows form1) if all of the 32 textboxes' backcolor is yellow.  How can I make it show form1 even if only 1 textbox is yellow?
--------------------------
If TxtName(Index).BackColor = &H80FFFF Then

form1.Show
Else

form2.Show

End If

-------------------

Thanks much
0
Comment
Question by:ptran2000
  • 3
  • 3
  • 3
  • +7
19 Comments
 

Expert Comment

by:GinaP
ID: 2647579
Try this:

dim i as integer
dim bYellow as Boolean

bYellow = False
For i = 0 to Ubound(TxtName)
   If TxtName(i).BackColor = &H80FFFF Then
      form1.Show
      bYellow = True
   End If
next

if bYellow = False then
      form2.Show
end if
0
 
LVL 20

Expert Comment

by:hes
ID: 2647595
Dim x,Found
Found = False
For x = 0 to 31
 If TxtName(x).BackColor = &H80FFFF Then
   form1.Show
   Found = True
   Exit for
 End if
Next x
If Found = False then
   form2.show
End IF
0
 

Expert Comment

by:PIBM
ID: 2647626
Hes got it..  except that I would have done ..

dim Found as Boolean
Found = false
for x% = 0 to 31
....

Anyway =)
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 50 total points
ID: 2647929
these should all work but I dont see a need to go through every textbox. Once you find a match youre done.

Dim i As Integer
Dim Found As Boolean
Found = False
Do
If TxtName(i).BackColor= &H80FFFF Then
   form1.Show
   Found = True
End If
i = i + 1
Loop Until i = UBound(TxtName) Or Found = True

0
 

Expert Comment

by:AshokKumar
ID: 2648187
ptran2000. All these guys have given u the solution u required. What r u waiting for. Each one is a solution for the problem and the best being AzraSound for the loop runs only until the backcolor is found. U r done know. rate it guy
0
 
LVL 1

Expert Comment

by:RandyB30
ID: 2648463
Answering my first question here. I'm so excited :)  What form are you textboxes on. Here is code for 3 forms. replace names if you need to. Everybody let me know what you think.


Private Sub Command1_Click()
Dim sControl As Control

For Each sControl In form1
    If TypeOf sControl Is TextBox And sControl.BackColor = &H80FFFF Then
        Form2.Show
        Exit Sub
    End If
Next

    If Form2.Visible = False Then
        Form3.Visible = True
    End If
   
End Sub
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2648484
Hello RandyB30. Welcome to EE!

As many others have already posted suggestions similar to your own would you mind retracting your answer and leaving it in as a comment?
0
 

Expert Comment

by:AshokKumar
ID: 2648533
Let him be caraf_q. It is the author who has encouraged RandyB30 to post a diff. solution(atleast he thinks it is different) as the author haven't accepted the previous answers.
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2648561
But... the BIG disadvantage of randyb30's code is that form2 is loaded even if there is no need to. And you will get a fatal error if a control on your form does not a Backcolor property... I would recommend to use a somewhat optimized form of hes' code, something like...

  Dim a As Integer
 
  For a = txtName.LBound To txtName.UBound
    If (txtName(a).BackColor = &H80FFFF) Then
      Form2.Show
      Exit For
    End If
  Next
  If (a > txtName.UBound) Then Form3.Show
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 7

Expert Comment

by:Vbmaster
ID: 2648567
<gah> of course it should be Form1.Show inside the For..Next loop and Form2.Show in the last line. ;)
0
 
LVL 1

Expert Comment

by:RandyB30
ID: 2648573
Sure, it's retracted. Maybe you should answer. Looks like you need points more than I.
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2648586
<blush>
AshokKumar, you're right. RandyB30 - apologies!
0
 

Expert Comment

by:AshokKumar
ID: 2648598
Ptran2000. u r messing up with all those guys around here. Just go ahead and accept any one answer. What is taking you so much time. All are genuine solutions. Guys, pls. don't give any more version of answers to this guy.
0
 
LVL 1

Expert Comment

by:RandyB30
ID: 2648602
I see now that they are all comments. Doesn't matter Vbmaster caught the backcolor property mistake. Last answer from me.
0
 
LVL 5

Expert Comment

by:Bhaskar Ganapathe
ID: 2648866
Hi ptran2000,
   
   r u not satisfied with these expert's answer ?

   Then why u r waiting ?

   U need still more stuff ?

   Rate the Expert.

   
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2648905
Whoa, give ptran a chance... the question was posted Thursday, March 23 2000 - 02:56AM GMT. It's now 11:34AM GMT. It is therefore fair to assume that ptran is in a different time zone and fast asleep at this stage <G>
0
 

Author Comment

by:ptran2000
ID: 2650312
Thank you for all your responses, all were great. But, it is true what AzraSound said, "Once you find a match you're done"
0
 
LVL 20

Expert Comment

by:hes
ID: 2650892
ptran2000, so does my solution,(only loop until a match is found) that is
0
 

Expert Comment

by:PIBM
ID: 2651063
Yes, the solutions before azrasound where all stopping when a match was found.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
vb6 connector to SQL Server 2 34
How to make an ADE file by code? 11 79
Passing a Text Box name to a Sub 6 71
how to know if my Checkbox is True in VB6.0? 9 36
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now