Solved

Calling function to fill textbox

Posted on 2006-10-19
6
191 Views
Last Modified: 2010-04-30
Hi,

I am trying to fill my textboxes using a function:

the actual textbox is in an array so it's named  txtM1(index)

I am trying to call the function :
....
Box_Down (txtM1)
.........


Private Function Box_Down(ByVal name As TextBox)
Dim ctl As Control
    For Each ctl In Me.Controls
        If TypeOf ctl Is TextBox Then
            ctl.Text = ""
        End If
    Next
'For z = 0 To 11
z = 0
While Not (z + arrCounterCode) = UBound(arrVerify) + 1
    Set name(z).Text = arrVerify(z + arrCounterCode, 0)
       Set name(z).Text = arrVerify(z + arrCounterCode, 1)
          Set name(z).Text = arrVerify(z + arrCounterCode, 2)
               Set name(z).Text = arrVerify(z + arrCounterCode, 3)
    z = z + 1
Wend
'Next
End Function

but I keep getting errors??
0
Comment
Question by:JamesBrian
  • 3
  • 2
6 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 125 total points
ID: 17766727
Several problems in there...

(1) To pass a Control Array, declare the parameter as Object.
(2) You are not returning anything so use a Sub not a Function.
(3) "Name" is not a good choice as this is already being used.
(4) Don't use "Set" with the "Text" property.
(5) Why are you setting the "Text" property of the SAME TextBox multiple times in the same iteration?
(6) The loop uses UBound(arrVerify) but we are accessing a Control Array.  Are you sure these two things are the same size?

Private Sub Command1_Click()
    Box_Down txtM1
End Sub

Private Sub Box_Down(ByRef ctlArray As Object)
    Dim ctl As Control
    For Each ctl In Me.Controls
        If TypeOf ctl Is TextBox Then
            ctl.Text = ""
        End If
    Next
       
    Dim z As Integer
    For z = 0 To UBound(arrVerify)
        ctlArray(z).Text = arrVerify(z + arrCounterCode, 0)
        ctlArray(z).Text = arrVerify(z + arrCounterCode, 1)
        ctlArray(z).Text = arrVerify(z + arrCounterCode, 2)
        ctlArray(z).Text = arrVerify(z + arrCounterCode, 3)
    Next
End Sub
0
 

Author Comment

by:JamesBrian
ID: 17766981
Idlemind said :
5) Why are you setting the "Text" property of the SAME TextBox multiple times in the same iteration?

oops, my mistake

originally, I called different textboxes in this loop

For z = 0 To 11
    textbox1(z).Text = arrVerify(z + arrCounterCode, 0)
       textbox2(z).Text = arrVerify(z + arrCounterCode, 1)
          textbox3(z).Text = arrVerify(z + arrCounterCode, 2)
               textbox4(z).Text = arrVerify(z + arrCounterCode, 3)
Next

How can I incorporate these four different textboxes in the same call?
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17767008
Next stupid question:

    Why are we passing in a Control Array to Box_Down() if you want to update SPECIFIC control arrays in your code?

Take a step back...

What is it you want to achieve with this procedure?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:JamesBrian
ID: 17767540
Well,

I have an array that holds 4 values(columns) per row
My screen shows 12 rows at a time.
When I come to the bottom of the screen, I want to show the next 12 rows and so on.

Thats why, when I get to the "new screen", I am looping through the array (arrverify), and I am
updating 4 textboxes (the 4 values)

I was thinking that something like this might do the trick:

Box_Down(txtM1,txtM2,txtEasy,txtQty) (these are the actual textbox names)

This explains also why the textboxes are in an array :

txtM1(0) txtM2(0)  txtEasy(0)  txtQty(0)
txtM1(1) and so on, all the way down to 11

Hope this sheds some light...

0
 
LVL 11

Assisted Solution

by:Dany Balian
Dany Balian earned 125 total points
ID: 17771718
i dont know if i got u straight or not...

here's a function that will reset the values of all the objects on ur form that have the same name and that have indexes in a specific range

Private Sub Box_Down(ByVal T As String, FromIndex As Integer, ToIndex As Integer)
    Dim i As Integer, ctl As Control
    For Each ctl In Me.Controls
        If ctl.name = T Then
            If ctl.Index >= FromIndex And ctl.Index <= ToIndex Then
                ctl.Text = "" ' read actual data from ur array
            End If
        End If
    Next
End Sub

you call the function by saying:

Box_Down  "txtM1", 0,3
this will change the values of the textboxes in the controlarray txtm1 that have indexes 0,1,2,3
please note that "txtM1" is a string value which corresponds to the name of the textbox...

hope this helps...
cheers,

Dan
0
 

Author Comment

by:JamesBrian
ID: 17773031
This is how I've done it, and got it to work:  
              Box_Up txtM1, 0
               Box_Up txtM2, 1
                Box_Up txtEasy, 2
                 Box_Up txtQty, 3

Private sub Box_Up (ByRef ctlArray As Object, position As Integer)
Dim ctl As Control
On Error GoTo errhandler
    If position = 0 Then
        For Each ctl In Me.Controls
            If TypeOf ctl Is TextBox Then
                ctl.Text = ""
            End If
        Next
    End If
    Dim z As Integer
    Y = 0
    For z = 0 To UBound(arrVerify)
        If Not Y + arrCounterCode = UBound(arrVerify, 2) + 1 Then
            ctlArray(z).Text = arrVerify(position, z + arrCounterCode)
        Else
    txtM1(0).SetFocus
            Exit Sub
        End If
        Y = Y + 1
    Next



0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

919 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

17 Experts available now in Live!

Get 1:1 Help Now