Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-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!

*Tek-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

Visual Basic (Classic) FAQ

Access Version or Conversion

How to put and access different types of data easily in an array? by vincentmairiaux
Posted: 5 Apr 01

Unfortunately, there is no such a thing as a variable type called "InputDataFromMyTestSessionOnThisParticularCase".
But you can create it. Nice? Easy? Yup:
Create your new type of variable, called e.g. TestResult (or anything you want), composed of several conventional variable types proposed by VB6. Once this new variable is created, you can declare an array of this new type of variant. Each component inside the new variable can be accessed separately (read from and write to it).
For an example, do exactly as described:
1. create a new project in VB6
2. click on project in the menu bar, select Add Module
3. double click on this new module to open it
4. copy and paste the following code between ***** lines into the module:

'first declare the new type of variable:
Type TestResult
    Today As Date
    TimeOfTest As String * 8 'rem: means 8 characters in each string
    Var1 As Single 'or Integer if ther are no decimals
    Var2 As Single
    Var3 As Single 'even more "Varx" as you need them
End Type

'then declare the array made of your new type of variable:
Public TestResults(100) As TestResult

5. get back to the form in your project
6. place a humble command button on your form, called Command1 (what a humor!)
7. double click on it, and copy and paste the following code (also between the ****** lines:

Private Sub Command1_Click()
    TestResults(50).Var1 = 5.2
    Debug.Print TestResults(50).Var1
    Debug.Print TestResults(50).Var2
End Sub

8. run the application (press F5)
9. click on the button on the screen, and stop the application
10. look at the debug-window: you should read 5,2 (result of TestResults(50).Var1 containing that value) and 0 (result of TestResults(50).Var2 which is still empty).
Understood how it works? You can put any type of VB variables inside your own new variable. Further inside your code, separate the new variable name by a dot (.) to its component in order to access one of its component.
If you don't know how many items you will need to put in your array, declare a dynamic array and apply in your code the "Redim" method or the "Redim Preserve" method to e.g. increment the array before writing to it.
If any problem, email me.
Good luck.

reach me at vincent.mairiaux@yucom.be

Back to Visual Basic (Classic) FAQ Index
Back to Visual Basic (Classic) Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close