Solved

Records???

Posted on 2004-04-16
3
198 Views
Last Modified: 2010-05-02
Hi there,

I'm REALLY struggling with doing records in VB. Currently I've got:

on main form:
a list box
a few edit boxes

in a module:
Public Type Data
    activity As String
    description As String
    tl As Integer
    tr As Integer
    bl As Integer
    br As Integer
    est As Long
    min As Long
    max As Long
End Type


What I'm wanting to do is create a few records of the type Data and have each record that is created have the activity field shown in the list box. There may be many similarities between the records including the activity field. I'm also wanting to save the records to a text file (in order) and maybe have an option to load them in again.

I'm quite happy to give it a go myself but I just can't seem to figure out how to create records??? Also I won't know until runtime how many records I'll need.

Can anybody help?
0
Comment
Question by:Sphinx5
3 Comments
 
LVL 7

Accepted Solution

by:
ramesh12 earned 125 total points
Comment Utility
You should use some thing like this in your form

create an empty array of the type you created like

dim x() as data

now whenever you want to add records use like this

redim preserve x(ubound(x)+1)

y=ubound(x)

x(y).activity="....."
x(y).description="..."
......

This is not perfect. BUt hope this gives you a start



0
 
LVL 6

Assisted Solution

by:___XXX_X_XXX___
___XXX_X_XXX___ earned 125 total points
Comment Utility
If you plan to save these records in file, you must set fixed length string in it's members or you will have problems storing such records in file, because if string members (activity and description) are with variable length, how will you know what is the length of each record when you save to file ? In fact, now with these variable length string members in your structre, they "occupy" 4 bytes because String is a pointer. Better declare type like this:
Public Type Data
    activity As String*255 ' Replace 255 with some number that can fix to your needs.
    description As String*255 ' Same here
    tl As Integer
    tr As Integer
    bl As Integer
    br As Integer
    est As Long
    min As Long
    max As Long
End Type


This structure is more easy to save/read from file.
0
 

Author Comment

by:Sphinx5
Comment Utility
Cheers guys! :)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now