borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Recent Docs in File Menu)Next Topic (Accessing File Atributes) New Topic New Poll Post Reply
AndreaVB Forum : VB General : Constants as an Array
Poster Message
SteveG
Level: Sage


Registered: 15-04-2002
Posts: 56

icon Constants as an Array  Archived to Disk

I have a section of a program (in a module) which is simply expressed as follows

Function Calc (ByVal Var1 As Double, ByVal VAr2 As Double) As Double

mdbl_A(1) = 2: mdbl_B(1) = 3: mdbl_C(1) = 11.375
mdbl_A(2) = 1: mdbl_B(2) = 0: mdbl_C(2) = 9.25
etc
mdbl_(43) = 0: mdbl_B(43) = 5: mdbl_C(43) = 0.25

for i = 1 to 43
     Calc = Calc + Var1^mdbl_A(i) + exp(mdbl_B(i) * Var2 ^ mdbl_C(i))
next i

end function

Later in the program I have to do different calculations using the same mdbl_.(..) values.

The only way I can see to do this is to duplicate all the variable in each function I have to calculate.

What I want to do is declare the variables (mdbl_.(..)) as constants but constants cannot be arrays in VB6 to the best of my knowledge.

Any help gratefully recieved.

05-07-2002 at 05:54 PM
View Profile Send Email to User Show All Posts | Quote Reply
Merrion
Level: VB Guru

Registered: 15-04-2002
Posts: 37
icon Re: Constants as an Array  Archived to Disk

You could declare them as an enumerated type e.g.


Pubic Enum MyConstants
   mdbl_A1 = 2
   mdbl_A2 = 1
   '...etc...
End Enum


HTH,
  Duncan

____________________________
--8<------------------------------
Free components and source code - see http://www.merrioncomputing.com/Download/index.htm for details

09-07-2002 at 08:43 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1617
icon Re: Constants as an Array  Archived to Disk

If you put a module, or if you have one form, you can also do the following:

' In a module, or form if only used in 1 form:

Public mdbl_A(43) As Double
Public mdbl_B(43) As Double
Public mdbl_C(43) As Double

Option Explicit

Public Function Init() As Boolean
    On Error Goto Err_Init
    mdbl_A(1) = 2: mdbl_B(1) = 3: mdbl_C(1) = 11.375
    mdbl_A(2) = 1: mdbl_B(2) = 0: mdbl_C(2) = 9.25
    ...
    mdbl_A(43) = 0: mdbl_B(43) = 5: mdbl_C(43) = 0.25
    Init=True
    Exit Function
Err_Init:
    Init=False
End Function
Public Function DeInit() as Boolean
' Not needed, but if you'd want
    On Error Goto Err_DeInit
    Erase mdbl_A
    Erase mdbl_B
    Erase mdbl_C
    DeInit=True
    Exit Function
Err_DeInit:
    DeInit=False
End Function

' In the form:
Private Sub Form_Load()
     Init
End Sub

09-07-2002 at 04:59 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
SteveG
Level: Sage


Registered: 15-04-2002
Posts: 56
icon Re: Constants as an Array  Archived to Disk

Many thanks for the help. It never ocurred to me to put the constants in a procedure and call that as needed. Obvious really !

20-07-2002 at 11:17 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB General : Constants as an Array
Previous Topic (Recent Docs in File Menu)Next Topic (Accessing File Atributes) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder