[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

Records???

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
Sphinx5
Asked:
Sphinx5
2 Solutions
 
ramesh12Commented:
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
 
___XXX_X_XXX___Commented:
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
 
Sphinx5Author Commented:
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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now