|
-
Jun 20th, 2000, 12:00 PM
#1
Thread Starter
Fanatic Member
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!)
-
Jun 21st, 2000, 08:19 AM
#2
Fanatic Member
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
-
Jun 21st, 2000, 08:58 AM
#3
-
Jun 21st, 2000, 11:37 AM
#4
Thread Starter
Fanatic Member
?????????
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!)
-
Jun 21st, 2000, 02:11 PM
#5
Hyperactive Member
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)
-
Jun 21st, 2000, 02:31 PM
#6
Thread Starter
Fanatic Member
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!)
-
Jun 21st, 2000, 02:45 PM
#7
Member
-
Jun 21st, 2000, 05:47 PM
#8
Addicted Member
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
-
Jun 22nd, 2000, 07:08 AM
#9
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.
-
Jun 22nd, 2000, 07:25 AM
#10
Thread Starter
Fanatic Member
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!)
-
Jun 22nd, 2000, 11:49 PM
#11
Thread Starter
Fanatic Member
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!)
-
Jun 23rd, 2000, 10:51 PM
#12
Thread Starter
Fanatic Member
-
Jun 25th, 2000, 11:26 AM
#13
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.
-
Jun 25th, 2000, 11:40 AM
#14
Thread Starter
Fanatic Member
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!)
-
Jun 25th, 2000, 11:49 AM
#15
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
-
Jun 25th, 2000, 12:51 PM
#16
Hyperactive Member
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).
-
Jun 25th, 2000, 01:05 PM
#17
Thread Starter
Fanatic Member
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!)
-
Jun 25th, 2000, 01:07 PM
#18
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|