• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1270
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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