Results 1 to 8 of 8
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Denmark
    Posts
    347
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Forms - parsing parameters (WinXP/ O2003)

    Hi,

    This is a thing that has puzzled me a few times now and so far I haven't been able to figure out the answer.

    Often I want to parse a parameter to a form eg. to make dynamic adjustments pending users answer to certain questions.
    I would parse them to the initialize event - sometimes byval sometimes byref, sometimes optional sometimes mandatory, but...

    ...no matter how I try I always get an error informing me that parsing parameters to forms is not possible.

    ...and this puzzles me as I don't really understand why it shouldn't be possible.

    (My normal workaround - though far from optimal - is to create a global variable, that I can subsequently read and change from within the initialize procedure)

    ...so any insights will be highly appreciated.
    Bests,
    RD


    PS: Wish there were a knob on the TV to turn up the intelligence. There's a knob called "brightness," but that doesn't work

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Forms - parsing parameters (WinXP/ O2003)

    Can you give an example of what you've tried? I don't have the slightest idea what you're talking about.

  4. #3
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Denmark
    Posts
    347
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Forms - parsing parameters (WinXP/ O2003)

    OK.

    Want in Excel to color 2 chart types (pie and column) in various colors depending on users selection in a form.
    I have a command bar with top item "Charts" - sub menus "Pie" and "Column"
    For file size considerations I prefer to use only one form and let captions change dynamically depending on users selected type.

    For Pie selection I want the form to have 2 option buttons with captions "Color Red" and "Color Blue", whereas #3 is hidden.
    For Column he has 3 options "Default", "Mixed", "Special" - so no option button is hidden.

    Does this make more sense?
    Bests,
    RD


    PS: Wish there were a knob on the TV to turn up the intelligence. There's a knob called "brightness," but that doesn't work

  5. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Forms - parsing parameters (WinXP/ O2003)

    You still don't provide any information about the code that causes an error.

  6. #5
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Denmark
    Posts
    347
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Forms - parsing parameters (WinXP/ O2003)

    This is in a class module

    Public Sub PieStyle_Set(ByRef chtNMdefault As Chart, ByRef strCallerIs As String)
    Dim intSeriesCount As Integer
    Dim blnColorType As Boolean

    intSeriesCount = chtNMdefault.SeriesCollection.Count

    With chtNMdefault
    With .SeriesCollection(intSeriesCount)
    .Select

    If strCallerIs = "Blue" Then
    blnColorType = True 'Report style (3 colors of blue)
    Else
    blnColorType = False 'Default palette"
    End If

    frmColorBackground.Show blnColorType

    '..... depending on users answer I need to do some more code here...

    With .Border
    .ColorIndex = 38
    .Weight = xlMedium
    .LineStyle = xlContinuous
    End With

    .ApplyDataLabels AutoText:=True, LegendKey:=False, HasLeaderLines:=False, ShowSeriesName:=False, ShowCategoryName:=True, ShowValue:=False, ShowPercentage:=True, ShowBubbleSize:=False
    End With

    .ChartGroups(intSeriesCount).FirstSliceAngle = 300
    End With

    End Sub



    HERE'S THE FORM

    Private Sub UserForm_Initialize(Optional Byref blnColorType as boolean)

    With frmColorBackground

    ' If blnColorType = True Then
    ' .optBlue.Caption = "Default colors"
    ' .optMixed.Caption = "Report style (blue only)"
    ' .optWhite.Hide
    ' Else
    ' .optBlue.Caption = "Blue background (Default)"
    ' .optMixed.Caption = "Mixed background (blue/white)"
    ' .optWhite.Caption = "White background (ao. for slides)"
    ' End If

    .Caption = "Select background color"
    .optBlue.Value = True
    End With

    End Sub
    Bests,
    RD


    PS: Wish there were a knob on the TV to turn up the intelligence. There's a knob called "brightness," but that doesn't work

  7. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Forms - parsing parameters (WinXP/ O2003)

    The syntax of event procedures is fixed and cannot be modified. You cannot add new arguments, or omit existing arguments.

    You can define blnColorType as a public variable in the userform module; this makes it a property of the userform:

    <img src=/w3timages/blueline.gif width=33% height=2>

    In the userform module:

    Public blnColorType As Boolean

    Private Sub UserForm_Initialize() ' required format!
    With frmColorBackground
    If Me.blnColorType = True Then
    ...

    <img src=/w3timages/blueline.gif width=33% height=2>

    In a standard or class module:

    With frmColorBackground
    .blnColorType = True
    .Show
    End With

  8. #7
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Denmark
    Posts
    347
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Forms - parsing parameters (WinXP/ O2003)

    OK - thanks for the clarification.

    Is it then correct to assume that the public variable will live until I set the form = nothing?... or unload it
    Bests,
    RD


    PS: Wish there were a knob on the TV to turn up the intelligence. There's a knob called "brightness," but that doesn't work

  9. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Forms - parsing parameters (WinXP/ O2003)

    Yes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •