Solved

Records???

Posted on 2004-04-16
3
201 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
ID: 10844269
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
ID: 10849339
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
ID: 10887742
Cheers guys! :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

789 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