473,385 Members | 1,402 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,385 software developers and data experts.

for next loop

72 64KB
Hi, just a quick question, I wonder if there a better way to write the lines below, just trying to simplify and learn more elegant ways of writing codes,
Thanks all, hope u all well


[code]
Dim i As Integer
Dim textTab As Variant
Dim ctl As Control

Expand|Select|Wrap|Line Numbers
  1. For i = 0 To 9
  2.         Set ctl = Me.Controls("cmd" & i + 1)
  3.         If i <= UBound(textTab) Then ctl.Caption = textTab(i)
  4.         If i > UBound(textTab) Then ctl.Visible = False
  5.   Next i
  6.  
Nov 23 '20 #1

✓ answered by twinnyfo

And even perhaps:

Expand|Select|Wrap|Line Numbers
  1. For i = 0 To 9
  2.     ctl.Visible = (i <= UBound(textTab))
  3.     ctl.Caption = IIf(i <= UBound(textTab), _
  4.                       textTab(i), _
  5.                       "")
  6. Next

3 4394
cactusdata
214 Expert 128KB
I would do like this:

Expand|Select|Wrap|Line Numbers
  1. For i = 0 To 9
  2.     Set ctl = Me.Controls("cmd" & i + 1)
  3.     If i <= UBound(textTab) Then 
  4.         ctl.Caption = textTab(i)
  5.         ' ???
  6.         ' ctl.Visible = True
  7.     else
  8.         ctl.Visible = False
  9.     End If
  10. Next
Nov 23 '20 #2
twinnyfo
3,653 Expert Mod 2GB
And even perhaps:

Expand|Select|Wrap|Line Numbers
  1. For i = 0 To 9
  2.     ctl.Visible = (i <= UBound(textTab))
  3.     ctl.Caption = IIf(i <= UBound(textTab), _
  4.                       textTab(i), _
  5.                       "")
  6. Next
Nov 30 '20 #3
Neruda
72 64KB
Uhh interesting, Thanks!
Dec 3 '20 #4

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

Similar topics

4
by: AndrewM | last post by:
Hello, I have a SUB which has input variables. If I run it once its okay, but I need to include it in a for....next loop. Can this be done ? for i=0 to 100 call mySub(arr(0,i)) next
8
by: Terry Olsen | last post by:
How do I loop back to the beginning of a for/next loop before getting to the end of it? Isn't there an "iterate" command or something like that? For Each This in That ...code if This = False...
7
by: wandoledzep | last post by:
I'm using Visual Studio .NET 2002 I remember there was a way to do this in C, so there should be a way of doing it in .NET: Instead of: Dim bolSquare1 as Boolean Dim bolSquare2 as Boolean...
6
by: Dave G | last post by:
I am writing a function to fill in the data in an unbound form. I have a table with field names of 1, 2, 3 etc up to approx 100. I have an unbound form with fields called 1, 2 3 etc. I gave...
2
by: BerkshireGuy | last post by:
I have a routine in Access that loops through an Excel workbook and executes code base on the worksheet name. If the worksheet name contains the word 'Stats' than that is a sheet I want to read...
1
by: Kevin | last post by:
ASP.NET 2.0 I have code that updates a database from a number of textboxes on a web form. I've had to hard coded references to my web form textboxes. I'd like to know how I can reference them...
7
by: muddasirmunir | last post by:
i am using vb6 i had make a for next loop which fill data into the table now , some time it may needed that we want to cancel that loop . now what is the code to exit the for next loop i want...
15
by: mygirl22 | last post by:
1.I have created a moving object (which is a button) in a form (rectangle box) called "Enjoy Button" and it moves when 2. a specific button named "Start Timer" is pressed...When the "Start Timer"...
3
by: smileyc | last post by:
I have 5 arrays, named array1 array2 array3 array4 array5. They are integer arrays each with 5 elements in them. I want to access all the elements in all the arrays using a for next loop,the pseudo...
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.