Results 1 to 18 of 18

Thread: I need a Dynamic User Defined Type!

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Unhappy THIS STILL ISN'T ANSWERED !!! PLEEEEEASE !!!

    I don't think this exists but some of you may have a way around the problem.

    I need to create a DB table like structure in memory, I was thinking about an array of UDTs which would be perfect but at design time I won't know the structure.

    eg the user may specify the "Table" like structure to have two string fields and three integer fields. This structure won't need to change during the life of the program but I need to create this memory structure temporarily.

    I was playing with cell objects in row objects but it was messy and briefly tried reDim varients with a new type but I won't know how many columns I need.

    I'd really rather not settle for an array of varient arrays, that would not be good.

    There must be a way of defining a memory structure at run time like you can at design time...

    Any ideas?
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  2. #2
    Fanatic Member
    Join Date
    Jan 1999
    Location
    UK
    Posts
    554

    Sure there is a way!!!

    eg the user may specify the "Table" like structure to have two string fields and three integer fields. This structure won't need to change during the life of the program but I need to create this memory structure temporarily.

    Code:
    'Module Level
    OPTIONBASE 1
    Public Type MyStructureInfo
      StringField1 as string * 30 'gives a string 30 chars long
      StringField2 as string * 30 'gives a string 30 chars long
      IntField1 as integer 'gives an integer field 2 bytes long
      IntField2 as integer 'gives an integer field 2 bytes long
      IntField3 as integer 'gives an integer field 2 bytes long
    End Type
    
    'implement one structure item
    Public MyStruct as MyStructInfo
    
    
    'implement a dynamic amount of the same structure
    Public AllStructs() as MyStructInfo
    
    
    
    
    PROCEDURE CODE:
    'add new ones by using redim 
    'and use preserve to preserve current contents
    'REDIMension array for upto 5 structs (1 to 5)
    Redim AllStructs(5) 
    
    'to access data
    MyStruct.StringField1 = "DocZaf"
    MyStruct.StringField2 = "Hello World"
    DocZaf
    {;->

    To clear structure
    AllStructs ERASE
    MyStruct ERASE

  3. #3
    Guest

    Thumbs up Damn Zaf got to it before me

    Yeap exactly right........Could always put it in a class l suppose. Just thought l would add my 2c worth

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Question

    ?????????

    This is not a dynamic UDT? This is a dynamic array of UDT. I know all about them. Sorry if I was vague what I meant was that the user will specify the table dimensions at RUN TIME! I can't write code like that because at design time I don't have the information. a different user may specify completely different criteria, or the same user may specify different table spec every time they use the app.

    When I said the structure won't need to change during the life of the program I meant from when it is run till when it is closed (while there is data in it) but at the begining of the session they need to specify the table dimensions

    A bit like when you set up a DB and you set the columns' data type, then once done it doesn't change (much) it just fills with data and is queried. I need that but in memory.

    I hope this is clearer

    Thanks
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  5. #5
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    Paul282:

    If I understand what you asking for, I think that this might work. You are just looking for a way of holding variables in memory, and the number of variables will be set at run-time. If this is the case, you can use something like the example below. Here you declare two dynamic arrays, and then redim them when you know their sizes. Anyway, it looks like this:

    Code:

    'These are your Global Variables
    Dim s() As String
    Dim i() As Integer


    Private Sub Command1_Click()
    b = InputBox("Set first Array")
    j = InputBox("Set Second array")

    'Use Redim Perserve s(b) as string
    'If you already have information
    'stored in the memory that you wish
    'to keep.

    ReDim s(b) As String
    ReDim i(j) As Integer

    For x = 0 To UBound(s)
    s(x) = x + 1
    Next

    For y = 0 To UBound(i)
    i(y) = y + 1
    Next

    End Sub

    Private Sub Command2_Click()
    For x = 0 To UBound(s)
    MsgBox s(x)
    Next

    For y = 0 To UBound(i)
    MsgBox i(y)
    Next

    End Sub


    I hope that this helps.

    (By the way, I am using VB6 SP3)

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    hmmmm.

    Close, But no Cigar!

    This effectively creates only two columns. I'm still racking my brain over this one and I have an idea with an array of Row() class which defines various cell classes

    Consider this:

    User1 requests the following structure

    5 Columns, 5000 rows
    Column1 = string
    Column2 = string
    Column3 = Date
    Column4 = Integer
    Column5 = Long

    User2 Requests the following structure

    20 Columns, 500 rows

    Column1 = Date
    Column2 = Date
    Column3 = string
    Column4 = string
    Column5 = string
    Column6 = string
    Column7 = Integer
    Column8 = Integer
    Column9 = Integer
    ...etc, you get the idea

    I need to effectively create a UDT array for each user but define the udt at run time (or simulate this) in memory (because I'll need more speed that a DB can deliver) which is also why I don't want variants. I'd like to work with the types (like a DB but in memory)

    I think I'll have to use classes & objects... it seems odd that this can't be done without OO




    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  7. #7
    Member
    Join Date
    Jul 1999
    Location
    J-ville, NC
    Posts
    54

    Testing

    Testing
    David Underwood
    Cannabatech Corporation

    ICQ - 14028049
    E-mail - [email protected]

    AIM - DK4ever23[/b]


  8. #8
    Addicted Member LAURENS's Avatar
    Join Date
    Jan 2000
    Location
    Utrecht, the Netherlands
    Posts
    138
    Can't you do something with collections and a collection within a collection. I haven't tried this, just a thought.
    Regards,
    Laurens

    Using VB5 Enterprise edition SP3
    VB6 Enterprise edition SP5

  9. #9
    Guest

    Thumbs up Paul ok got what you want....

    We did something similar to generate databases. Will dig it out over the weekend...involves dynamically creating Collections on the fly. Will post the project...

    VB suxs for dynamic array declaration. Easier in other basic dialects and OSs.

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Thumbs up

    Cool McCool!

    I'll be watching this space

    Thanks dood

    Paul

    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Unhappy

    This post made it all the way to page three!

    C'mon Guys! Don't give up on me!

    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Angry

    Moving this back to the top again...

    It seems I've been abandoned!

    Is it that hard????????????

    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  13. #13
    Guest

    Thumbs up No luck Paul

    We did it in Delphi apparently, source code with my ex-employers....Damn thought we had got away with all code that was created by us on site....

    Phantomd is trying to recreate what he did in Delphi with vb, but seems to be spending a lot of time swearing about it.

    Tried to create Collections on the fly over weekend, but vb didn't want to know about it. Will keep hacking for you though as it's an interesting problem.

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    Thanks,

    I've been reading up on the ADO recordset object as it seems to be a similar sort of data structure (although hideously more complex than I need)

    It seems to be a Field() collection per row. but they have Field(0).value, Field(0).name, Field(0).datatype

    It looks like I'll have to try to put something together with arrays of object refs... just sounds like it's going to get awfully slow.
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  15. #15
    Guest

    Thumbs up Ahhhhhh!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    Have done that with DAO to create a database from paramters passed in via Universe, (l know coz l found that while looking for the Collections stuff), if ya want will post that to you...may or may not be any help

  16. #16
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    Paul.

    Your answer is simple in concept but a bit more complex in implementation.

    What you need to do is create a CLASS.

    I would suggest actually making SEVERAL classes :

    Class 1 : "Field"
    Class 2 : "Fields"

    The first class is simple :

    Code:
    Public Enum VarType
      vtString = 0
      vtInteger = 1
      vtDate = 2
      ..
      ..
    End Enum
    
    Public Type as VarType
    Public Name as String
    Public Attributes as String
    Public Value as Variant
    What you now have is an object that has 4 parameters that contain the details of what the particular "field" is about. The "Attributes" parameter might contain a length if the VarType is string or a format number if it is a Date or precision etc, etc...

    The second "Class" would then internally hold a variant collection of type "Field" and have methods to be able to add and delete fields as well as modify them. You would also then provide Property Get/Let/Set to allow access to these fields and their types.

    The final product would be an object that you could set and interrogate at will.

    Code:
    Dim ftFields as New Fields
    
    ftFields.Add "Name", vtString, "100", ""
    ftFields.Add "StartDate", vtDate, "dd/mm/yyyy", now()
    
    ...
    
    MsgBox ftFields("Name").Value
    Now if you want to translate this to a variable definition to a database there is no reason why you cannot create a table with fields similar to the variables given in the "Fields" class and then automatically generate Create Table statements (providing you are using something like SQL Server of course).

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Thumbs up

    Thanks,

    I need to do some reading on collections, I've rarely used them.
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  18. #18
    Hyperactive Member
    Join Date
    Dec 1999
    Posts
    321

    Thumbs up

    Kewl... all the code in these forums is worth money
    Signed, Rodik ([email protected])
    Programmer,usesVB6ED
    ===========================
    Copyright©RodikCo,2002.

    Dont mind this signature ;] Its old

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width