zachattack05 70 Posting Pro in Training

I've got a question about navigating memory streams.

Memory stream properties aside (like making sure the stream can use seek etc...) if someone is storing variable or dynamic data in a stream, how can you retrieve that data? Like, for example if a user could store an image from their hard drive (for example) in a memory stream. and could add to that memory stream a caption to go with the image...how could someone retrieve only the image from the stream if we don't know how big the image is? It could be any number of bytes. I know you can use the Read method and seek to the start of the image data (which a programmer might know depending on how they organize the stream) but how do you know when to stop reading (the count parameter)? Do memory streams contain a "map" of some sort? or is it strictly a STREAM stream, and your SOL if you don't know the locations of the data in the stream?

I ask because I am encrypting (or trying to) a memory stream and then serializing it. But the memory stream contains a class instance as well as some string, integer and object data. The string, integer and object data I have a handle on size, the class instance not so much. I know where the class instance starts, but the size...not so sure of.

zachattack05 70 Posting Pro in Training

Momerath,

Funny...I think I'm going to go jump off the nearest bridge now...I swear I tried the CopyTo method and it didn't work.

I must be losing it. All work and no play...I think I need a vacation.

Thanks Momerath. I'll have to check on that one. I can't believe I missed it.

zachattack05 70 Posting Pro in Training

Stupid question I know. But I have looked for HOURS on examples of how to do this. Every single example I can find uses streamwriter or streamreader which reads and writes text, not byte arrays.

Is it possible to get a byte array from a CryptoStream?

The closest I can find is using a streamwriter and then using GetBytes(SomeString).

I don't understand, if CryptoString is encrypting binary data, why can't I get the byte array that the cryptostring creates directly from it? Seems like a huge chance for corruption by going from string data back to bytes.

Any help? I'm about to pull my hair out. I've tried everything I can think of.

zachattack05 70 Posting Pro in Training

Hmmm...Excellent point. I was unaware of the current user session requirement. I'll have to do some tweeking to it and see if I can encrypt with a different method.

Just seemed like all of the methods out there required you serialize the data to disk first, then re-serialize the new file with an encryptor...that's unacceptable to me. Recovering deleted, moved or otherwise "ghost" files is not hard. Granted, the data remains in memeory as well until the GC comes by, but still, that would take a bit more of an advanced hacker to grab it. It works well if you want to prevent some hacker from copying the file and trying to crack it on a different computer. The local machine I'm not worried about...if you lack the security on your work station, that's the user's fault and I can't prevent that.

Thanks for the info though! That could have left me frustrated again!

zachattack05 70 Posting Pro in Training

Ok...I spent hours (I know, probably something you pros know already) trying to figure this out. I finally did and thought I would share it with others considering I found nothing (literally) out there on this.

Feedback would be much appreciated!

Most of the time string data written to a file using the BinaryFormatter and a FileStream is human readable (to a point). You may not be able to directly tell what the string is (like is it a username, password whatever) but the string data itself is left as is. This is a problem if the data you are serializing is sensitive, or contains usernames or passwords for servers or other settings.

I figured out a way to serialize data and encrypt it all in one step. It's not perfect, but it works well for me.

Check this out:

I created a class that holds a few pieces of information, one of them is a connection string to an SQL server. (the data is fake I was just testing it). I called a method to serialize the entire class to a file. I opened the file that was created using Notepad and this is what was in it:

ÿÿÿÿ ;DATA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null DATA.LocalSettings BalloonHelpSysRunNumberSysFirstRundbmsConnectionTypedbmsDataSourcedbmsUserNamedbmsPassworddbmsCatalogdbmsIntegratedSecuritydbmsPersistSecurityconnSql ÿÿÿÿ


dData Source=localhost;Initial Catalog=master;Integrated Security=True;User ID=Zach;Password=MyPaSsWoRd

Not so good. The connection string is pretty obvious if it's what you are looking for.

I changed my method a little to put the class data …

zachattack05 70 Posting Pro in Training

That's what I figured...and that's what I intended to do if no one gave a good reason to do otherwise.

zachattack05 70 Posting Pro in Training

I have a project that can potentially use a SQL server as a host for it's data.

When a user starts the application for the first time, a wizard walks them through selecting how to store their data.

If a user selects the SQL option and indicates that the database they want to use doesn't exist and that the software needs to create it, what's the better choice:

1) Have the wizard connect to the SQL server, and if it can connect, check to make sure the user name they provided has all the permissions necessary to store the data on the server (such as create databases, use the select, insert, update, delete statements, etc...) and if they do, continue with the configuration wizard...

