Link to home
Start Free TrialLog in
Avatar of ptran2000
ptran2000

asked on

3rd Array question

What is the best way to do this.

On form1 I have an array of 32 textbox
txtValue(0))....txtValue(31)

On form2 I have an array of 32 checkboxes
chkValue(0)....chkValue(31)

When form2 opens it looks at form1 (form 1 is still open)

If form1.TxtValue(0).BackColor = &H80FFFF Then
ChkValue(0).value = 1
Else
ChkValue(0).value = 0
End If

If form1.txtValue(1).BackColor =&H80FFFF Then
ChkValue(1).value = 1
Else
ChkValue(1).value = 0
End If

........

Is there a better way to do this, instead of using a bunch of if statements?

thanks much
Avatar of AzraSound
AzraSound
Flag of United States of America image

You should look at the examples from your other two questions and note how loops were used and try to do this yourself first and then come here if you cant figure it out.
Avatar of ptran2000
ptran2000

ASKER

Would a loop be faster that a bunch of if statements, I'm really looking for performance.
well what in your program is making the backcolor yellow anyways? is it set at design time or is it something that happens at runtime?
ASKER CERTIFIED SOLUTION
Avatar of PIBM
PIBM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Dim i As Integer
For i = 0 to TxtValue.Ubound
If form1.TxtValue(i).BackColor = &H80FFFF Then
ChkValue(i).value = 1
Else
ChkValue(i).value = 0
End If
Next


thats if you want to use a loop
Explication : What is does is looping through all the box using a variable, giving the variable all the values of the textbox one after the other, and checking if that's right or not every times.
Azra is the same as mine, except that I used the % to "dim" my variable.
It is set at runtime by a user clicking on it.  It serves as an indicator that the value in that control will be changed.
then just add code there and then to set the checkbox value. right where you use that code to change the color just add one more line

form2.chkValue(index).Value = 1
yeah sorry bout that PIBM...you type faster than me I suppose
Thanks,   PIBM for being the faster typist.
hehe thanks for your point, with the question I asked I was down to 1 point. And finally I found out by myself =)