Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
The subs below are each run from 2 command buttons on a form, Machine
Hours and Labour Hours. When the form is initially loaded it is with Machine hours in the txtMilla thru txtMille text boxes . The operator can then change from Machine Hours to Labour Hours by clicking the Labour Hours command button, likewise the operator can change the Labour Hours back to Machine Hours by clicking the Machine Hours command button. I need to overcome the problem of subsequence clicks on the same command button, for example, if the labour hours were clicked twice one could never get back to the original value of machine hours when the machine hours button is clicked. How would you code these such that after the labour hours command button is clicked it is somewhat disabled until the machine hours has been clicked. Or better yet can this be run from the same command button, as on initial loading of the form it displays Machine Hours in the text boxes, the command button caption could say Machine hours, but when pressed it would convert the values in the text boxes to Labour hours and display Labour Hours in the caption, then obvoiusly on subsequent clicks it would toggle between the two, but the values maintain integrity, any thoughts. Private Sub LabourHours_Click() Factor = 2.5 MachineHours.Font.Bold = False LabourHours.Font.Bold = True frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value * Factor frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value * Factor frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value * Factor frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value * Factor frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value * Factor End Sub Private Sub MachineHours_Click() Factor = 2.5 LabourHours.Font.Bold = False MachineHours.Font.Bold = True frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value * (1 / Factor) frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value * (1 / Factor) frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value * (1 / Factor) frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value * (1 / Factor) frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value * (1 / Factor) End Sub Regards burl_h |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Burl
There are a number of options but you need some type of flag to indicate the current status of the hours (machine or labour). 1. You can you two buttons and disable the other option 2. You could have one button and switch the caption 3. You could use a global flag and check the status on the button press. Lets look at 1. In you startup code set the me.LabourHours.enabled = true me.MachineHours.enabled = false then you need to switch the buttons when they are clicked: const Factor as double = 2.5 Private Sub LabourHours_Click() me.MachineHours.enabled= true me.LabourHours.enabled = false frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value * Factor frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value * Factor frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value * Factor frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value * Factor frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value * Factor End Sub Private Sub MachineHours_Click() me.MachineHours.enabled= false me.LabourHours.enabled = true frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value / Factor frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value / Factor frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value / Factor frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value / Factor frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value / Factor End Sub If you want one button and switch the text use say LabourHours LabourHours.caption = "Switch to Labour Hours" This i would set in the initialize section to make sure you get the text correct: Private Sub UserForm_Initialize() me.LabourHours.caption = "Switch to Labour Hours" End Sub then you need to the following: const Factor as double = 2.5 const szLab as string ="Switch to Labour Hours" const szMc as string ="Switch to Macine Hours" Private Sub LabourHours_Click() if me.LabourHours.caption = szLab then ' switch to labour me.LabourHours.caption = szMc ' switch text frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value * Factor frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value * Factor frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value * Factor frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value * Factor frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value * Factor else ' switch to machine me.LabourHours.caption = szLab ' switch text frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value / Factor frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value / Factor frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value / Factor frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value / Factor frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value / Factor end if End Sub The last option is a global flag define at the top of the module dim bFlagLab as boolean in the initialize section bflagLab=true then in each routine add for lab if bflagLab=true then bflaglab=false else beep exit sub end if for machine if bflagLab=false then bflaglab=true else beep exit sub end if The last one may be the wrong way round. -- Hope this helps Martin Fishlock, Bangkok, Thailand Please do not forget to rate this reply. "burl_h" wrote: The subs below are each run from 2 command buttons on a form, Machine Hours and Labour Hours. When the form is initially loaded it is with Machine hours in the txtMilla thru txtMille text boxes . The operator can then change from Machine Hours to Labour Hours by clicking the Labour Hours command button, likewise the operator can change the Labour Hours back to Machine Hours by clicking the Machine Hours command button. I need to overcome the problem of subsequence clicks on the same command button, for example, if the labour hours were clicked twice one could never get back to the original value of machine hours when the machine hours button is clicked. How would you code these such that after the labour hours command button is clicked it is somewhat disabled until the machine hours has been clicked. Or better yet can this be run from the same command button, as on initial loading of the form it displays Machine Hours in the text boxes, the command button caption could say Machine hours, but when pressed it would convert the values in the text boxes to Labour hours and display Labour Hours in the caption, then obvoiusly on subsequent clicks it would toggle between the two, but the values maintain integrity, any thoughts. Private Sub LabourHours_Click() Factor = 2.5 MachineHours.Font.Bold = False LabourHours.Font.Bold = True frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value * Factor frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value * Factor frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value * Factor frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value * Factor frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value * Factor End Sub Private Sub MachineHours_Click() Factor = 2.5 LabourHours.Font.Bold = False MachineHours.Font.Bold = True frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value * (1 / Factor) frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value * (1 / Factor) frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value * (1 / Factor) frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value * (1 / Factor) frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value * (1 / Factor) End Sub Regards burl_h |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Martin,
Thanks for the 3 solutions, I did try the first 2 and they worked great, I'm not sure I'll try the 3rd solution, it looks a little confusing, where the first two were quite simple to implement, thanks again for your response. burl_h Martin Fishlock wrote: Hi Burl There are a number of options but you need some type of flag to indicate the current status of the hours (machine or labour). 1. You can you two buttons and disable the other option 2. You could have one button and switch the caption 3. You could use a global flag and check the status on the button press. Lets look at 1. In you startup code set the me.LabourHours.enabled = true me.MachineHours.enabled = false then you need to switch the buttons when they are clicked: const Factor as double = 2.5 Private Sub LabourHours_Click() me.MachineHours.enabled= true me.LabourHours.enabled = false frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value * Factor frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value * Factor frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value * Factor frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value * Factor frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value * Factor End Sub Private Sub MachineHours_Click() me.MachineHours.enabled= false me.LabourHours.enabled = true frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value / Factor frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value / Factor frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value / Factor frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value / Factor frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value / Factor End Sub If you want one button and switch the text use say LabourHours LabourHours.caption = "Switch to Labour Hours" This i would set in the initialize section to make sure you get the text correct: Private Sub UserForm_Initialize() me.LabourHours.caption = "Switch to Labour Hours" End Sub then you need to the following: const Factor as double = 2.5 const szLab as string ="Switch to Labour Hours" const szMc as string ="Switch to Macine Hours" Private Sub LabourHours_Click() if me.LabourHours.caption = szLab then ' switch to labour me.LabourHours.caption = szMc ' switch text frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value * Factor frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value * Factor frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value * Factor frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value * Factor frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value * Factor else ' switch to machine me.LabourHours.caption = szLab ' switch text frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value / Factor frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value / Factor frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value / Factor frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value / Factor frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value / Factor end if End Sub The last option is a global flag define at the top of the module dim bFlagLab as boolean in the initialize section bflagLab=true then in each routine add for lab if bflagLab=true then bflaglab=false else beep exit sub end if for machine if bflagLab=false then bflaglab=true else beep exit sub end if The last one may be the wrong way round. -- Hope this helps Martin Fishlock, Bangkok, Thailand Please do not forget to rate this reply. "burl_h" wrote: The subs below are each run from 2 command buttons on a form, Machine Hours and Labour Hours. When the form is initially loaded it is with Machine hours in the txtMilla thru txtMille text boxes . The operator can then change from Machine Hours to Labour Hours by clicking the Labour Hours command button, likewise the operator can change the Labour Hours back to Machine Hours by clicking the Machine Hours command button. I need to overcome the problem of subsequence clicks on the same command button, for example, if the labour hours were clicked twice one could never get back to the original value of machine hours when the machine hours button is clicked. How would you code these such that after the labour hours command button is clicked it is somewhat disabled until the machine hours has been clicked. Or better yet can this be run from the same command button, as on initial loading of the form it displays Machine Hours in the text boxes, the command button caption could say Machine hours, but when pressed it would convert the values in the text boxes to Labour hours and display Labour Hours in the caption, then obvoiusly on subsequent clicks it would toggle between the two, but the values maintain integrity, any thoughts. Private Sub LabourHours_Click() Factor = 2.5 MachineHours.Font.Bold = False LabourHours.Font.Bold = True frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value * Factor frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value * Factor frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value * Factor frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value * Factor frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value * Factor End Sub Private Sub MachineHours_Click() Factor = 2.5 LabourHours.Font.Bold = False MachineHours.Font.Bold = True frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value * (1 / Factor) frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value * (1 / Factor) frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value * (1 / Factor) frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value * (1 / Factor) frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value * (1 / Factor) End Sub Regards burl_h |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to Hide Form and Command Buttons until such condition is true? | Excel Discussion (Misc queries) | |||
Cell name to change name in codes of command buttons | Excel Discussion (Misc queries) | |||
User form Command Buttons | Excel Discussion (Misc queries) | |||
Excel Form With Date Time Picker And Command Buttons | Excel Programming | |||
User Form Option & Command Buttons | Excel Programming |