Copy info from one form to another VB 6

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Dec 2007
Posts: 74
Reputation: HB25 is an unknown quantity at this point 
Solved Threads: 0
HB25 HB25 is offline Offline
Junior Poster in Training

Copy info from one form to another VB 6

 
0
  #1
Dec 25th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 464
Reputation: invisal is a jewel in the rough invisal is a jewel in the rough invisal is a jewel in the rough 
Solved Threads: 49
invisal's Avatar
invisal invisal is offline Offline
Posting Pro in Training

Re: Copy info from one form to another VB 6

 
0
  #2
Dec 25th, 2007
frmsummary.lblfname0.Caption = frmWage.lblfirstname.Caption
Yesterday is a history, tomorrow is a mystery, today is a gift.
Behind every smile is a tear.
Visal .In
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 106
Reputation: SCBWV is an unknown quantity at this point 
Solved Threads: 16
SCBWV SCBWV is offline Offline
Junior Poster

Re: Copy info from one form to another VB 6

 
0
  #3
Dec 25th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 74
Reputation: HB25 is an unknown quantity at this point 
Solved Threads: 0
HB25 HB25 is offline Offline
Junior Poster in Training

Re: Copy info from one form to another VB 6

 
0
  #4
Dec 25th, 2007
Originally Posted by invisal View Post
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 218
Reputation: hkdani is an unknown quantity at this point 
Solved Threads: 24
hkdani's Avatar
hkdani hkdani is offline Offline
Posting Whiz in Training

Re: Copy info from one form to another VB 6

 
0
  #5
Dec 25th, 2007
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.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Option Explicit
  2. Public Type Employee
  3. Salary As Currency
  4. FirstName As String
  5. SurName As String
  6. HoursWorked As Single
  7. End Type
  8. Dim MyEmployees(10) As Employee

Hank
Last edited by hkdani; Dec 25th, 2007 at 6:20 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 74
Reputation: HB25 is an unknown quantity at this point 
Solved Threads: 0
HB25 HB25 is offline Offline
Junior Poster in Training

Re: Copy info from one form to another VB 6

 
0
  #6
Dec 25th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 218
Reputation: hkdani is an unknown quantity at this point 
Solved Threads: 24
hkdani's Avatar
hkdani hkdani is offline Offline
Posting Whiz in Training

Re: Copy info from one form to another VB 6

 
0
  #7
Dec 25th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 74
Reputation: HB25 is an unknown quantity at this point 
Solved Threads: 0
HB25 HB25 is offline Offline
Junior Poster in Training

Re: Copy info from one form to another VB 6

 
0
  #8
Dec 25th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 218
Reputation: hkdani is an unknown quantity at this point 
Solved Threads: 24
hkdani's Avatar
hkdani hkdani is offline Offline
Posting Whiz in Training

Re: Copy info from one form to another VB 6

 
0
  #9
Dec 25th, 2007
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.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Update_Array()
  2. With MyEmployees(ArrayCounter)
  3. .FirstName = txtFirstName.text
  4. .SurName = txtSurName.text
  5. .HoursWorked = txtHoursWorked.text
  6. .SalaryRate = txtSalaryRate.text
  7. End with
  8. ' Update the counter for the next employee
  9. ArrayCounter= ArrayCounter + 1

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

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. With MyEmployees(ArrayCounter)
  2. frmwagw.labelEmp1Name = .FirstName
  3. frmwagw.labelEmp1Surname = .SurName
  4. ' etc.
  5. frmummary.labelEmp1Name = .FirstName
  6. frmummary.labelEmp1SurName = .SurName
  7. ' etc
  8. End with
Last edited by hkdani; Dec 25th, 2007 at 8:28 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 106
Reputation: SCBWV is an unknown quantity at this point 
Solved Threads: 16
SCBWV SCBWV is offline Offline
Junior Poster

Re: Copy info from one form to another VB 6

 
0
  #10
Dec 25th, 2007
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC