Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Dynamic Object Naming

I have a problem, I am trying to convert one of my first programs to
be more stable. In doing so, I found that one of my form modules is
upwards of 550kb in size and I know that it is causing a lot of my
instability. I have offloaded all private subs to another module to
bring the size down, but I am faced with a number of similar
repetitive textbox_change subs.

The program is for a budget program for a software testing group, so I
have a ton of these textboxes with names like:
txtAlphaMGRHours
txtAlphaSrLeadHours
txtBetaSrTesterDays
txt1PartyTempTesterPeople

and so on...

Each name has 4 parts, for example 'txtAlphaMGRHours' has these parts:
1. 'txt', just a prefix
2. 'Alpha', the phase of the project
3. 'MGR', the row we are calculating
4. 'Hours', the column we are calculating

I have posted a link to the UI here for your reference:
http://drop.wowtcgdeckbuilder.com/budget.png

Here is the change code for the 'txtAlphaMGRHours' text box.
=============================================
Private Sub txtAlphaMGRHours_Change()
'runs when the box changes

If boolLoadAlpha = True Then Exit Sub
If InChange = True Then Exit Sub

InChange = True

'look for a trailing '.' or ','
Dim RightChar As String
RightChar = Right(Me.txtAlphaMGRHours.Value, 1)

If RightChar = "." Or RightChar = "," Then
Me.txtAlphaMGRHours.Value = Left(Me.txtAlphaMGRHours.Value, Len
(Me.txtAlphaMGRHours.Value) - 1)
End If

'check for a valid entry
Me.txtAlphaMGRHours.Value = ValidateChangeX
(Me.txtAlphaMGRHours.Value)

'assign the value to the Total Hours box
dblAlphaMGRTotalHours = Me.txtAlphaMGRPeople.Value * _
Me.txtAlphaMGRHours.Value * _
Me.txtAlphaMGRDays.Value

'get the total dollars for the phase
dblAlphaMGRTotalDollars = GetAlphaTotalDollars(1,
Me.txtAlphaMGRPeople.Value, _

Me.txtAlphaMGRHours.Value, _

Me.txtAlphaMGRDays.Value, _
dblMGRRate)

'assign the variable a value
Me.txtAlphaMGRTotalHours.Value = dblAlphaMGRTotalHours

'assign the variable a value
Me.txtAlphaMGRTotalDollars.Value = FormatCurrency
(dblAlphaMGRTotalDollars)

'assisgn the subphase hours
dblAlpha1Hours = dblAlphaMGRTotalHours + dblAlphaSrLeadTotalHours
+ _
dblAlphaProjectLeadTotalHours +
dblAlphaSrTesterTotalHours + _
dblAlphaTempTesterTotalHours

'Assign the SubPhase Dollars
dblAlpha1Dollars = dblAlphaMGRTotalDollars +
dblAlphaSrLeadTotalDollars + _
dblAlphaProjectLeadTotalDollars +
dblAlphaSrTesterTotalDollars + _
dblAlphaTempTesterTotalDollars

'call the subs that calc the Total Dollars and hours
AlphaTotalDollars
AlphaTotalHours

If RightChar = "." Or RightChar = "," Then
Me.txtAlphaMGRHours.Value = Me.txtAlphaMGRHours.Value &
RightChar
End If

InChange = False

End Sub
=============================================

First mistake I made the when I made this was not knowing how to use a
tab strip which would cut this down by 80%, but I don't have the time
to make a transition like that.

I was thinking about doing something like this...
==============================================
Public Sub HoursTestSub(ObjHours As MSForms.TextBox, _
ObjPeople As MSForms.TextBox, _
ObjDays As MSForms.TextBox)

'look for a trailing '.' or ','
Dim RightChar As String
RightChar = Right(ObjHours.Value, 1)

If RightChar = "." Or RightChar = "," Then
ObjHours.Value = Left(ObjHours.Value, Len(ObjHours.Value) - 1)
End If

'check for a valid entry
ObjHours.Value = ValidateChangeX(ObjHours.Value)
==============================================

But get stuck when i need to assign phase, position, type variables
like 'dblAlphaMGRTotalHours'

Any help here would be great, I may have to switch to tabstrip I
really want to get this down. FYI, the program runs with a form
module size of 590kb, but it requires a save before all the code is
run through.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Dynamic Object Naming

You can call Control object dynamically like below. this may be able to
reduce the amount of your code.


boxes = Array("Textbox1", "Textbox2", "Textbox3")
For Each box In boxes
Set mybox = ActiveSheet.OLEObjects(box)
mybox.Object.Text = "Joel"
Next box


"theSquirrel" wrote:

I have a problem, I am trying to convert one of my first programs to
be more stable. In doing so, I found that one of my form modules is
upwards of 550kb in size and I know that it is causing a lot of my
instability. I have offloaded all private subs to another module to
bring the size down, but I am faced with a number of similar
repetitive textbox_change subs.

The program is for a budget program for a software testing group, so I
have a ton of these textboxes with names like:
txtAlphaMGRHours
txtAlphaSrLeadHours
txtBetaSrTesterDays
txt1PartyTempTesterPeople

and so on...

Each name has 4 parts, for example 'txtAlphaMGRHours' has these parts:
1. 'txt', just a prefix
2. 'Alpha', the phase of the project
3. 'MGR', the row we are calculating
4. 'Hours', the column we are calculating

I have posted a link to the UI here for your reference:
http://drop.wowtcgdeckbuilder.com/budget.png

Here is the change code for the 'txtAlphaMGRHours' text box.
=============================================
Private Sub txtAlphaMGRHours_Change()
'runs when the box changes

If boolLoadAlpha = True Then Exit Sub
If InChange = True Then Exit Sub

InChange = True

'look for a trailing '.' or ','
Dim RightChar As String
RightChar = Right(Me.txtAlphaMGRHours.Value, 1)

If RightChar = "." Or RightChar = "," Then
Me.txtAlphaMGRHours.Value = Left(Me.txtAlphaMGRHours.Value, Len
(Me.txtAlphaMGRHours.Value) - 1)
End If

'check for a valid entry
Me.txtAlphaMGRHours.Value = ValidateChangeX
(Me.txtAlphaMGRHours.Value)

'assign the value to the Total Hours box
dblAlphaMGRTotalHours = Me.txtAlphaMGRPeople.Value * _
Me.txtAlphaMGRHours.Value * _
Me.txtAlphaMGRDays.Value

'get the total dollars for the phase
dblAlphaMGRTotalDollars = GetAlphaTotalDollars(1,
Me.txtAlphaMGRPeople.Value, _

Me.txtAlphaMGRHours.Value, _

Me.txtAlphaMGRDays.Value, _
dblMGRRate)

'assign the variable a value
Me.txtAlphaMGRTotalHours.Value = dblAlphaMGRTotalHours

'assign the variable a value
Me.txtAlphaMGRTotalDollars.Value = FormatCurrency
(dblAlphaMGRTotalDollars)

'assisgn the subphase hours
dblAlpha1Hours = dblAlphaMGRTotalHours + dblAlphaSrLeadTotalHours
+ _
dblAlphaProjectLeadTotalHours +
dblAlphaSrTesterTotalHours + _
dblAlphaTempTesterTotalHours

'Assign the SubPhase Dollars
dblAlpha1Dollars = dblAlphaMGRTotalDollars +
dblAlphaSrLeadTotalDollars + _
dblAlphaProjectLeadTotalDollars +
dblAlphaSrTesterTotalDollars + _
dblAlphaTempTesterTotalDollars

'call the subs that calc the Total Dollars and hours
AlphaTotalDollars
AlphaTotalHours

If RightChar = "." Or RightChar = "," Then
Me.txtAlphaMGRHours.Value = Me.txtAlphaMGRHours.Value &
RightChar
End If

InChange = False

End Sub
=============================================

First mistake I made the when I made this was not knowing how to use a
tab strip which would cut this down by 80%, but I don't have the time
to make a transition like that.

I was thinking about doing something like this...
==============================================
Public Sub HoursTestSub(ObjHours As MSForms.TextBox, _
ObjPeople As MSForms.TextBox, _
ObjDays As MSForms.TextBox)

'look for a trailing '.' or ','
Dim RightChar As String
RightChar = Right(ObjHours.Value, 1)

If RightChar = "." Or RightChar = "," Then
ObjHours.Value = Left(ObjHours.Value, Len(ObjHours.Value) - 1)
End If

'check for a valid entry
ObjHours.Value = ValidateChangeX(ObjHours.Value)
==============================================

But get stuck when i need to assign phase, position, type variables
like 'dblAlphaMGRTotalHours'

Any help here would be great, I may have to switch to tabstrip I
really want to get this down. FYI, the program runs with a form
module size of 590kb, but it requires a save before all the code is
run through.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Naming a chart object Jeff M Charts and Charting in Excel 6 September 23rd 08 06:00 AM
Dynamic naming of worksheets Zyvind Excel Programming 1 December 10th 04 09:04 AM
Dynamic Sheet Tab Naming rpgun[_2_] Excel Programming 0 October 19th 04 12:36 AM
Dynamic Sheet Tab Naming rpgun Excel Programming 1 October 19th 04 12:01 AM
Dynamic Range Naming JMay Excel Programming 4 December 9th 03 11:17 PM


All times are GMT +1. The time now is 02:54 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"