- or -

2) Assume that the user knows they have permissions, don't check on the permissions and just attempt to create the database and use the statements necessary. If at run time the queries fail, throw an exception and let the user know what the problem is?

Maybe both?

zachattack05 70 Posting Pro in Training

Hmmm....good point. I might look into that.

zachattack05 70 Posting Pro in Training

Thanks for the replies!

I do use locks, and invoke...that was a quick lesson that i learned when i first started threads.

I do understand that performance may not increase with using the threads unless someone has a CPU that is capable of processing them in a quicker fashion. I decided to use separate threads for these two functions because the two functions are completely unrelated and could be called later on in different code one at a time. If I combine the methods and use one thread, I lose the ability to run one and not the other without adding an if or switch to the code, which is unnecessary.

The threads are used because without it, the UI was hanging and wasn't processing any UX updates. Even with passing Application.DoEvents(), it did nothing. After starting the threads, they complete flawlessly now, and the UI never hangs. I'm extremely happy.

The methods themselves are rather uncomplicated, but they query the network for SQL servers and check system services for running servers to help configure the application. When the methods to query the network and the services are called the thread it is called on stops until the other method completes, which involves waiting for responses from network devices and services.

I agree that creating threads just for the fun of it is kind of useless and, if they are anything like the problems I had learning where the thread was dieing and which one …

zachattack05 70 Posting Pro in Training

Maybe this is more of a "how do you report progress" topic.

I have a progress bar on a form. The same form launches 2 separate threads. I would like each thread to report to the same progress bar.

Instead of cluttering my code up with a bunch of stuff like progressBarOverall.value += 10; .

I've used progress bars before for tasks with loops, and they work extremely well, but what about tasks with no loop? or tasks with multiple loops? Or even better...tasks with multiple loops but determining the number of times a loop must occur is a long process itself?

I know how to actually update the values of the progressbar from the threads, I'm just wondering if I have to keep calling stuff like progressBarOverall.value += 10; over and over again to update it?

Oh yeah...forgot to say I'm not threading with background workers...I'm using thread.start() and the like.

zachattack05 70 Posting Pro in Training

Diamonddrake,

Sorry I've been busy working on this thing...I never realized threads could be so complicated!

I'll have to post those screen shots either this afternoon or Monday...it's been so busy lately.

zachattack05 70 Posting Pro in Training

Nevermind :)

I got it figured out...I think

zachattack05 70 Posting Pro in Training

Having a problem here...not sure if it's something simple or not.

I'll be honest, threading is new to me so I'm not quite sure what the problem is here.

Let me explain the problem first and then I'll post some code.

I have a method that runs in a wizard called StartWizard(). The method is not a form method, but it does open and access forms to complete the wizard tasks. One of the methods that the StartWizard method calls is called InspectEnvironment() which runs two other methods that check to see if a .dll is registered and also scans the local computer and network for SQL servers that can be automatically detected.

I would like to have InspectEnvironment() run on a separate thread.

The InspectEnvironment() method is only called when the first step is shown in the wizard. The first step contains a few label controls, some picture boxes to indicate what task is currently being performed and a progress bar.

Before the InspectEnvironment() is called, the StartWizard() method shows an instance of the wizard container (an MDI form) and also calls another form inside of that container called Step1. Step1 is a form that contains all of the controls I mentioned.

The InspectEnvironment() method that needs to run on a separate thread needs to be able to access the controls on the Step1 form.

Earlier this morning the code was throwing exceptions saying that a thread was trying to access …

zachattack05 70 Posting Pro in Training

Diamonddrake,

Yeah, I've put my original wizard aside and have started working on a more simple one. The first one wasn't that complicated, but even so, it was less intuitive than my new concept. The new concept will take your suggestion of having default settings and advanced settings and will actually select some default choices based on the environment the software is running in (is the correct Ole extension installed? is there a SQL server running on the machine that can be automatically detected? is there a SQL server running on the local network that can be automatically detected?). Having some of these questions answered by simply querying the registry, the active services and the network can make the wizard look a lot less "heavy" and might prevent users from selecting options that would otherwise cause errors (such as selecting to use an Ole connection, but not having the extension installed to do so).

Now maybe instead of 4 screen changes, I'll only have 2 or 3. The code behind the wizard is much more complex now and was taking a while to perform tasks (now I need to split those into separate threads to possibly make it faster), but eh...I think it might be worth it.

No point in bothering a user with things that aren't necessary.

Anyone interested in taking a look at screen shots of the two wizards and providing some feedback? I'd love to have some constructive criticism.

