how can create user control to store big file?
hi, i want create a user control(activex control) with these properties :
file1,file2,file3 or like these.
and then can choose any file(any format and big size like more than 20mb or 50 or 100mb) for file1 and file2 and file3 and then save embed that files selected.
any way? any class any modoule?
Re: how can create user control to store big file?
Usercontrols can save binary data in its propertybag using byte arrays. Even though that is possible, I'd consider compressing the data first before caching it in the propertybag, then expanding the data when the propertybag is read. Any project that uses your control, storing 100+ mb of information will obviously be much larger when that project is compiled.
Re: how can create user control to store big file?
i know that means.i always see user controls example to store [pictures] like aic control and gdi image class used but i want store other formats,can u send a sample code for other format like mp3 exe or other format? my problem is about how work with array in property bag.
just a simple sample for save and load.
and my second question is about limit of store?(how can store more than 100 mb for example 200 300 or 500 mb in property bag?)
Re: how can create user control to store big file?
Can you first explain why you want to store these huge amounts of data in a user control?
Maybe we can come up with better alternatives.
Re: how can create user control to store big file?
Quote:
Originally Posted by
Black_Storm
i know that means.i always see user controls example to store [pictures] like aic control and gdi image class used but i want store other formats,can u send a sample code for other format like mp3 exe or other format? m
Pictures are relatively small in size regarding bytes. Even the AIC will prefer to store images as PNG vs bitmap if the user doesn't override the option to preserve the original image format. PNG is much smaller file size than BMP. Likewise, you should seriously consider compressing any large file for storage and then expand when reading.
To save to the property bag, you need to understand how the property bag works.
1. It is read just one time and only one time. When you read the data from the bag, you need to either cache it or save it to file for future use.
2. It is written just one time and only one time. When your user chooses the UC option to select the file, you need to cache its bytes or 'remember' the file name so you can extract the bytes when the UC writes its property bag.
3. The very first time a UC is created, the UserControl_InitProperties event is called. After that very first time, UserControl_ReadProperties is always called and UserControl_InitProperties never called again. UserControl_WriteProperties is always called any time the properties are changed and/or user saves project.
The property bag is typically read each time the UC is added to its parent or in VB when the project is saved. The property bag is written when the project closes and the UC was loaded or when the project is saved. The bag is also read/written during runtime if a UC is created dynamically from another UC, i.e., ReDim Preserve myUC(x): Load myUC(x)
To save binary data in a UC:
Code:
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Dim bData() As Byte
' if you cached data into a byte array, then: bData() = yourByteArray()
' else: get the data into bData() array. If this means reading a file into the array, then so be it.
PropBag.WriteProperty "BinaryStuff", bData()
End Sub
To read binary data in a UC:
Code:
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Dim bData() As Byte
bData() = PropBag.ReadProperty("BinaryStuff", bData())
' either cache this array or write to file and retrieve it later to write to the property bag, as needed
End Sub
Re: how can create user control to store big file?
Previous reply standing and a general outline to follow... If your usercontrol is not storing data that the coder is browsing to and selecting, then you should not be storing that data in a property bag. Rather, store in a resource file of the usercontrol. Then, each time you need to access the data, you simply call LoadResData() to get the data.
It isn't really clear how you are using this data and whether or not it is something a coder selects or if the UC needs for its own use.
Re: how can create user control to store big file?
UserControls are not data structures.
These aren't the droids you're looking for.
Re: how can create user control to store big file?
I've read through things and I'm quite unclear on what's actually going on here. However, if we're just trying to "carry around" some data with our project's files, there are two approaches that I'd consider:
1) If it's ASCII/ANSI data, I'd consider placing it into a Class (CLS) module. In fact, I've got cases where I do precisely that. I started out with ASCII files, but I didn't want to "carry those around", so I stuffed the data into a Class:
Code:
Private Sub GetFileData(CDC() As CDC_Data, CDC_Count As Integer, FileName As String)
Dim i As Integer
Dim sFle As String
Dim iFle As Long
Dim s As String
'
Select Case FileName
Case "LengthForAge"
s = "1,0.0,1.267004226,49.988884080,0.053112191,0.5,0.511237696,52.695975300,0.048692684" & vbCrLf
s = s & "1,0.5,0.511237696,52.695975300,0.048692684,1.5,-0.452244460,56.628428550,0.044116830" & vbCrLf
s = s & "1,1.5,-0.452244460,56.628428550,0.044116830,2.5,-0.990594599,59.608953430,0.041795583" & vbCrLf
s = s & "1,2.5,-0.990594599,59.608953430,0.041795583,3.5,-1.285837689,62.077000270,0.040454126" & vbCrLf
s = s & "1,3.5,-1.285837689,62.077000270,0.040454126,4.5,-1.430312380,64.216864100,0.039633879" & vbCrLf
s = s & "1,4.5,-1.430312380,64.216864100,0.039633879,5.5,-1.476575470,66.125314900,0.039123813" & vbCrLf
s = s & "1,5.5,-1.476575470,66.125314900,0.039123813,6.5,-1.456837849,67.860179900,0.038811994" & vbCrLf
Someday, I should rework that into numbers that are more binary in the origin. But it gets the job done.
2) If it's binary data, I'd consider stuffing it into the project's Resources. It's rather trivial to pull data from resources directly into memory and do with it what you like. If it's image data, there are several procedures in these forums for converting Byte data into images.
Either/both of the above approaches would seem to give you much more control of things, including when things are pulled into memory. When a user-control is thrown onto a form, it is presumably loaded into memory anytime that form is loaded. However, you have complete control over a class module and/or when things are loaded from your resources.
Good Luck,
Elroy
EDIT1: Now there are cases where I store some binary data with my User-Controls. And I use procedures similar to those provided by LaVolpe. However, when I do that, the data is only for the benefit of that User-Control and making it do what I want. I must agree with Dilettante that using a User-Control for a general-purpose-data-storage-container is a bit unusual.
Re: how can create user control to store big file?
i hv a idea and i want create a user control and compile to ocx for personal use and i want store unlimited file counts like mp3 pdf or any documents and then i want read it from my user control or save it in my user control like embeded documents i want play or run it from memory,i dont want save it on hard disk i want just storein my user control and then can read or run it, i don't want use loadresdata and add manual files in designing because i want add dynamic my files to my project and store in user control.can send sample project to do that?
Re: how can create user control to store big file?
I really don't have clue what you are talking about.
Store data in user controls? You want a user control to behave as a virtual storage??
Re: how can create user control to store big file?
Quote:
Originally Posted by
Black_Storm
i hv a idea and i want create a user control and compile to ocx for personal use and i want store unlimited file counts like mp3 pdf or any documents and then i want read it from my user control or save it in my user control like embeded documents
That's not how they work. A usercontrol, compiled or not, has no data other than a resource file if it exists. Whenever a usercontrol is added to a form, whatever properties it has to select files/data, gets stored with the form during design-ti me, not the usercontrol and not during run-time.
Re: how can create user control to store big file?
if i can not use user control for my idea so how can store big files dynamic at run time embed in my project? i dont want create data file for store or bind files in one file,i want just embed my files with big size in my project at run time.
Re: how can create user control to store big file?
for exmple i want just have a exe file so send to friend and then he used it and add files in it and then send me same exe file to me(different is embeded files in it) and i want use that exe file now with stored data in it
Re: how can create user control to store big file?
Why not send files instead of an executable of which you want to update resource section??
Re: how can create user control to store big file?
Sounds like a home-grown self-extracting zip file is what he's making.
-tg
Re: how can create user control to store big file?
I now see what is wanted: A self-modifying executable. I suspect Dilettante will chime in and talk about how that'll be a flag for virus scanners, and he'll be correct.
But just continuing to think about it, I do store several large files within the resources of my primary project. However, I've never attempted to modify these files after the project was compiled, but it may be possible. It sounds like you need to be looking at resource hacker code. You need some code that can directly read/modify/write/expand the resources in an executable. You might start by exploring the UpdateResource API function.
But again, my suggestions have nothing to do with OCX files. In fact, changing the properties (i.e., changing any binary data) in an OCX control isn't going to be permanently stored in the EXE file. Once your program ends, those property settings are going to be thrown out.
As another idea, you might play around with just tacking stuff onto the end of the EXE file. However, that's certainly not guaranteed to work, and it'll almost certainly flag virus scanners. Basically, that's what an EXE's resources are doing, but in a documented/sanctioned way.
Good Luck,
Elroy
EDIT1: I played around with this a bit more, and here's a C++ example of how to modify the resources of an EXE file. At this time, I'm not up for converting that code to VB6, but there's no doubt in my mind that it could be done.