Hi
I am working on a payroll program which have 3 forms.
First form has three text box (First name, Surname, Total Hour) and one command button Calculate.
After the user put the info he/she will click calculate button and this will show the second form which display the (firstname, surname, Gross salary, netwage).
I do have another form called frmsummary this form should hold detail of up to 10 person, currently using the code bellow in form two when user click copy info command button on the second form I could only copy 1 person info to form 3. I don’t know what to do any help to get 10 people info coped?

Private Sub cmdcd_Click()
frmsummary.lblfname0 = frmWage.lblfirstname.Caption
frmsummary.lblsname0 = frmWage.lbllastname.Caption
frmsummary.lblgsalary = frmWage.lblGrossSalary.Caption
frmsummary.lblnwage = frmWage.lblNetWage.Caption
frmsummary.Show
End Sub

Thanks for your help in advance
HB25

You can use frmsummary.lblfname0.Caption = frmWage.lblfirstname.Caption or you can put the captions / text in public variables which are accessible to any form.

frmsummary.lblfname0.Caption = frmWage.lblfirstname.Caption

Thank you for your reply, at the moment without using lblfname0.caption I could copy detail of 1 person but what I wont to do is the frmsummary be able to display information of up to 10 people

I would declare a Public Array of your own type: You can declare the amount in the array to begin with or assign the amount dynamically with a Redim statement.

Option Explicit
Public Type Employee
   Salary As Currency
   FirstName As String
   SurName As String
   HoursWorked As Single
End Type
Dim MyEmployees(10) As Employee

Hank

Thanks for your reply, but I don’t know how to use this code, i could copy one person name using the above code. BTW in frmsummary I only need to display (First Name, Surname, GrossSalary, NetWage) Thanks for your help

You have to update the Array.

MyEmployees(0) Would be your first employee

MyEmployees(1) Would be your second employee, etc.

Using the different values in the array, you have separate storage area for each employee. Once you've stored the values corresponding to one member, it can be later accessed by remembering the Array Value.

Or you can even search the Array until you find the Name you're looking for using a loop.

MyEmployees(1).Name


MyEmployees(2).Name

hkdani you have been very helpful but you miss understand me I don’t have 10 emplyee what I have in frmsummary which is my last form does have 10 lable under first name, 10 lable under surname, 10 lable under Gross Salary and 10 lable under Netpay. I need these lables to be updated after user use from one “frminput” to input the info and then in form two “frmwagw” click on cmdcd( which is for copying the info in this form to frmsummary)
hope you understand above, I would like to send you the project but I don’t how to do that I wonder if accept I send you my email address
Thanks

You can use the Public type as a means of storage. You might want to add a regular module (not a class module) to your product to declare it in that section as I mentioned before. You could also declare a Public Variable ArrayCounter for your array in the same module.

But you need to change the Array Counter as new employee information is entered for each different employee. As long as you don't close your program down, the information will remain in memory. I don't know how you determine when your done collecting your information, but at that point, if you're using the Public type Array, you should enter that information at that time:

Your first input form (frmInput) will copy the info into the Array.

Private Sub Update_Array()
With MyEmployees(ArrayCounter)
   .FirstName = txtFirstName.text
   .SurName = txtSurName.text
   .HoursWorked = txtHoursWorked.text
   .SalaryRate = txtSalaryRate.text
End with
' Update the counter for the next employee
ArrayCounter= ArrayCounter + 1

Now you can use that info once its stored in the Public Type to copy into your other forms.

With MyEmployees(ArrayCounter)
  frmwagw.labelEmp1Name = .FirstName
  frmwagw.labelEmp1Surname = .SurName
  ' etc.
  frmummary.labelEmp1Name = .FirstName
  frmummary.labelEmp1SurName = .SurName
  ' etc
End with

Well, there's lots of ways to do this. For example, you could have labels for all 10 on the summary for and populate each individually from the first two forms. You could have the summary form contain a list control with columns that is populated from the other forms.

Well, there's lots of ways to do this. For example, you could have labels for all 10 on the summary for and populate each individually from the first two forms. You could have the summary form contain a list control with columns that is populated from the other forms.