zachattack05 70 Posting Pro in Training

Diamonddrake,

Good point.

The scalability of the application ranges greatly. Some users could be single users with no need (or even access to for that matter) for an application that could interact with a SQL server instance hosted on a network. But at the same time, a totally different user might need to allow access to a few dozen or even hundreds of users at the same time.

Though I don't think that many users would need such a large range. Similar software in the marketplace doesn't claim to have any restrictions on speed, network abilities, or the number of users (no surprise there). But in reality, a file based (Access) data source poses quite a few limitations, but also provides quite a few advantages. The same also applies to the SQL server solution though.

My main concern is not so much whether to offer the flexibility of choosing a data source type (file or server based), but instead how the end user's first interaction with the software is perceived.

First impressions mean a lot, especially in software. I can't tell you how many times I have downloaded "freeware" or purchased software that claims to be "user friendly" or "easy" and turns out to be nothing of the sort.

I understand that presenting setup wizards and first run guides are pretty standard in many applications. I would just prefer to limit the amount of time a user has to set up a software solution, …

zachattack05 70 Posting Pro in Training

I have been reading through a rather lengthy Microsoft document regarding UX (User eXperience) design and standards.

There are many great suggestions that I have started to adopt. But something occurred to me last night while working on my solution and I wanted to solicit some ideas and possibly have a short discussion on the topic of features and the Windows Forms Application UX.

Last night I was driving home from the office after spending quite a few hours on a handful of wizard forms and a concept that would allow users, on first run of the application, to setup a brand new data source. They are effectively presented with two options, create and use a new SQL Database, or create and use a new MS Access Database. Each selection carries on to a different form in the wizard asking the appropriate questions for the data source type and then finally executes a final form that creates, and inserts some default data into whatever data source type they selected.

I designed the forms using the UX guide that Microsoft published, which suggests that wizards only be used for tasks that are infrequently performed. Setting up the initial data source seemed like something that needed to be done on first run and never again. A wizard seemed logical.

The concern is though...is it necessary to offer it on first run or even at all?

My initial goal was to create a system that allowed flexibility, giving …

zachattack05 70 Posting Pro in Training

I considered just using .databkp. I just want to make sure that the extension is:

1) easy to remember for a user
2) unique enough that conflicts with other programs are limited.

I'll have to think about this a bit more.

zachattack05 70 Posting Pro in Training

I am adding a feature to my application that allows users to backup an entire SQL database, as well as include application settings with that backup file. My dilemma is choosing a good file extension to use.

The over-used .bkp type could cause conflicts in systems that have applications that already create a file with that extension.

I know that Microsoft recently started creating 4 character extension .docx etc... and was wondering what people thought about using extensions with 4 or more characters as well as just selecting file extensions in general.

zachattack05 70 Posting Pro in Training

*sigh*

Seems like interfaces keep poking their nasty little head up and staring at me.

Since I've learned about them, my code production/output has been terrible...I keep thinking an interface would be useful in situations where I'm not sure if it is, or just complicates things.

I'll read up on those. Thanks!

zachattack05 70 Posting Pro in Training

Has anyone tried this?

My general dilemma is having to open and maintain multiple connections across multiple forms.

I have an MDI application and I would prefer to store the connection in the parent form and just have the child forms use that connection if it needs it. This normally wouldn't be a problem except that the application can have many different data source types (a SQL Server or a Access Database). So simply using a delegate won't work because I can't cast the connection to the correct connection type until run time.

I have a feeling what I will have to do is use a delegate with the type of Object , and just use a if (Connection is _______) type of thing and cast it inside of the if statement and then call whatever functions the form needs to use the connection object.

Any other ideas or solutions that someone has used that they care to share?

zachattack05 70 Posting Pro in Training

I was wondering...has anyone ever written an application that interacts with a device that is NOT inside of the computer? Like a photocopier, scanner, etc...?

If so, does anyone know where I can find, or figure out, what type of communication protocol is required to talk to and use a particular device?

I am attempting to replace the functionality of an unsupported application called ScanRouter V2 lite which would interact with our MFP and allow users to scan documents as PDFs and deliver them to our file server. ScanRouter V2 lite is unsupported and is so old it wont work on our computers anymore.

Any suggestions on where I might be able to find this information?

zachattack05 70 Posting Pro in Training

embooglement,

No, I actually haven't researched or ever used virtual functions. You are the first person to bring them to my attention.

I think the main issue I have with the interfaces is determining what "class" was initialized when passing an instance of an interface class as a parameter.

