Question for Mike Williams... please need help

Question for Mike Williams... please need help

Post by Co » Mon, 09 Oct 2006 03:10:26


Hi Mike,

According to J French I should ask you for help, so...

http://www.yqcomputer.com/




Ask Mike Williams

- you have talent, but I am rather intolerant
- you need to be taught old style coding
 
 
 

Question for Mike Williams... please need help

Post by Mike Willi » Mon, 09 Oct 2006 06:51:12


Looking at your posts it appears that your problem is more to do with
database structures than with graphics, and I'm afraid that databases are
not one of the things I know much about.

Mike

 
 
 

Question for Mike Williams... please need help

Post by Co » Mon, 09 Oct 2006 18:07:57

Well, yes and no.
I do have to save some record data but I also need to export pictures
and lines.
So that includes their starting point and end point.

Is there a way to do this with PropertBag or in a plain ini file?

Marco

Mike Williams schreef:
 
 
 

Question for Mike Williams... please need help

Post by erewho » Mon, 09 Oct 2006 18:34:49

On Sat, 7 Oct 2006 22:51:12 +0100, "Mike Williams"







I got nervous when Marco started talking about Record Sets
- I'm pretty sure that you know a lot about 'roll your own' data
access, and reckoned that you would be able to explain his graphics
parameter storage from the graphical angle.

As far as I can see his graphical objects (Ropes and Boxes) have
clearly defined parameters that could be slapped into a UDT or a form
of INI file record.

Since I am a bit weak on the graphical side, I reckoned that you would
be better at explaining the concept - and steering him away from
standard databases.
 
 
 

Question for Mike Williams... please need help

Post by Mike Willi » Tue, 10 Oct 2006 02:14:45

Co" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...


I presume that you are looking for a way to store a set of data (lines,
rectangles, pictures, etc) in which each element has a specified size and
position within a composite complete image? Is that what you're doing? It's
difficult to know without a detailed description of what it is you are
actually doing. Is it perhaps something like a drawing that you might create
in a drawing program such as Corel Draw for example? If that is the case
then I would advise you to take up Mike Sutton's suggestion of drawing all
of the elements into a enhanced metafile, so that the complete metafile can
be saved as a file and then later loaded and "played" into any suitable DC
(Form, printer or whatever) at any desired size. If that is what you want
then I think Mike Sutton has already posted some links for you that describe
how to create such metafiles in VB.

Otherwise, if a metafile is not suitable for your specific purposes, then J
French's suggestion of using an array of standard UDTs would be fine for
storing the start and end points of lines (x1, y1, x2, y2 all Singles). The
pictures would also need x1, y1 coordinates for their position and also w1,
h1 values if they are to be printed or displayed at something other than
their default size. What format are your images in by the way? And are they
all the same file size (for example a number of different bitmaps each with
the same colour depth and pixel area)? If so, and if they are fairly small
and few in number, you can store each image as a fixed size Byte array in a
UDT that contains all the required data. For example:

Private Type picData
x1 As Single
y1 As Single
wide As Single
high As Single
b(1 To 1000) As Byte ' image data or image file data
End Type
Private myPics(1 To 50) As picData ' to store 50 pics

If each image has a line associated with it then you can store the line
parameters in the same UDT (adding four more variables to the declaration).
Otherwise, if the number of lines is different to the number of images then
you can store the lines in a separate array of UDTs. These UDTs can then be
saved to a file using the VB Put statement and later read from the file
using the VB Get statement. If the pictures have different data sizes then
you could save each image data block, one after the other, in a file using
Put to place them into the file one after the other (making a note of the
position and data size of each one as you do so). Then at the end of the
file you can add a set of "pairs of Longs" (one for each image data block)
specifying the start position and length of each image data block, finally
appending another Long that specifies how many images there are in the file.
To read the file back you would first read the last four bytes of the file
into a Long (which will tell you how many images there are) and you can then
read the appropriate number of "pairs of Longs" from the tail end of the
file, each time loading the appropriate block of image data into memory.
This is all very easy to do using the VB Get statement.

