CallByName VB6 Question

Posted on 2005-04-28
Last Modified: 2009-12-16
Hi I want to use CallByName in a loop to change an array of  10 text box s  from visible to invisible

for i = 0 to 9
if CallByName text1 (0) .visible = True then CallByName  text1(0) .visible = False
next i

I know there are alterantives to changing property but I must use CallByName.

Does that make sense; can it be done?

Question by:NessieB
    LVL 4

    Expert Comment

    For i = 0 To 9
        CallByName Text1(i), "Visible", VbLet, False
    Next i

    Author Comment

    This is what I got so far

    I have textboxa to textboxj

    For i = 0 To 9
       If CallByName(CallByName(Me, "Textbox" & Chr$(97 + i), VbGet), "Visible", VbGet) = True Then
       CallByName Me, "textbox" & Chr$(97 + i), "Visible", VbLet, False
       End If
    Next i

    This doesnt work :(    Can you give me the code that does please?
    LVL 85

    Accepted Solution

    Option Explicit

    Private Sub Command1_Click()
        Dim i As Integer
        Dim c As Control
        For i = 0 To 9
            Set c = getControlByName("Textbox" & Chr$(97 + i))
            If Not c Is Nothing Then
                If CallByName(c, "Visible", VbGet) = True Then
                    Call CallByName(c, "Visible", VbLet, False)
                End If
            End If
        Next i
    End Sub

    Private Function getControlByName(ByVal controlname As String) As Control
        Dim c As Control
        controlname = LCase(controlname)
        For Each c In Me.Controls
            If LCase(c.Name) = controlname Then
                Set getControlByName = c
                Exit Function
            End If
    End Function

    Author Comment

    Thats the one ! Thanks IdleMind

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    Article by: Martin
    Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    760 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

    7 Experts available now in Live!

    Get 1:1 Help Now