Even in my race car example I was completely guessing when I put together public ICar AssembledCar(ICar selectedCar, IComponents fuelTank, IComponents motor) ...I'm still struggling to figure out how, if one method calls the AssembledCar() method and a ICar object is returned...how can the parent method find out "is this instance of the ICar object the red car or the blue car?" But I guess that's the whole point of using interfaces so that the methods don't HAVE to know. To get around that I embedded the name variable in each car and set it in the code...it's not a variable, that way I can just do a if/then/else or whatever referencing the object.name property.

I dunno...I'll figure it out I suppose. Right now I'm too scared to try implementing interfaces in my application...if I end up breaking tons of code I have no one to cry to but myself to fix it hehe...

Thanks a ton for your help! I really REALLY learned a lot the last few days.

I really do appreciate it. :)

zachattack05 70 Posting Pro in Training

Oh yea...anyway I suppose this thread is answered. Thanks momerath and embooglement!

zachattack05 70 Posting Pro in Training

Wait a second...I'm confused again (doesn't take much lately it seems)...if calling Close() on the object automatically disposes of it...would this code throw an exception:

if (Connection is SqlConnection)
            {
                //these types of connections can have many databases
                //cast our connection
                SqlConnection ActiveConnection = (SqlConnection)Connection;

                //open the connection
                ActiveConnection.Open();

                //create our data table and get the list of table names
                DataTable CatalogNames = ActiveConnection.GetSchema("Databases");

                //close the connection
                ActiveConnection.Close();

                //re-open the connection
                ActiveConnection.Open();

                //create our data table and get the list of table names
                DataTable CatalogNamesAgain = ActiveConnection.GetSchema("Databases");

                //close the connection
                ActiveConnection.Close();

                //return our data set
                return CatalogNames;
            }

Also, I was reading some more on the new .NET framework (v4) and found this which seems to indicate that when you call Close() or even Dispose() on a SqlConnection object, that it in fact is not disposed of, but is placed into a Connection Pool where active connections are stored and managed. Here's what the MSDN has to say about this:

Connection pooling reduces the number of times that new connections must be opened. The pooler maintains ownership of the physical connection. It manages connections by keeping alive a set of active connections for each given connection configuration. Whenever a user calls Open on a connection, the pooler looks for an available connection in the pool. If a pooled connection is available, it returns it to the caller instead of opening a new connection. When the application calls Close on the connection, the pooler returns it to the …

zachattack05 70 Posting Pro in Training

momerath,

For my own education I looked up SqlConnection Class on the MSDN site.

In the "Methods" section there is a chapter on the "SqlConnection.Dispose Method." There it gives an example of how to implement it. Here's the example:

Example

[Visual Basic, C#, C++] The following example creates a SqlConnection and then disposes of it.

[Visual Basic, C#, C++]Note This example shows how to use one of the overloaded versions of Dispose. For other examples that might be available, see the individual overload topics.

[Other examples removed from quote]

[C#]
public void SqlConnectionHereAndGone()
{
SqlConnection myConnection = new
SqlConnection("Initial Catalog=Northwind;Data Source=localhost;Integrated Security=SSPI;");
myConnection.Open();
//Calling Dispose also calls SqlConnection.Close.
myConnection.Dispose();
}

This example to me suggests that Dispose() is a method of the SqlConnection object and is defined already.

For example, if I do SomeVariable.toString(); I don't need to define anywhere what toString() does...it's already defined somewhere in the framework and I can just call it.

But then I thought I would look up Cleaning Up Unmanaged Resources. In that article it states that you should implement a dispose method and then proceeds to provide the following lengthy example:

// Design pattern for the base class.
// By implementing IDisposable, you are announcing that instances
// of this type allocate scarce resources.
public class BaseResource: IDisposable
{
   // Pointer to an external unmanaged resource.
   private IntPtr handle;
   // Other managed resource this …
zachattack05 70 Posting Pro in Training

momerath,

There are many objects (sorry for calling them methods before, I was very sleepy) that I use that I don't read documentation on.

I learned how to build and use an SqlConnection object by searching around the internet for examples (plus intellisense helps if you have a general idea of what an object needs to be used correctly). But until recently I didn't know that it implimented any type of "resource" that needed to be disposed. I assumed, incorrectly, the method ended, the objects and anything associated with them are gone.

I'm a little confused though.

If I use this:

class UnmanagedResourcesClass : IDisposable
{
//some code with unmanaged resources
}

Do I need to define somewhere what Dispose() does? I mean if I just create a method called public void Dispose() {}; what good does that do? There is no code for it to execute if it is called...

If I just use:

class UnmanagedResourcesClass
{
//some code with unmanaged resources
}

and after a SqlConnection object is used, I use MyObject.Dispose();

will that alone dispose of the unmanaged resources? Or do I need to define Dispose(); somewhere in the class?

I'm lost because, if I need to define what Dispose() does...what exactly do I put in the method? Don't all objects that need to dispose unmanaged resources use the same process to dispose of them?

zachattack05 70 Posting Pro in Training

embooglement,

Thank you so much for trying to explain this to me. But that last example threw me for a loop.

Let me try this.

Pretend we are going to build a race car game together. Forgetting all the stuff involved in that and only worrying about the cars and the race itself, take a look at this and tell me if you see any problems. VS doesnt show any, and it's not functional obviously, but I'm more into if this is a good implementation of interfaces and that the usage of the class instances is correct.

namespace AwesomeRaceCarGame
{
    /// <summary>
    /// Defines what all cars in our game need
    /// </summary>
    interface ICar
    {
        string Name { get; }            //the name of the car so a player can identify it
        int Speed { get; }              //the maximum speed of the car in kph
        int FuelCapacity { get; set; }  //how much fuel the car can hold in (litres)
        int Acceleration { get; set; }  //how fast the car accelerates in (kph/sec)
        int Deceleration { get; set; }  //how fast the car decelerates without braking and no acceleration 
                                            //in (kph/sec)
        int Weight { get; set; }        //how much the car weighs - use this to compute acceleration and 
                                            //deceleration (fuel weighs something, so we should include that)

        bool Drive(Object track, ICar opponent);    //the method that computes acceleration, 
                                                    //deceleration, weight and calls other 
                                                    //functions that would display the car's 
                                                    //position on a track as well as …
zachattack05 70 Posting Pro in Training

Very good point embooglement...I suppose a developer has a general idea what system requirements their final product will require, RAM quantity being one of them. Disposing of something in mid function when it is no longer needed could reduce the RAM cost of the application.

Momerath...how do I know if something implements IDisposable...

Surely no one browses through the documentation of every function called to check if it uses IDisposable, applications would take decades to write...would it be a safe assumption that if I am done with something to use intellisense to see if something has a .Dispose() method? If it does, I should use it?

Also, is it necessary to write the function ((IDisposable)sc).Dispose(); or would sc.Dispose(); suffice?

Also, as I am discussing with embooglement in a different thread the concept and implementation of interfaces...with IDisposable being an interface...doesn't its implementation require a class and a Dispose() method to be defined somewhere? Or does the system have that automatically defined somewhere to handle the Dispose() method?

I guess what I'm saying is, in the absence of all other code, would building a connection to a SqlServer, opening the connection and then closing the connection and then simply calling ((IDisposable)sc).Dispose(); actually dispose of the resource? Or is something else needed?

zachattack05 70 Posting Pro in Training

I've never used DirectX or anything similar so the concept sort of escapes me completely, but I could pretend... :)

One thing I don't understand is...how can a class method that implements an interface return a specific object if it doesn't know what object type to return?

When I create a method the standard that I follow is if a method returns something (anything) that type needs to be declared. (or you could use the Object type and cast it later)

For example:

public SqlConnection MakeSqlConnection(some parameters that a sql connection needs)
  { //code to make a SqlConnection
    return a built connection
  }

In your interface, if you define a bunch of methods to build every possible connection (or DirectX device) type you want to support that means every class that uses it would need to define methods for all of those as well...that doesn't seem very logical.

Also, did I understand you correctly that you can define classes (methods, properties, events etc...) inside of an interface definition? I don't get it? How? I didn't think interfaces could contain classes, only the skeleton of a class?

What you are talking about with the DirectX solution seems very similar to the whole reason I looked into interfaces to begin with. I am developing an application that can support various types of data sources (but only uses one at a time), each data source needs to be communicated with in a different way, but most have …

zachattack05 70 Posting Pro in Training

I see, allowing for another programmer (after my application is complete) to write a .dll plugin or whatever, to add a new class of animal to the list can be done my accessing the public Animal interface and complying with it, so long as my application allowed such a thing.

Besides allowing other programmers or users to programatically add to the Animal type, why would a programmer use an interface?

If, for instance, I didn't want an outside user to add new Animals, why would I want to implement interfaces in my application? Do you have any real-life specific examples...I don't need to see code, just a synopsis of a situation besides adding things to a list.

zachattack05 70 Posting Pro in Training

embooglement,

I think I am starting to get the idea behind interfaces, and I can see a few instances where it could be useful. Having many classes that are related in some way, but perform slightly different functions would be an example. Maybe interfaces for performing mathematical computations that all require the same number and type of variables but produce different outcomes could be a situation.

But more so, it seems like, unless two classes are going to potentially interact with each other in some way, interfaces aren't necessary. Is that right?

Even in your original example with the cow and dog...the only reason (I imagine) that a programmer would want to put those objects into a list together is because they have something in common, and somewhere along the line they may interact with each other, like having a dog chase a cow and produce a result (the dog catches the cow, or the cow escapes) and then having a different method interpret that result and either perform additional methods or return the result to a variable for use later; or with mathematical computations, having one mathematical class depend on another to achieve a final solution.

I could also see using interfaces to potentially "protect" certain methods from throwing exceptions and/or guarantee results of a certain kind, for example If a method such as public Animal myMethod(Animal parameter1, Animal parameter2){ //do stuff return AnimalObject } was implemented, passing a string, integer or any type other …

zachattack05 70 Posting Pro in Training

I've been trying to figure this one out.

I was under the impression that when a class method contains any resources, once the method has reached the end of the code and returns it's result (or nothing in the case of void), that all of those resources are gobbled up by the garbage collector and released back to the system.

If this is true, why would anyone ever bother disposing of something, managed or unmanaged? If I have a form that displays data in a DataSet or Array or whatever, those resources need to persist and when the form is closed, the form and all the components and resources associated with it should be released as well right?

If I have a connection to a data source, and it is called in a method, once the method is done (even if the programmer forgets to close the connection) the connection, connection string etc...should all be released from memory right?

I don't seem to understand why it would be necessary to bother with disposing of something that should be disposed of automatically.

Besides, how would someone know what kind of resources are unmanaged? Is there a list somewhere?

zachattack05 70 Posting Pro in Training

embooglement,

I've been reading your post over and over and doing more self-education on interfaces...I wonder though...

How do you deal with a multiple (possibly dynamic) number of instances of the same class that are initialized with an interface?

Like for example...

Changing your code from:

class Program
{
   public void Main()
   {
     Farm farm = new Farm();
     farm.AddAnimal(new Cow());
     farm.AddAnimal(new Dog());

     foreach(Animal a in farm.animals)
     {
       a.MakeNoise();
     }
   }

}

to:

class Program
{
   public void Main()
   {
     Farm farm = new Farm();
     farm.AddAnimal(new Cow());
     farm.AddAnimal(new Cow());
     farm.AddAnimal(new Dog());

     foreach(Animal a in farm.animals)
     {
       a.MakeNoise();
     }
   }

}

adds a second cow to the list. Great...how can I tell cow #1 apart from cow #2?

What if in my foreach statement I only want the second cow to moo and not the first one?

Or in a dynamic situation where a loop is used to add animals to a list and the number of times a loop is run depends on user input...at compile time we don't know what number the user will put in. It could be 0 or a million. How could we modify any of those number of instances?

What if we had the interface for Animal set up like this:

interface Animal
    {
        string NoiseToMake { get; set; }
        string CreateANoiseToMake();
        void MakeNoise();
    }

and each class instance could be implemented differently like this:

class Dog : Animal
    {
        private string _noiseToMake;

        public string …
zachattack05 70 Posting Pro in Training

embooglement,

missed your other question. I've never even heard of virtual functions. I'll have to research that. Are they related to interfaces?

zachattack05 70 Posting Pro in Training

It's late so bear with me...

embooglement,

Let me make sure I understand this implementation by stepping it out:

1. You create an interface (Animal) and define in that interface what is required for any classes to be derived from that interface (MakeNoise()).

2. You then create classes that are derived from the interface (Cow and Dog). You can derive nearly an unlimited number of classes from the interface, all of which follow the same interface scheme, but are different (Cow.MakeNoise() returns Moo and Dog.MakeNoise() returns Bark).

3. You can then create any number of other classes that are not derived from the interface (Farm) but can use instances of the classes that are derived from the interface.

That's honestly as far as I get before I start to get lost.

How about this...tell me if this is a good example of a situation to implement an interface:

A program that supports retrieving data from a few different data sources (MS Access files or an SQL server). I ask this because I have something that does that now...would an interface be useful in a situation like this?

If an interface wouldn't be of help here...I really am lost still to find a situation where one would be useful. Farm animals are cute and the example you provided makes sense...but I can't think of a real situation where something like that would ever be used. Maybe I just haven't gotten that far …

zachattack05 70 Posting Pro in Training

Hmmm...

too many copy variables and...too many copy words!

I think I understand what you mean though...that a-ha moment is approaching I think...

so would it be a fair statement to say interfaces are useful, but are only useful when a class implements the interface and a different, 3rd class calls what it needs from the second class?

Bad wording I think, let me try saying it a different way...in order to use an interface correctly, one would implement the interface on a class and the properties, methods etc... inside the class (or multiple classes I suppose) could be called by a different method in a different class?

You basically make a template with an interface, and build classes off of that interface to use elsewhere...right?

Would you ever implement an interface on a class that contained code that would execute on it's own?

For example, would it ever be useful to implement an interface on say, the

Program

class? (you know, the entry point for the application?) Or on the class that your main application form opens under?

Seems like it might be better to implement the interface on a different class and then just call whatever you needed from that class to the

Program

class or the main application form.

I still do not see how it could help improve code maintainability though...If my application uses an interface to build class objects and in the future that …

zachattack05 70 Posting Pro in Training

For the past few hours I have been pouring through hundreds of internet articles, blogs and posts in various forums regarding interfaces.

I get a general idea that it is basically a class with no implementation at all...a "skeleton" if you will.

I was hoping for an a-ha! moment that never came. This is my last ditch effort here.

What exactly is the usefulness of making interfaces?

I've read that it makes code more clean and easier to manage, but I fail to see how it would ever do that. Changing a public class that is used by many other methods or classes seems to be much MUCH more manageable than editing a "template" and then having to edit (maybe) every single instance of that template.

Also, it provides no information on it's function.

I mean an interface like this:

public interface ICopy
{
public void CopyMethod();
}

Could be implemented in any way a programmer wants like this:

public class FileManipulation : ICopy
{
public void CopyMethod()
{
//code to copy files
}
}

but it could also be implemented like this:

public class MakePrankCalls : ICopy
{
public void CopyMethod()
{
//code to use a modem and dial random numbers then play a .wav file to prank them
}
}

I mean it basically means nothing right?

The definition of an interface (in computer science) is "a point of interaction between two components." I fail to see how …

zachattack05 70 Posting Pro in Training

That's what I figured...makes sense that it would be easier to update.

zachattack05 70 Posting Pro in Training

So is it just for programmer preference? There is no real benefit to it other than programmer organization?

zachattack05 70 Posting Pro in Training

I have been reading through many blogs, the MSDN website, and Google search results trying to figure this out...

At what point, or in what situations would someone ever want to have multiple projects under one solution?

I have thought about having a project that contains forms and some "core" elements and another class library project that would contain SQL connection string builders, command interpreters for a console in a window and a data verification routine...the problem is, doesn't that create an exe and a dll file that need to be distributed?

If so, what advantage is there to this? Wouldn't it just be better to cram everything into the exe instead of splitting it?

Does it possibly make updates in the future easier?

Any guidance is appreciated.

zachattack05 70 Posting Pro in Training

Momerath,

If you get a chance can you find the name of that book? I might want to check that one out and see if it's any help.

I'm not really sure why it's split up. I understand that SQL does have overhead...it's a server. But in a network environment, where you have hundreds of potential users accessing the same data, a file based system seems (to me) to be a terrible choice...a programmer would have to create (I would think) some sort of manager to update the file as new queries come in...which in essence is a SQL server, it's just a custom made one. General Windows file sharing wouldn't suffice. Right?

zachattack05 70 Posting Pro in Training

I am working on a software project that utilizes the MSSQL Express version. My question is...

I have checked out software that does the same thing that I want to do, but it seems that the competition uses a file based database system. I intend to use SQL because it seems easier and more reliable to me. Anyway, the issue I have is, the competition stores their data in generic dbf files that can be opened in excel or any other similar type of program. So I checked out the data structure, they store all addresses in one file, all contact names in another file, all billing information in one file, all billing addresses in another file etc... I am just wondering...because I know the company won't tell me if I ask, what would be the reason for splitting this information up into so many fragments? I assume because it is file based it is to help avoid read/write IO problems but I can't tell. I would think that having to look in multiple locations for one "record" would cause significant performance problems. I know once the data is retrieved from the file, the file is "closed" so to speak so that other instances across the network can view/modify the data (I tricked them into telling me that) but that's about all I can get out of them.

Any thoughts?

If I'm using an SQL database to store my information, would it improve or hinder performance to …

zachattack05 70 Posting Pro in Training

This might be my best option. I would prefer the calendar drop to be months only, but in the absence of that, using the arrows might be the best option.

zachattack05 70 Posting Pro in Training

Hi!

I was wondering if anyone knew a way to have a date/time picker only allow the selection of months/years? Like January, 2010...etc and not the specific day of the week?

Kinda like the attached image.

zachattack05 70 Posting Pro in Training

I think for the sake of my sanity and to not rush into anything. I am going to complete my application to a generic level.

At that time I'll just make a copy of the directory and work on a second copy and add the functionality that my employer needs.

I think plug-ins are a little too advanced for my taste at the moment. I'm sure it's much simpler than I am making it out to be, but I'd rather stick to what I know for now.

zachattack05 70 Posting Pro in Training

I would actually like the plug-in to house all of it's own functions, but only be "set into motion" by the main application.

The data that the plug-in would use is located on an SQL server. The data needed from the main application (such as connection strings, the current user and the current user's permission level etc..) would be sent to the plug-in functions when called as variables.

The plugin would alter the data, update the data or whatever all based on the information sent to it by the host application.

Am I thinking about this to simply? I tend to do that sometimes.

I suppose that the menu bar on the host application would have to be modified to show plugin "commands" that the user can select from. But that can be set by the host right? The host could request information from the plug-in and display it, the plugin shouldn't need to alter the menu on it's own.

The plugin that I am thinking of at the moment would be built using the QuickBooks SDK. Basically it would collect data from a table in a SQL database, parse it correctly and send it to QuickBooks to generate invoices automatically.

I do see your point about changes requiring plugins to change...that's a point I never thought of.

zachattack05 70 Posting Pro in Training

I'm getting to a point in my project where functionality can be based on the needs of individual users.

As part of my application I would like to have the ability to add and remove functionality based on the user. I figure plug-ins might be the way to go for something like this.

Here is my current dilemma:
I have a rather sweet deal going with my employer. I get paid to write a software solution and the final source code and solution remains my property.

I am designing my application from a very generic point of view, as in, I want to be able to market the final product to other companies and not have features that only apply to my current employer.

I want to put the features that my employer wants that are specific to them into a .dll (for example) and when that file is added to a "plugin" folder in the application directory it will add those features. If the .dll is not there, the features aren't there and the application will still function normally.

Before I spend more hours researching the different ways of doing this (I've already spent a few), I was wondering if I could get a simple discussion going on if this is a good idea, bad idea, problems, pros, cons, etc...

I'd really like to hear from people who have done something like this before.

zachattack05 70 Posting Pro in Training

Sure,

The solution I was using was correct. For some reason when the form is small in size the code doesn't function the way I expected. But if the window is made larger it works perfectly, so much so that you don't even notice anything happened.

Here is my code:

#region Refresh RecordSet
        
        /// <summary>
        /// Reloads, trims and refreshes the current recordset every 30 seconds
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ReloadRecordSet(object sender, EventArgs e)
        {
            //set cursor
            Cursor = Cursors.AppStarting;

            int scrollPosition = this.VerticalScroll.Value;

            //set the task
            Main main = ParentForm as Main;
            mainTasks task = new mainTasks(main.statusTaskCurrent);
            mainProgress progress = new mainProgress(main.statusTaskProgress);
            task("Refreshing account data...");
            Application.DoEvents();

            //get our current position in the recordset
            int recordCurrent = int.Parse(DataNavigatorPositionItem.Text) - 1;
            
            //get the number of records we have right now before the refresh
            int oldRecordCount = bindsrc.Count;

            //update the dataset with the new records
            adrQuery.Fill(dsQuery, "accounts");
            
            //delete the old records from the data set
            int i = 0;
            while (i < oldRecordCount)
            {
                //update our progress bar
                progress(oldRecordCount, i);

                dsQuery.Tables["accounts"].Rows[i].Delete();
                i++;
            }

            //accept any changes to the data
            dsQuery.AcceptChanges();

            //set our current position
            bindsrc.Position = recordCurrent;

            //reset the task
            task("Idle");
            progress(100, 0);
            Application.DoEvents();

            this.VerticalScroll.Value = scrollPosition;

            //return cursor
            Cursor = Cursors.Default;
        }

        #endregion
zachattack05 70 Posting Pro in Training

Figured it out. :)

zachattack05 70 Posting Pro in Training

I have a timer that runs a SQL query every 30 seconds to retrieve updated information.

Unfortunately every time the query runs the vertical scroll bar resets to the top most part of the form.

I tried

int scrollPosition = this.VerticalScroll.Value;

at the beginning of the timer code and

this.VerticalScroll.Value = scrollPosition;

at the end, but it only scrolls 1/2 way back. For example, if you are all the way at the bottom of the form, it resets to the middle of the form.

Any suggestions? I'm lost. It's not a major bug, but it's annoying.