Does any of this sound useful to you, or have I perhaps misunderstood what
you are doing? A "real world" explanation would be nice (the story of what
you are doing explained in terms of how the "user" would see it, rather than
as how the programmer would see it). Sometimes it helps t
 
 
 

Question for Mike Williams... please need help

Post by Larry Serf » Tue, 10 Oct 2006 04:23:49


"Co" < XXXX@XXXXX.COM > wrote

For an alternative method, you could build an ad hoc combination
file that has picture data as well as numerical data, but it would have
to be organized so that you can learn from the file exactly what was
saved.

For the picture data, you could copy all the images to one picture box
so that you only have deal with loading one image. You might do that
by creating a grid of images, or just a horizontal row or vertical column
of all the images. In any case once done, you have one picture that has
all the images. When you load the image back in, you must reverse
the process to break that one large picture back into its smaller parts.

Then, the data has to be added such that you know right off how many
boxes, and how many ropes will be needed. As you might guess those
numbers come from the Count property of their respective collections.

For illustrative purposes, assume you have 3 boxes, and 3 ropes. In
that case the numerical data could be laid out like the data column
below (the Description is added to let you know where the data came
from, not to be included in the file):

Data Description
3 # of boxes
3 # of ropes
0 Box #1 Image Left
0 Box #1 Image Top
60 Box #1 Image Width
60 Box #1 Image Height
120 Box #1 Display Left
100 Box #1 Display Top
60 Box #2 Image Left
0 Box #2 Image Top
60 Box #2 Image Width
60 Box #2 Image Height
220 Box #2 Display Left
100 Box #2 Display Top
180 Box #3 Image Left
0 Box #3 Image Top
60 Box #3 Image Width
60 Box #3 Image Height
170 Box #3 Display Left
200 Box #3 Display Top
150 Rope #1 X1
130 Rope #1 Y1
250 Rope #1 X2
130 Rope #1 Y2
150 Rope #2 X1
130 Rope #2 Y1
200 Rope #2 X2
230 Rope #2 Y2
200 Rope #3 X1
230 Rope #3 Y1
250 Rope #3 X2
130 Rope #3 Y2

The Image (Left, Top, Width, Height) indicates where in the
the single picture the image for that box is, and its size. The
Display values indicate where on the form that box will go.
The ropes have just two end points so less data is needed to
indicate where they belong.

As you can see, once you get the number of boxes, and number
of ropes the remaining data is in a consistant format, which would
suggest using a User Defined Type (UDT) to get the data from the
file.

For an example of combining picture data with other data, have
a look at these:

http://www.yqcomputer.com/
http://www.yqcomputer.com/

LFS
 
 
 

Question for Mike Williams... please need help

Post by Co » Tue, 10 Oct 2006 07:20:37

ike,

It does make sense for me.
I was just wondering if I could save a UDT to a file using The Property
Bag.

What I'm doing is:
I use default pictures (eight to be precise) Person, Event, Town,
Vehicle etc...
I have one initial picture and data (from a recordset). This is drawn
in the middle of the form.
All the other pictures are drawn in a circle around it.
All the other pictures also contain data (from a recordset).
The middle picture is connected through a line with all the pictures in
the circle.
On the lines connecting the pictures there is a label (telling the user
what the connection is,
for example between to Persons "Family").

When loading a saved file into the viewer I would need:
1. the initial picture (just its number cause the program will know
which picture to choose).
2. the data related to the initial picture (two strings max.)
3. for all the other pictures I would need the number and the data
(again two strings max.)
4. For the lines I would need to have to connect the right boxes and
add the right data.

For example this is how I load the pictures (Box) and the lines (Rope)
on my form:

For LoopPts = 1 To MyDataCount
With CircPts(LoopPts) ' were I determine the amount of pictures
Font.Size = 24
Boxes.Add NewBox(imBox.ListImages(MyData(LoopPts).pIcon).Picture,
.X, .Y, MyData(LoopPts).sLabel, MyData(LoopPts).sID,
MyData(LoopPts).sLabel2)

Font.Size = 8
If MyData(LoopPts).pIcon = 1 Then
Ropes.Add NewRope(Boxes(1), Boxes(LoopPts + 1),
MyData(LoopPts).sLink, IIf(MyData(LoopPts).sGrade <> " Confirmed ",
vbDot, vbSolid))
ElseIf MyData(LoopPts).pIcon = 2 Then 'Orgs
Ropes.Add NewRope(Boxes(1), Boxes(LoopPts + 1),
MyData(LoopPts).sLink, IIf(MyData(LoopPts).sGrade <> " Confirmed ",
vbDot, vbSolid))
ElseIf MyData(LoopPts).pIcon = 3 Then 'Events
Ropes.Add NewRope(Boxes(1), Boxes(LoopPts + 1),
MyData(LoopPts).sLink, IIf(MyData(LoopPts).sGrade <> " Confirmed ",
vbDot, vbSolid))
ElseIf MyData(LoopPts).pIcon = 6 Then 'Units
Ropes.Add NewRope(Boxes(1), Boxes(LoopPts + 1),
MyData(LoopPts).sLink, IIf(MyData(LoopPts).sGrade <> " Confirmed ",
vbDot, vbSolid))
ElseIf MyData(LoopPts).pIcon = 7 Then 'Vehicles
Ropes.Add NewRope(Boxes(1), Boxes(LoopPts + 1),
MyData(LoopPts).sLink, IIf(MyData(LoopPts).sGrade <> " Confirmed ",
vbDot, vbSolid))
End If
End With
Next LoopPts

I'm not sure how this could be done best.

Marco

Mike Williams schreef:


 
 
 

Question for Mike Williams... please need help

Post by Mike Willi » Tue, 10 Oct 2006 16:37:15


I've no idea what a Property Bag is (some sort of Class methinks). I never
use 'em. But your data is very simple (just some integers and some strings
and a number specifying how many data items there are). It should be easy to
place the data in a UDT and save that UDT directly to a file using Open for
Binary and the VB Put statement. The file can then be read at some later
date using Open for Binary and the VB Get method. By the way, when Putting
data into a file in order to create a new file containing only that data you
need to "clear" the file first, otherwise it will still have its original
length. Open for Output followed by Close will do that for you.

Otherwise, if these files you're saving are only going to be viewed by
someone (rather than edited in some way) you can draw your pictures and
boxes and lines into a metafile instead of directly to the display (or as
well as) and then save the metafile. This would of copurse make the file
larger (because it would contain the actual pictures instead of just
pointers to them) but anyone will be able to view and / or print the
resultant file in anything that can open metafiles (most drawing
applications and word processors and publishers and lots of other things).

Perhaps someone who knows about Property Bags can come up with a better
answer for you.

Mike
 
 
 

Question for Mike Williams... please need help

Post by Co » Tue, 10 Oct 2006 17:09:43

Mike,

your answer sounds great.
The data that I save is only to be viewed by someone with a Viewer I
will program.
So this metafile sounds good enough for me.
Could you please post a small example how to do this getting me on
track.

Many thanks,

Marco

Mike Williams schreef:
 
 
 

Question for Mike Williams... please need help

Post by Mike Willi » Wed, 11 Oct 2006 01:25:29


You seem to have misinterpreted what I said. A metafile is graphic file that
can be viewed and or printed by anyone using any application that is capable
of dealing with such graphic files (drawing programs, desktop publishers,
word processors, all sorts of applications). If your data is only to be
viewed by someone with a viewer that you will program yourself in VB then
you should choose the othe option I mentioned (UDTs and the VB Put and Get
methods of saving and reading data to standard files) or some other similar
method.

Mike
 
 
 

Question for Mike Williams... please need help

Post by Co » Wed, 11 Oct 2006 01:54:55

Mike,

You see I'm just an amateur.
Trying to make something out of life.
This UDT can be saved to a file?

I think then I would need something like:

Private Type LINKDATA
pIcon As Long
sLabel As String
sLabel2 As String
sID As String
sLink As String
sGrade As String
End Type

Dim MyData() As LINKDATA

MyData(MyDataCount).pIcon = lIcon
If sEntity = "Biographies" Then
MyData(MyDataCount).sLabel = UCase(rs2.Fields("family_name")) &
", " & rs2.Fields("first_name")
MyData(MyDataCount).sLabel2 = ""
MyData(MyDataCount).szTip = rs2.Fields("family_name") & Chr$(0)
MyData(MyDataCount).sID = "B" & rs2.Fields("BID")
MyData(MyDataCount).sLink = IIf(rs2.Fields("LinkType") <> 0, " "
& rs2.Fields("LinkType") & " ", "")
MyData(MyDataCount).sGrade = IIf(rs2.Fields("Grade") <> 0, " " &
rs2.Fields("Grade") & " ", "")
Endif

But there my knowledge ends.
How to write this to a file, and what extension should the file get?
And finally how to retrieve it once more in the reader?

Marco

Mike Williams schreef:
 
 
 

Question for Mike Williams... please need help

Post by Mike Willi » Wed, 11 Oct 2006 05:58:43

Co" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...


Actually you're pretty much "on the ball" with the code you posted.


Writing the file is very easy. The file extension can be anything you want
(or no extension at all if you wish). It is of course best to avoid
extensions that are in common use.

Basically you create a dynamic array of UDTs (initially containing a hundred
or so elements) and you keep filling each element with data, "topping up"
the number of elements by a further hundred or so each time you see that you
are running out of available elements. Finally you get rid of any unused
elements. Then you save to a file a Long value specifying how many elements
are in the array and immediately following that long value you save the
actual data. the entire array of UDTs can be saved with a single VB Put
statement.

When you want to read back the file you simply open it and read the first
Long value. That Long value allows you to create a array of similar UDTs
with exactly the required number of elements, which you can read with a
single VB Get statement.

The only complication is that when you save to a file using Put and if the
file already exists then it will remain at its original file length unless
the data you are "Putting" exceeds that amount. This can result in files
that are too long if the data you are "Putting" contains fewer bytes than
the original file contents. You can easily solve this problem though in
various ways. One very simple way is to Open the file for Output and
immediately Close it. This will produce a zero length file, which you can
then Open for Binary and Put your stuff into it.

As is always the case with these things, a little example is worth a
thousand words. Paste the following code into a new VB project (one Form
containing two Command Buttons and one Text Box). Run the code and type a
number into the Text Box. Then pressing Command1 button will save exactly
that number of UDT elements to a file. Pressing Command2 button will then
load that file into another similar UDT. One data item of the final element
is printed out in both cases, so that you can see they are the same (in
other words, the data loaded is exactly the same as the data you saved).
This specific example is a little contrived and it merely populates some of
the data items with random values, but I'm sure you will be able to modify
it to suit your own specific requirements.

Mike

Option Explicit

Private Type LINKDATA
pIcon As Long
sLabel As String
sLabel2 As String
szTip As String
sID As String
sLink As String
sGrade As String
End Type

Private Sub Command1_Click()
Dim MyData() As LINKDATA
Dim nCount As Long, n As Long, fNum As Long
ReDim MyData(1 To 100) ' initially reserve 100 elements
Do
nCount = nCount + 1
'
If nCount > UBound(MyData) Then
' add a further 100 elements if needed
ReDim Preserve MyData(1 To UBound(MyData) + 100)
End If
'
MyData(nCount).pIcon = Rnd * (12)
MyData(nCount).sLabel = "Some Text " & CStr(Rnd * 123456)
MyData(nCount).sLabel2 = "More text " & CStr(Rnd * 123456)
MyData(nCount).szTip = "Another " & CStr(Rnd * 123456)
' etc, etc
Loop Until nCount >= Val(Text1.Text)
ReDim Preserve MyData(1 To nCount) ' remove unused elements
' save the file
fNum = FreeFile 'get next free file number
Open "c:\myfile.abc" For Output As f
 
 
 

Question for Mike Williams... please need help

Post by Co » Thu, 12 Oct 2006 14:09:11

hanks for that Mike,

I finally got it to work. Now I have to write the Viewer.

Marco

Mike Williams schreef: