×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Problems using a Public Array

Problems using a Public Array

Problems using a Public Array

(OP)
I want to store some data to a Public Array but the following Error Message appears:

"Complie error

Constants, fixed-length strings, arrays, user-defined types
and Declare statements not allowed as Public memebers of object modules."

I am using a UserForm to get the information at first time and, then, call the information from the array as needed.  What is the problem with my code?    Below you can see the code related with my problem.  



Public dd1
Public Data(1 To 100, 1 To 100, 1 To 14)
____________________________________________________________

Private Sub Calculate_Click()
Static d1
If SmallerPole = "" Or HigherPole = "" Or _
    Spacing = "" Or ElevationS = "" Or ElevationH = "" Then
        MsgBox "All Fields in 'Poles in Span' Must Be _
                Filled.", vbInformation, "Check"
    GoTo 10
ElseIf IsNumeric(HigherPole) = False Or _
       IsNumeric(SmallerPole) = False Then
    MsgBox "The IDs for Pole #1 and #2 must be Numbers.", _
            vbInformation, "Check"
    GoTo 10
ElseIf SmallerPole > HigherPole Or _
       SmallerPole = HigherPole Or _
       SmallerPole < 0 Or HigherPole < 0 Then
    MsgBox "Verify that the ID Number for Pole #1 is _
            smaller than the ID Number for Pole #2 and _
            that both of them are positive.", _
            vbInformation, "Check"
    GoTo 10
ElseIf IsNumeric(Spacing) = False Or _
       IsNumeric(ElevationS) = False Or _
       IsNumeric(ElevationH) = False Then
    MsgBox "Input Numeric Data for the Spacing, _
            Elevation #1 and Elevation #2.", _
            vbInformation, "Check"
    GoTo 10
ElseIf Clearance = "" And HT = "" Then
    MsgBox "Fill the Clearance or the Horizontal _
            Tension to Start the Calculations.", _
            vbInformation, "Check"
    GoTo 10
ElseIf Clearance <> "" And HT <> "" Then
    MsgBox "Just Fill the Clearance or the Horizontal _
            Tension.  Do Not Fill Both of Them.", _
            vbInformation, "Check"
    GoTo 10
ElseIf IsNumeric(Clearance) = False And HT = "" Then
    MsgBox "Input Numeric Data for the Clearance.", vbInformation, "Check"
    GoTo 10
ElseIf IsNumeric(HT) = False And Clearance = "" Then
    MsgBox "Input Numeric Data for the Horizontal _
            Tension.", vbInformation, "Check"
    GoTo 10
End If

d1 = d1 + 1
Data(d1, 1, 1) = SmallerPole
Data(d1, 1, 2) = HigherPole
Data(d1, 1, 3) = Spacing
Data(d1, 1, 4) = ElevationS
Data(d1, 1, 5) = ElevationH
Data(d1, 1, 6) = Clearance
Data(d1, 1, 7) = HT
Data(d1, 2, 1) = CodeWord1
Data(d1, 2, 2) = CodeWord2
Data(d1, 2, 3) = CodeWord3
Data(d1, 2, 4) = CodeWord4
Data(d1, 2, 5) = CodeWord5
Data(d1, 2, 6) = CodeWord6
Data(d1, 2, 7) = CodeWord7
Data(d1, 2, 8) = CodeWord8
Data(d1, 2, 9) = CodeWord9
Data(d1, 2, 10) = CodeWor10
Data(d1, 2, 11) = CodeWord11
Data(d1, 2, 12) = CodeWord12
Data(d1, 2, 13) = CodeWord13
Data(d1, 2, 14) = CodeWord14
Data(d1, 3, 1) = Quantity1
Data(d1, 3, 2) = Quantity2
Data(d1, 3, 3) = Quantity3
Data(d1, 3, 4) = Quantity4
Data(d1, 3, 5) = Quantity5
Data(d1, 3, 6) = Quantity6
Data(d1, 3, 7) = Quantity7
Data(d1, 3, 8) = Quantity8
Data(d1, 3, 9) = Quantity9
Data(d1, 3, 10) = Quantity10
Data(d1, 3, 11) = Quantity11
Data(d1, 3, 12) = Quantity12
Data(d1, 3, 13) = Quantity13
Data(d1, 3, 14) = Quantity14
Data(d1, 4, 1) = Delta1
Data(d1, 4, 2) = Delta2
Data(d1, 4, 3) = Delta3
Data(d1, 4, 4) = Delta4
Data(d1, 4, 5) = Delta5
Data(d1, 4, 6) = Delta6
Data(d1, 4, 7) = Delta7
Data(d1, 4, 8) = Delta8
Data(d1, 4, 9) = Delta9
Data(d1, 4, 10) = Delta10
Data(d1, 4, 11) = Delta11
Data(d1, 4, 12) = Delta12
Data(d1, 4, 13) = Delta13
Data(d1, 4, 14) = Delta14
dd1 = d1
10
End Sub
____________________________________________________________

Private Sub Spacing_Change()
Dim n As Byte
For n = 1 To dd1
    If Data(n, 1, 1) = SmallerPole And _
       Data(n, 1, 2) = HigherPole Then
        Spacing.Value = Data(n, 1, 3)
        End Sub
    End If
Next n
End Sub

RE: Problems using a Public Array

Put the line
Public Data(1 To 100, 1 To 100, 1 To 14)
in a module, not a form

RE: Problems using a Public Array

(OP)
FrancisL,  

When I use the Form, I have a Button "OK" so when I press it the information in the ComboBoxes are stored in an array.  Now, when I'm wrighting the data in the form the program check if the data for POle1 and Pole 2 exist in the same array and use the data in the array for those poles.  If the data for POLe1 and Pole 2 doesn't exists in the same array the program accept the new data and store it in the next array.

Now, if I put the "line" in the OK Botton, it will be ok; I mean, the program will work and it will not be erased any information from the array?

Thanks for your answer.. I'll be waiting for this one!!

RE: Problems using a Public Array

Did you try what I suggested?
"Constants, fixed-length strings, arrays, user-defined types
and Declare statements not allowed as Public memebers of object modules." means just that
 
Alternatively just change
Public Data(1 To 100, 1 To 100, 1 To 14)
to
Dim Data(1 To 100, 1 To 100, 1 To 14)

Francis

RE: Problems using a Public Array

(OP)
Thank you, FrancisL.  Your information worked.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources