Re: NEWBY Struggling with Conditional Text Merge Problem
and quick responce to spoo... the Name() / Names() is a good point. What I do when I have Types that have common properties like Name, Date, Index, Count, Type, i'll even prefix those names..
Public Type PersonType
PersName() As EventType
PersBirth() As EventType
PersDeath() As EventType
as for the Get #FileNumber, 1, Data ' << run-time error '458' error, I think it doesnt like 'Data' variable name. 'Data' seems recognized by VB compliler.... although I still have no idea what it is (type? function?)
Re: NEWBY Struggling with Conditional Text Merge Problem
Golgo
I also tried Dataz .. same error
in a BAS module (this line added to what was shown in post #39)
Code:
Private Dataz As DataType
in the form
Code:
Private Sub LoadData(pstrFile As String)
Dim FileNumber As Long
FileNumber = FreeFile()
Open pstrFile For Binary As #FileNumber
Get #FileNumber, 1, Dataz ' << run-time error '458'
' Variable uses an Automation type not supported by Visual Basic
Close
End Sub
Any other ideas ? .. ;)
Spoo
Re: NEWBY Struggling with Conditional Text Merge Problem
ah, the declaration helps :)
[cannot test this for sure at the moment but...]
I believe the Dataz needs to be Byte
then you can put the Byte into your DataType..
just can't combine the steps as GET #,, doesn't support the DataType
The Automation error is becuase you used a UDT, had you used a more basic data type, you probably would have gotten the more common 'type mis-match' error
Re: NEWBY Struggling with Conditional Text Merge Problem
Golgo
Makes sense, but as a total newbie to UDTs, I'm just
"aping" what Ellis proposed.
Thanks for jumping in with suggestions, but, natch,
the real culprit is Ellis .. :rolleyes:
Spoo
Re: NEWBY Struggling with Conditional Text Merge Problem
I do like the way he broke down the user types. very object oriented.
once you get the hang of UDTs they're pretty handy. Just need to keep in mid the extra considerations if attempting to pass them across objects, force them into other UDTs, or store them in collections/arrays
Re: NEWBY Struggling with Conditional Text Merge Problem
I'm surprised that the compiler objects to "Name," but it looks like it does. Learned my something new for the day.
"Data" is a perfectly valid name; I've used it countless times.
The error you're getting looks like the error you get when there is an enumeration anywhere in the udt structure. Enumerations cannot be "Get"ed or "Put"ed. The workaround I use for that is to use enumerations as if they're allowed and comment out the "Get"/"Put" lines until I'm ready to compile to exe. Just before the full compilation I uncomment the Get/Put and change the "As Enum" declarion to "As Long." This lets me get the benefit of intellisense while writing code.
On closer inspection, your error isn't about enumerations, but instead is a simple scoping problem. I didn't get into that too much with the primer, but you want to be careful about scoping your data. Generally speaking, I encapsulate the entire "data" structure inside a single module. This is particularly effective in class modules where you aren't given a choice in the matter. It also lets you treat the udt fields as actual properties exposed by the class.
Anyway, you declared all the sub-parts of the udt structure as public, but then the type definition for "data" is marked as Private. That's why you can't access the "data" type in other modules. (Or form, as in your example.)
Even short of complete encapsulation -- which I recommend -- you should at very least be keeping the save and load code in the same module that has the udt definitions. Putting the save/load routines in a form is very odd.
Note that I'm not talking about the data (or dataz) variables themselves, though those are also a problem because you scoped them Private too. I'm mainly talking about the type definition itself.
Re: NEWBY Struggling with Conditional Text Merge Problem
Ellis
OK.. I made some alterations. I now get Run-time error '7': Out of memory.
on the form
Code:
Dim fn44 As String
fn44 = "D:\VBForum Stuff\Txt Files\lando geneo.txt"
LoadData fn44
in bas module
Code:
Public Data As DataType
'------------------------------------------------
Public Sub LoadData(pstrFile As String)
Dim FileNumber As Long
FileNumber = FreeFile()
Open pstrFile For Binary As #FileNumber
Get #FileNumber, 1, Data ' << Run-time error '7': Out of memory
Close
End Sub
the file
Code:
0 @I1@ INDI
1 BIRT
2 DATE 1868
2 PLAC New York, America
1 BIRT
2 DATE Mar 1868
1 BIRT
2 DATE 18 Mar 1868
2 PLAC America
1 BIRT
2 DATE abt 1868
2 PLAC Sullivan County, NY, United States
0 @I2@ INDI
Clearly, the file is microscopic, so there is no memory issue.
Any suggestions?
Spoo
Re: NEWBY Struggling with Conditional Text Merge Problem
That looks like a text file to me. You can't load a text file directly to a udt structure, you can only load an exact match of the structure. The only way to make one of those is to use the Save code to create the file from the udt structure.
You're getting out of memory because VB6 is trying to plop the contents of the text file directly onto the udt structure. Consider this: the udt structure has dynamic arrays, and I see no SAFEARRAY structures in that text file.
In the interest of conveying the underlying concept, the file you save and load a udt structure to/from is a binary file that you can't read or modify with any other program. Well, I guess you could use a hex editor, but I would strongly recommend against it.
The raw text file needs to be imported to the structure before any processing can take place. The ease of saving/loading is a side benefit not directly applicable to reading the gen files.