Thanks SCBWV but could you explain in some more detial, i do have the lables for all 10 on the summary but i don't know how i could populate each individual from the first two form.

Well, you could just send us your code. And we would just send it back to you finished. But the whole point of these forums is to help the person.

If you find yourself stuck, you need to sweat a little. The brain is like other muscles in the sense that you need to use it before it can grow stronger.

You have reached an impasse. You need to sweat.

In the Form_Load event of the summary form, load the captions from the other two forms.

It's probably NOT how I would populate data from one form to another, but if you insist on doing so with labels, I suggest making the labels a control array so you can populate them in a for / next loop:

for i - 0 to 9
frmsummary.label(i). caption = form1.label(i).caption
next

Thank you (hkdani and SCBWV ) for your replies, I had a feeling that only with array my problem will get solved but my problem is I never understand arrays. I am planning to take one thing at a time. As I will have 10 lableI for (fname,sname, grosssalary,netwage) in frmsummary do I have to do something like below, and declared at the top of the frmsummary.

Dim lblfname (10) As String
Dim lblsname (10) as string
Dim lblgrosssalary (10) as Integer
Dim lblnetwage (10) as Integer

Thanks for your help

Dim lblfname (10) As String
Dim lblsname (10) as string
Dim lblgrosssalary (10) as Integer
Dim lblnetwage (10) as Integer

Yes, that will declare an array with 11 values (0 -10). But when you use Dim, the Array's scope is limited to the form. You can only use that variable within your form.

Use the Public declaration to make it available to other forma within your project

Option Explicit
Public lblsname(10) as String
....

Then you'll have to access it using the name of the form first like so:

frmInput.lblsname(0) = "MyInput"

You can avoid this if you add a module to your project and declare the Public Array in that module. Then you can access it without having to name the name of the form.

Hank

The easiest way to make a control array is to create the first control, then copy and paste the others. The first time you paste the control, Visual Basic will ask you if you want to create a control array. Say yes. From then on, every copy you paste will be in the control array.

A couple points:

Control arrays require an index. For instead of lblfname.caption, it becomes lblfname(index).caption, where index is a number. The nice thing about control arrays is that they all share the same event procedures... click, change, etc. The Index argument of the procedure will tell you which control fired the event.

Control arrays default to an index of 0, although you can change it to 1. Therefore, the first control in the array will be 0; lblfname(0). So for your 10 labels it ranges from lblfname(0) to lblfname(9).

Thank you for your help guys

I have created a model and I have put the fallowing in it:
Option Explicit
Public lblfname(9) As String
Public lblsname(9) As String
Public lblgsalary(9) As Integer
Public lblnwage(9) As Integer

At the same time I have created a control array and that is by creating the first control, then copy and paste the others in frmsummary, therefore I have 10 labels for each of them (First name, Surname, gross salary and Net wage) .

and finally in frmwage which is the form display the information including (First name, Surname, gross salary and Net wage) I have put the fallowing code behind the command button (Copy Info) so it copy these info to frmsummary :

frmsummary.lblfname(0) = frmWage.lblfirstname.Caption
frmsummary.lblsname(0) = frmWage.lbllastname.Caption
frmsummary.lblgsalary(0) = frmWage.lblGrossSalary.Caption
frmsummary.lblnwage(0) = frmWage.lblNetWage.Caption
ArrayCounter = ArrayCounter + 1
frmsummary.Show

But the above still does not work it will only update the first label when the user put new info using frminput form e.g putting new (first name, surname and Total hours)

Thanks for helping, I am new to vb and I would like to learn

Your syntax is wrong for the control array. frmsummary.lblfname(0) = frmWage.lblfirstname.Caption should be frmsummary.lblfname(0).caption = frmWage.lblfirstname.Caption

I don't think you're understanding the suggestions. If the labels are controls, you don't need to Dim strings.

In frmwage and your other form, text boxes should gather the user input. Then in the Form_Load event of the frmsummary form, you can use something like this:

Private Sub Form_Load()
for i = 0 to 9
frmsummary.lblfname(i).Caption = frmWage.lblfirstname(i).Caption
'use frmsummary.lblfname(i).Caption = frmWage.lblfirstname(i).Text for Text Boxes
next
end sub

Can you attach a zip file of your forms?

Your syntax is wrong for the control array. frmsummary.lblfname(0) = frmWage.lblfirstname.Caption should be frmsummary.lblfname(0).caption = frmWage.lblfirstname.Caption

I don't think you're understanding the suggestions. If the labels are controls, you don't need to Dim strings.

In frmwage and your other form, text boxes should gather the user input. Then in the Form_Load event of the frmsummary form, you can use something like this:

Private Sub Form_Load()
for i = 0 to 9
frmsummary.lblfname(i).Caption = frmWage.lblfirstname(i).Caption
'use frmsummary.lblfname(i).Caption = frmWage.lblfirstname(i).Text for Text Boxes
next
end sub

Can you attach a zip file of your forms?

Thank you SCBWV

I have fallowed your suggestion know it does copy the info to the frmsummary but it will copy the same info into all the labels. Please find attached the project as requested

Your code has many issues to be fixed... such as form placement, handling the backspace key, etc.

Anyway, I did what I could quickly. Try the attached.

You have to right click on the link and use "Save Target As" otherwise you will get a corrupt compressed file. Not sure why. Seems to be something with DaniWeb.

Thank you very much SCBWV
My problem has solved now as my problem was to be able to display 10 people info on the frmsummar and I will take care of the other problems. Thanks again :icon_smile:

Well, you're making good progress. I can tell that you're exercising your brain.

You're right at the edge. Personally, I prefer to understand what I'm doing and not have someone do all the work for me.

Seems that people appreciate, in the long run--maybe not in the short run--, the feeling they receive when they have worked at a goal and through their own efforts (maybe with a little guidance) have achieved their goal.

frmsummary.lblfname(0) = frmWage.lblfirstname.Caption
frmsummary.lblsname(0) = frmWage.lbllastname.Caption
frmsummary.lblgsalary(0) = frmWage.lblGrossSalary.Caption
frmsummary.lblnwage(0) = frmWage.lblNetWage.Caption
ArrayCounter = ArrayCounter + 1
frmsummary.Show

You just need to place a variable in your array location: frmSummary.labelsname(ArrayCounter)

instead of frmSummary.lblfname(0)

As you have it, the only value of the array that will be filled is the first one: instead of frmSummary.labelsname(0)


frmSummary.labelsname(ArrayCounter)

Just as a matter of style. If you're working with a text box, it's good style to start the name of that text box with txt, labels --> lbl, etc. so that you're code will be easier read, if you have to go back to that code and edit it later.

Hank

Well, you're making good progress. I can tell that you're exercising your brain.

You're right at the edge. Personally, I prefer to understand what I'm doing and not have someone do all the work for me.

Seems that people appreciate, in the long run--maybe not in the short run--, the feeling they receive when they have worked at a goal and through their own efforts (maybe with a little guidance) have achieved their goal.

frmsummary.lblfname(0) = frmWage.lblfirstname.Caption
frmsummary.lblsname(0) = frmWage.lbllastname.Caption
frmsummary.lblgsalary(0) = frmWage.lblGrossSalary.Caption
frmsummary.lblnwage(0) = frmWage.lblNetWage.Caption
ArrayCounter = ArrayCounter + 1
frmsummary.Show

You just need to place a variable in your array location: frmSummary.labelsname(ArrayCounter)

instead of frmSummary.lblfname(0)

As you have it, the only value of the array that will be filled is the first one: instead of frmSummary.labelsname(0)


frmSummary.labelsname(ArrayCounter)

Just as a matter of style. If you're working with a text box, it's good style to start the name of that text box with txt, labels --> lbl, etc. so that you're code will be easier read, if you have to go back to that code and edit it later.

Hank

Thank you hkdani for all your advice and guidance, I have tried what you are suggesting here to put frmSummary.labelsname(ArrayCounter) instead of frmSummary.lblfname(0) but still it will copy the info to the all the labels in frmsummary.

Anyway, again thanks for your help as my problem has been solved now by some help from yourself and SCBWV

but still it will copy the info to the all the labels in frmsummary.

You need to change the data before you copy it into the new array. If you don't write code to change or update the data, it won't change by itself.

Hank

This question has already been answered. Start a new discussion instead.