• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1249
  • Last Modified:

CallByName VB6 Question

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?


0
NessieB
Asked:
NessieB
  • 2
1 Solution
 
learning_t0_pr0gramCommented:
For i = 0 To 9
    CallByName Text1(i), "Visible", VbLet, False
Next i
0
 
NessieBAuthor Commented:
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?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
    Next
End Function
0
 
NessieBAuthor Commented:
Thats the one ! Thanks IdleMind
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now