Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have created a user-defined type in a standard module along with an array
of 12 of this user-defined type. I also have a form containing a command button. When the command button is clicked, I want a procedure run that uses the array of user-defined type. However, the Click event procedure in the form doesn't recognize the array. Am I missing something obvious? |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I think it would be useful for you to post some of your code. Specifically,
the code used to create the UDT and the array of 12 of them, the code the fills the array, the Click event code for your button and, if the "procedure run" is different for the Click event procedure, its code also. Rick "dunnerca" wrote in message ... I have created a user-defined type in a standard module along with an array of 12 of this user-defined type. I also have a form containing a command button. When the command button is clicked, I want a procedure run that uses the array of user-defined type. However, the Click event procedure in the form doesn't recognize the array. Am I missing something obvious? |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks Rick. Here's the code you asked for. Thanks. Sorry for the delay in
answering but I went to bed after posting. a) Setting up the UD type Public Type team teamname As String code As String manager As String m_email As String End Type Dim pmhc(1 To 12) As team b) Code To Fill The Array (takes information from a worksheet; Sub fill_array(pmhc() As team) ' In the worksheet called "Teams", the data is as follows: ' Column A - numbers 1 to 12 ' Column B - Name of team ' Column C - Team manager ' Column D - Team code ' Column E - Manager's email For x = 1 To 12 ' Populate the team name fields; tmp_range = "b" & Trim(Str(x)) pmhc(x).teamname = Worksheets("teams").Range(tmp_range).Value Next For x = 1 To 12 ' Populate the team code fields; tmp_range = "d" & Trim(Str(x)) pmhc(x).code = Worksheets("teams").Range(tmp_range).Value Next For x = 1 To 12 ' Populate the team manager fields; tmp_range = "c" & Trim(Str(x)) pmhc(x).manager = Worksheets("teams").Range(tmp_range).Value Next For x = 1 To 12 ' Populate the email fields; tmp_range = "e" & Trim(Str(x)) pmhc(x).m_email = Worksheets("teams").Range(tmp_range).Value Next End Sub c) The click event code from the user form: Sub cmd_Admin_Click() frm_main.Hide do_admin (pmhc()) End Sub |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I see two things that I think are causing you problems. One, if pmhc is
declared in the module, it should use Public, not Dim to declare it. Two, take the parentheses off of the do_admin call. The correct syntax is either this... do_admin pmhc() or this... Call do_admin(pmhc()) You should **only** use parentheses where **required** by syntax or in forcing precedence in an expression evaluation. The problem is that when you use non-syntax parentheses, VB assumes an expression is being evaluated. You can get away with this for single, simple variable arguments in function/subroutine calls because VB's evaluation of them as an expression is simply themselves. But complex things, like Type arrays, multiple arguments, and such are another story and VB doesn't know what to do with them. You might be able to get away with complex things like an Object, such as a control name, but that is because the Object has a default property and VB will use that as the evaluation of the Object and, if the data type matches what the function or subroutine is expecting, will pass it with out raising an objection. The best rule to follow, though, is to use parentheses only when required and not to "pretty things up". Rick "dunnerca" wrote in message ... Thanks Rick. Here's the code you asked for. Thanks. Sorry for the delay in answering but I went to bed after posting. a) Setting up the UD type Public Type team teamname As String code As String manager As String m_email As String End Type Dim pmhc(1 To 12) As team b) Code To Fill The Array (takes information from a worksheet; Sub fill_array(pmhc() As team) ' In the worksheet called "Teams", the data is as follows: ' Column A - numbers 1 to 12 ' Column B - Name of team ' Column C - Team manager ' Column D - Team code ' Column E - Manager's email For x = 1 To 12 ' Populate the team name fields; tmp_range = "b" & Trim(Str(x)) pmhc(x).teamname = Worksheets("teams").Range(tmp_range).Value Next For x = 1 To 12 ' Populate the team code fields; tmp_range = "d" & Trim(Str(x)) pmhc(x).code = Worksheets("teams").Range(tmp_range).Value Next For x = 1 To 12 ' Populate the team manager fields; tmp_range = "c" & Trim(Str(x)) pmhc(x).manager = Worksheets("teams").Range(tmp_range).Value Next For x = 1 To 12 ' Populate the email fields; tmp_range = "e" & Trim(Str(x)) pmhc(x).m_email = Worksheets("teams").Range(tmp_range).Value Next End Sub c) The click event code from the user form: Sub cmd_Admin_Click() frm_main.Hide do_admin (pmhc()) End Sub |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Worked like a charm, Rick. Many thanks for your help.
"Rick Rothstein (MVP - VB)" wrote: I see two things that I think are causing you problems. One, if pmhc is declared in the module, it should use Public, not Dim to declare it. Two, take the parentheses off of the do_admin call. The correct syntax is either this... do_admin pmhc() or this... Call do_admin(pmhc()) You should **only** use parentheses where **required** by syntax or in forcing precedence in an expression evaluation. The problem is that when you use non-syntax parentheses, VB assumes an expression is being evaluated. You can get away with this for single, simple variable arguments in function/subroutine calls because VB's evaluation of them as an expression is simply themselves. But complex things, like Type arrays, multiple arguments, and such are another story and VB doesn't know what to do with them. You might be able to get away with complex things like an Object, such as a control name, but that is because the Object has a default property and VB will use that as the evaluation of the Object and, if the data type matches what the function or subroutine is expecting, will pass it with out raising an objection. The best rule to follow, though, is to use parentheses only when required and not to "pretty things up". Rick "dunnerca" wrote in message ... Thanks Rick. Here's the code you asked for. Thanks. Sorry for the delay in answering but I went to bed after posting. a) Setting up the UD type Public Type team teamname As String code As String manager As String m_email As String End Type Dim pmhc(1 To 12) As team b) Code To Fill The Array (takes information from a worksheet; Sub fill_array(pmhc() As team) ' In the worksheet called "Teams", the data is as follows: ' Column A - numbers 1 to 12 ' Column B - Name of team ' Column C - Team manager ' Column D - Team code ' Column E - Manager's email For x = 1 To 12 ' Populate the team name fields; tmp_range = "b" & Trim(Str(x)) pmhc(x).teamname = Worksheets("teams").Range(tmp_range).Value Next For x = 1 To 12 ' Populate the team code fields; tmp_range = "d" & Trim(Str(x)) pmhc(x).code = Worksheets("teams").Range(tmp_range).Value Next For x = 1 To 12 ' Populate the team manager fields; tmp_range = "c" & Trim(Str(x)) pmhc(x).manager = Worksheets("teams").Range(tmp_range).Value Next For x = 1 To 12 ' Populate the email fields; tmp_range = "e" & Trim(Str(x)) pmhc(x).m_email = Worksheets("teams").Range(tmp_range).Value Next End Sub c) The click event code from the user form: Sub cmd_Admin_Click() frm_main.Hide do_admin (pmhc()) End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Passing an array in a user defined function | Excel Programming | |||
Type Mismatch: array or user defined type expected | Excel Programming | |||
Help: Compile error: type mismatch: array or user defined type expected | Excel Programming | |||
Passing User Defined Type Array to Listbox | Excel Programming | |||
Passing an Array of User-Defined Type to an Argument of a Function | Excel Programming |