From: Jim Mack on
Webbiz wrote:
>
> I think maybe this one is better?

I didn't study it, but it's the right idea.

If you're adding and removing on a regular basis, I wouldn't bother
with the ReDim on delete, just decrement the count after swapping. I'd
use m_SymbolCount as the current max when searching, and check it
against UBound when adding. I'd also ReDim upward by 10 elements
rather than one at a time if I needed to add an element.

--
Jim Mack
Twisted tees at http://www.cafepress.com/2050inc
"We sew confusion"






>
>
> Public Sub Delete(ByRef ChartName As String)
>
> Dim i As Long, j As Long
> Dim bResize As Boolean
>
>
> If m_SymbolsCount > 0 Then
>
> If m_Symbols(m_SymbolsCount).ChartName = ChartName Then
> 'delete last record by resizing only
> If m_SymbolsCount = 1 Then
> Erase m_Symbols
> mSymbolsCount = 0
> Exit Sub
> End If
> Else
> For j = 1 To m_SymbolsCount
> If m_Symbols(j).ChartName = ChartName Then 'match
> m_Symbols(j) = m_Symbols(m_SymbolsCount)
> 'Transfer last record over one to remove
> ReDim Preserve m_Symbols(m_SymbolsCount - 1)
> mSymbolsCount = mSymbolsCount - 1
> Exit Sub
> End If
> Next j
> End If
>
> End If
>
> End Sub
>
>
> Webbiz

From: David on
Webbiz:

Didn't read all the posts so hope I'm not off base here.

I believe your design may run into a few problems.
Each data vendor has a separate symbol that is unique to them.
That may be different than the one the user may name it.

Using a class is OK, but I think you need to make some provisions, a table
works well, to cross reference the vendor symbol to the users designated
symbol.


David


"Nobody" <nobody(a)nobody.com> wrote in message
news:eiqp2UvvKHA.1692(a)TK2MSFTNGP04.phx.gbl...
> "Webbiz" <nospam(a)noway.com> wrote in message
> news:gkbap59vi85c1gpmfcb21lmsj4tv5unnrh(a)4ax.com...
>> Thanks for taking the time to write this code example NOBODY. Much
>> appreciated.
>>
>> I like the idea of using ADD and REMOVE methods as part of a class.
>> Seems to be a 'clean' solution that is also portable if I have to do
>> this again in another project.
>>
>> When it comes to Classes, I'm still a bit slow in catching on. I'm
>> going to babble on here on what this is doing. If I'm off base, please
>> let me know.
>>
>> The Form_Load() is where the object will be instantiated and data
>> loaded into it. I can put this anywhere I want in the app, but for my
>> purposes, the Form_Load() would fit just fine in triggering the
>> 'SYMBOL OBJ INITIALISING' procedure. Within this procedure, I would
>> have to load the data from a datafile to restore all the previously
>> entered data.
>>
>> Q: Might be a dumb question, but is it possible to save a class object
>> with its data to a file in one easy dump and load it as such to
>> restore it, or do I have to loop through all the records within the
>> class object when saving to and loading from disk?
>
> I haven't used this, so I don't know the details, but check the help for
> "PropertyBag object". You will find a topic called "Persisting a
> Component's Data". It probably doesn't apply to Standard EXE projects.
> Other than that, you can provide your own Load/Save functions that take a
> file name and save the information there. You can call these functions
> from Initialize/Terminate events, but these events don't return error
> codes, so it's best to call Load/Save methods explicitly. You can show a
> MsgBox, but I tend to avoid GUI code in classes and return an error code,
> and let the calling form show a MsgBox. This is just in case I use that
> class in a non-GUI app later, such as a command line only tool, or ActiveX
> in a web server, or as a service, which cannot show a GUI.
>
>> Q. Would it be wise/unwise to have the data load (from file) as part
>> of the Class, perhaps as the Class Constructor triggered when an
>> object is created from it? And then, to have all the data saved back
>> to the file as part of the Class Destructor (Terminate?) ?
>
> That's fine. See the above.
>
>> Q. I find it interesting this technique of deliberately causing an
>> error in order to branch to a different routine, such as the initial
>> Redim of m_Symbols. Is this common practice?
>
> That's very common and perfectly fine, especially when ReDim'ing arrays
> for the first time.
>
>


From: Webbiz on
On Mon, 8 Mar 2010 21:43:23 -0500, "David" <NoWhere(a)earthlink.net>
wrote:

>Webbiz:
>
>Didn't read all the posts so hope I'm not off base here.
>
>I believe your design may run into a few problems.
>Each data vendor has a separate symbol that is unique to them.
>That may be different than the one the user may name it.
>
>Using a class is OK, but I think you need to make some provisions, a table
>works well, to cross reference the vendor symbol to the users designated
>symbol.
>
>
>David
>
>
>"Nobody" <nobody(a)nobody.com> wrote in message
>news:eiqp2UvvKHA.1692(a)TK2MSFTNGP04.phx.gbl...
>> "Webbiz" <nospam(a)noway.com> wrote in message
>> news:gkbap59vi85c1gpmfcb21lmsj4tv5unnrh(a)4ax.com...
>>> Thanks for taking the time to write this code example NOBODY. Much
>>> appreciated.
>>>
>>> I like the idea of using ADD and REMOVE methods as part of a class.
>>> Seems to be a 'clean' solution that is also portable if I have to do
>>> this again in another project.
>>>
>>> When it comes to Classes, I'm still a bit slow in catching on. I'm
>>> going to babble on here on what this is doing. If I'm off base, please
>>> let me know.
>>>
>>> The Form_Load() is where the object will be instantiated and data
>>> loaded into it. I can put this anywhere I want in the app, but for my
>>> purposes, the Form_Load() would fit just fine in triggering the
>>> 'SYMBOL OBJ INITIALISING' procedure. Within this procedure, I would
>>> have to load the data from a datafile to restore all the previously
>>> entered data.
>>>
>>> Q: Might be a dumb question, but is it possible to save a class object
>>> with its data to a file in one easy dump and load it as such to
>>> restore it, or do I have to loop through all the records within the
>>> class object when saving to and loading from disk?
>>
>> I haven't used this, so I don't know the details, but check the help for
>> "PropertyBag object". You will find a topic called "Persisting a
>> Component's Data". It probably doesn't apply to Standard EXE projects.
>> Other than that, you can provide your own Load/Save functions that take a
>> file name and save the information there. You can call these functions
>> from Initialize/Terminate events, but these events don't return error
>> codes, so it's best to call Load/Save methods explicitly. You can show a
>> MsgBox, but I tend to avoid GUI code in classes and return an error code,
>> and let the calling form show a MsgBox. This is just in case I use that
>> class in a non-GUI app later, such as a command line only tool, or ActiveX
>> in a web server, or as a service, which cannot show a GUI.
>>
>>> Q. Would it be wise/unwise to have the data load (from file) as part
>>> of the Class, perhaps as the Class Constructor triggered when an
>>> object is created from it? And then, to have all the data saved back
>>> to the file as part of the Class Destructor (Terminate?) ?
>>
>> That's fine. See the above.
>>
>>> Q. I find it interesting this technique of deliberately causing an
>>> error in order to branch to a different routine, such as the initial
>>> Redim of m_Symbols. Is this common practice?
>>
>> That's very common and perfectly fine, especially when ReDim'ing arrays
>> for the first time.
>>
>>
>


Hello David.

The symbols they use are the ones that I use and supply. It is my file
that they will download and the app will load. So to use the feature,
they must match up the symbols available in my download file to their
charts.

Thanks.

Webbiz
From: Larry Serflaten on

"Webbiz" <nospam(a)noway.com> wrote

> The user of the program can name his charts whatever he wants. But in
> order to retrieve information specific to the data loaded into the
> chart, the symbol needs to be associated with it.

<snipped for brievity>

> That's it in a rather large nutshell. Can collections deal with this?

A Collection would only help for the look-up side of the problem, it
would not be suitable for saving to the disk.

Keep in mind you can design the process in any number of ways,
so why not pick a method that will be easy for you to both; store
to disk, and work with, in the program?

You indicated that a user might assign different charts (with
different names) to the same base symbol. Thats a design requirement;
the user is allowed to use multiple names that all reference the
same base symbol. How many is 'multiple'? Ideally, you would
want no limitation (within reason) on the number of different charts
so it needs to be somewhat open ended in terms of relating the names
to their symbol.

Also, you want to avoid trouble from charts that have similar names,

"S" = "Chart 1"
"CL" = "Chart 2"
"CT" = "Chart"

When you go looking for "Chart" in a bunch of strings, you want to
be sure to find the one related to CT and not either of the other two.
That means you need to make each name unique, or as Jim has shown,
store them with delimiters.

It may help to first look at how you want to lay out the data in the file,
to make that easy for the program to read and store. Then with that
file format, look for methods that would be suitable for translating
the long names to their base symbols.

One obvious (to some, anyway) solution would be to put each symbol
on one line in the file, followed by the different user names for that symbol:

CT|May Corn 2010|Corn May 2010|
S|Soybean|
GT|
CL|April Lettuce 2010|Spring Lettuce|
.... etc ...

A file like that could be read into string memory in one go, and Split
into an array for use in the program.

When you need to find the symbol for a name, you loop through the
array testing each line (InStr) until a match is found. When you have a
match, you know the first few characters of that line is the desired symbol.

Something like that could be implemented in a BAS module, or in a class,
if that is how you want to go....

LFS




From: Webbiz on
On Tue, 9 Mar 2010 07:44:48 -0600, "Larry Serflaten"
<serflaten(a)usinternet.com> wrote:

>
>"Webbiz" <nospam(a)noway.com> wrote
>
>> The user of the program can name his charts whatever he wants. But in
>> order to retrieve information specific to the data loaded into the
>> chart, the symbol needs to be associated with it.
>
><snipped for brievity>
>

>You indicated that a user might assign different charts (with
>different names) to the same base symbol. Thats a design requirement;
>the user is allowed to use multiple names that all reference the
>same base symbol. How many is 'multiple'? Ideally, you would
>want no limitation (within reason) on the number of different charts
>so it needs to be somewhat open ended in terms of relating the names
>to their symbol.
>
>Also, you want to avoid trouble from charts that have similar names,
>
>"S" = "Chart 1"
>"CL" = "Chart 2"
>"CT" = "Chart"
>

Fortunately the user cannot name two charts the same. So 'similar'
names would not be an issue since the comparison must be EXACT, not
simply contain some similarity.

"Chart" and "Chart 1" and "Chart 1" are all different names as far as
the app is concerned. It's a complete string comparision that must
match, not a partial only.

However, I have made some minor changes. The user can only assign a
symbol to a chart when that chart happens to be loaded and in view
mode. At that point, the chart's unique 'filename' is found in a
global chart name variable. An example would be "S098376.prv". Each
chart has a unique file name that holds all the unique values for that
chart, including the path and filename of the actual data file it
loads. So when the user has a chart loaded and wants to use the tool
that requires a symbol, the app will ask for the symbol and then
assign it to the name of the .prv file associated with that chart.
Even 5 charts of Soybeans will all have their own unique .prv file, as
each chart will likely have diffent things drawn on it, etc.

The app will now only ask for a symbol if one has never been assigned
to it.

This appears to be working out so far. More testing ahead! :-)

Thanks.

Webbiz
First  |  Prev  | 
Pages: 1 2 3 4 5
Prev: Datagrid problem
Next: Virtual memory increasing.