[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 227
  • Last Modified:

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
0
ptran2000
Asked:
ptran2000
  • 5
  • 4
  • 3
1 Solution
 
AzraSoundCommented:
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.
0
 
ptran2000Author Commented:
Would a loop be faster that a bunch of if statements, I'm really looking for performance.
0
 
AzraSoundCommented:
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?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
PIBMCommented:
For I% = 0 to 31
  If form1.TxtValue(I).BackColor = &H 80FFFF Then
    ChkValue(I).value = 1
  Else
    ChkValue(I).value = 0
  End If
Next I


That does it, and it's the fastest both programming & CPU time consuming way to do it. Can't remove the else or previous values would not be removed
0
 
AzraSoundCommented:
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
0
 
PIBMCommented:
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.
0
 
PIBMCommented:
Azra is the same as mine, except that I used the % to "dim" my variable.
0
 
ptran2000Author Commented:
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.
0
 
AzraSoundCommented:
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
0
 
AzraSoundCommented:
yeah sorry bout that PIBM...you type faster than me I suppose
0
 
ptran2000Author Commented:
Thanks,   PIBM for being the faster typist.
0
 
PIBMCommented:
hehe thanks for your point, with the question I asked I was down to 1 point. And finally I found out by myself =)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now