mcriscolo 47 Posting Whiz in Training
mcriscolo 47 Posting Whiz in Training

Nonsense! Forms are your friend! Here's how you can get it to work, provided, that Form2 acts as a dialog - that is, you display Form2 wait for the user to exit the box, then close Form2 and collect the information from now hidden form.

In Form1 (in the button1_Click method):

Form2 f = new Form2();
f.ShowDialog();  // Code will hang here, waiting for Form2 to go away
MessageBox.Show(f.getText());
f.Close();// Discard the form

In Form2, put a single, lone text box, called "textBox1", and a button, called "button1", then:

private void button1_Click(object sender, EventArgs e)
{
    this.Hide(); // Hides the form, but it is still alive!
}

public string getText()
{
    return textBox1.Text;
}

The public "getText" function is called from Form1 after the user presses the button in Form2. The code in Form1 is able to "reach into" Form2 to call the public function and get the contents of the text box. Then, you call "Close" on the instance of Form2 to get rid of it.

mcriscolo 47 Posting Whiz in Training

That may be a way to do it. The COM addin could handle the communications, and some client-side macro code (VBA) could take the results from the addin and do something meaningful with it in a Word doc (like create a new doc that has, for example, the label data needed to perform a mail merge).

Looks like you may even be able to use Visual Studio to do Office automation development - check this out: http://msdn.microsoft.com/en-us/library/bb157892.aspx - you may be able to develop your client side library as a DLL or an Add-in, and then call it from Word via buttons and get it do you what you need.

mcriscolo 47 Posting Whiz in Training

You do have the word "double" in your regex string twice (once near the beginning and once near the end). But that doesn't fix the issue.

Modify your token string to look like:

string tokens = "\\s(auto|int|struct|break|else|long|switch|case|enum|register|typedef|char|extern|return|union|const|float|short|unsigned|continue|for|signed|void|default|goto|sizeof|volatile|do|double|if|static|while)\\s";

This will cause it to make sure each token is preceded and followed by a whitespace.

mcriscolo 47 Posting Whiz in Training

A few things to look at:

1) Since RealEstateSalesPerson and GirlScout are subclasses of SalesPerson, and SalesPerson takes two strings as parameters on the constructor, you may want a way to pass these two strings when you construct a RealEstateSalesPerson instance. Sure, you could leave it like you have it, but then you will have to do this:

RealEstateSalesPerson oRS = new RealEstateSalesPerson(7.0);
    oRS.FirstName = "Bob";
    oRS.LastName = "Smith";

Wouldn't it be nicer if you could just do:

RealEstateSalesPerson oRS = new RealEstateSalesPerson("Bob", "Smith", 7.0);

You can, if you do your constructor like this:

public RealEstateSalesPerson(string fName, string lName, double commissionRate) : base(fName, lName)

That way, the base class (SalesPerson) gets set up with the first name and last name, and the derived class gets the commission rate.

2) The "fullName" method in the SalesPerson class should be implemented there, not set up as "abstract". The derived classes will be able to call it. Remove the implementations of "fullName" from RealEstateSalesPerson and GirlScout. They wouldn't have worked anyway, because for some reason, they were set up with a return type of "double", but the method was actually returning a string.

3) You've defined the ISell interface, but you don't make your classes implement it. It needs to be specified on the "class" lines for the RealEstateSalesPerson and GirlScout classes. This can be seen in action in your current code, since the MakeSale method is not implemented in the GirlScout class. If the interface were …

mcriscolo 47 Posting Whiz in Training

Oof, wrong forum...

But, I was looking at EnumDisplaySettings; however, that appears to be in System...

Well, the same site as my last (erroneous) link has a C++ example, but it's probably no good to you, since it's using System namespace functions:

http://www.news2news.com/vfp/?example=374&ver=vcpp

Sorry I couldn't be of any help.

mcriscolo 47 Posting Whiz in Training

Current screen size/resolution.

You will need some more code to check the display driver capabilities. Check this out:

http://www.news2news.com/vfp/?example=374&ver=vcs

mcriscolo 47 Posting Whiz in Training

What do you have so far?

mcriscolo 47 Posting Whiz in Training

Enrique,

It's because you declare the class "DataStructure" within the namespace of "CreateFile". When the file is created, the class is serialized with the namespace under which it was created. When the ReadFile project comes along, it cannot resolve the "CreateFile" namespace that's in the data file.

Try this: declare a separate C# file (call it DataStructure.cs) and move your declaration of the DataStructure class into it (you will have to change the [Serializable] tag to [System.Serializable]). Remove the DataStructure declarations from both the CreateData and ReadData classes. Include the DataStructure.cs file into both projects.

Should work a whole lot better.

mcriscolo 47 Posting Whiz in Training
mcriscolo 47 Posting Whiz in Training

zachattack05,

To answer your last question first - no, security and tech support issues are never unfounded. Once you deliver an application to a user, you have to support it. And you will also have to make sure that only authorized users access the system.

I may have misunderstood part of your explanation of the app - you will be delivering the "server" app to your customers? I was under the impression that the server would remain with you (or your company) and the clients would access it over the network. Of course, if you are packaging up this solution, then the decision to include or not to include a full-blown database is a big one.

If I also understand part of the use case for the clients, you would want to be able to access the "server" directly from programs like Word or Excel? Hmm... If I had to do that, I'd open the can of worms with the database. While there is a lot of management that comes with it, I still maintain that it would be easier and take less time than trying to develop a wire protocol mimic of SQL Server or ODBC. You could always lock down the security in the database, and also issue the standard warning that if the customer monkeys with the database that you're not responsible, blah, blah (even though you and I both know you really are... But maybe you can beat some support $$$ out of …

mcriscolo 47 Posting Whiz in Training

Other than the details you gave in your post (so I don't know the *real* complexity of your app, or your budgetary constraints), might I suggest that you actually convert the data for your app to use a database? That is (and again, I'm not privy to the reasons why a custom format may be needed), developing a pseudo-ODBC driver or a server process that mimics the wire protocol of SQL Server (TDS, or Tabular Data Stream) seems like a whole lot of work. The time you spend developing, debugging, and then maintaining such a construct seems way more than what it would take to convert your data to use a database.

If the clients expect a database, then give 'em a database.

That being said, if a database just isn't going to work for you, there are some open source projects you may be able to look at to "borrow" some code - FreeTDS (though that's mainly for Unix/Linux programs that need to access a SQL Server database; and it's in C), unixODBC is an ODBC driver/manager developed in C.

Since you mentioned C# (probably running on Windows), there is a free edition of SQL Server 2008 (Express Edition) - it has some limitations, but it may be something you can try out.

Check this link out http://www.thefreecountry.com/sourcecode/database.shtml for a list of database projects where source may be available.

Good luck!

kvprajapati commented: Good suggestion! +11
mcriscolo 47 Posting Whiz in Training

In the Mask property, use the "a" character instead of "0". This will allow alphanumerics (a-z, A-z, 0-9). Be sure the "ASCIIOnly" property is false, otherwise it will not allow you to enter the numbers (it defaults to false).

See the link I posted in an earlier post to see all of the options you can use for the control.

mcriscolo 47 Posting Whiz in Training

Put this into your "Clear" button's code:

dTable.Columns.Clear();  // Clears the column defs
    dTable.Clear();          // Clears the data

The dTable is what actually controls what the DataGridView displays. So, clearing this out corrects the issue.

mcriscolo 47 Posting Whiz in Training

Change the property "PromptChar" - it is currently set to the underscore character. Change this to a space and you should be good.

mcriscolo 47 Posting Whiz in Training

You may want to try the MaskedTextBox. It allows you to specify a mask to use in the control. Also, this will be smoother for handling things like editing in the control (backspaces, user clicking in the middle of the text and making changes, etc.) To set the mask, do this:

myMaskedControl.Mask = "00 00 00 00";

This will allow the user to enter 4 groups of digits, separated by spaces.

See the MSDN doc for additional explanation of the characters you can use in the mask, e.g., allowing the user to enter letters, etc.

http://msdn.microsoft.com/en-us/library/1fkc1cz6.aspx

mcriscolo 47 Posting Whiz in Training

Have you tried setting the "DataSource" property of the DataGridView to null?

tblAllEntries.DataSource = null;
mcriscolo 47 Posting Whiz in Training
mcriscolo 47 Posting Whiz in Training

Use the "CompareTo()" method of the string class. It compares two strings and returns an integer, thusly:

int iCmp = Text[i].CompareTo(Text[i+1]);
if (iCmp < 0)
{
    // Text[i] is "less than" Text[i+1]
}
else if (iCmp > 0)
{
    // Text[i] is "greater than" Text[i+1];
}
else
{
    // Strings are equal
}
mcriscolo 47 Posting Whiz in Training

Try this link:

http://www.switchonthecode.com/tutorials/csharp-tutorial-binding-a-datagridview-to-a-database

Looks to be a good example of exactly what you need.

mcriscolo 47 Posting Whiz in Training

Look at line 33 - is this the correct way to call a function? See line 24 for a good example...

But you have a second problem. Look at where "firstNum" and "secondNum" are declared (in the function "displayMessage"). These will not be visible in your main() function. You either need to define them in main, then pass them to the displayMessage function, or make them global.

mcriscolo 47 Posting Whiz in Training

This is going to sound like I'm being an a**, but I don't mean to be... sometimes it helps to just put stuff down on paper and visualize it.

Write 2 columns of ascending (sorted) numbers on the paper (you can use 10 values, but less will suffice for illustration). Have an arrow point to the top of the "a" (left) list, and another arrow point to the top of the "b" (right) list. You will single step through the values in the "a" list, comparing them to the values pointed to by the pointer in the "b" list. Set aside room for a result list (which is now empty):

Compare:
- If the pointer for the "a" list is past the end of the "a" array, write all the remaining values from the "b" list to the result list and exit.
or
- If the pointer for the "b" list is past the end of the "b" array, write all the remaining values from the "a" list to the result list and exit.

- If the "current" value in the "a" list is greater than the "current" value in the "b" list, write the "b" list number in the result list and move the pointer up in the "b" list. Go back to "Compare:"
- If the "current" value in the "a" list is less than the "current" value in the "b" list, write the "a" list number in the result list …

mcriscolo 47 Posting Whiz in Training

It looks like you may be off a node when you issue the delete.

Here's a console app that will do what you want - you can adapt the code as you see fit:

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;

namespace XMLDelete
{
    class Program
    {
        static string sXML = "<?xml version=\"1.0\"?><Security><User><Username>jon</Username><Password>khan</Password><UserFolder>aliHomeDIR</UserFolder></User><User><Username>bob</Username><Password>khan</Password><UserFolder>aliHomeDIR</UserFolder></User></Security>";

        static void Main(string[] args)
        {
            XmlDocument myDoc = new XmlDocument();
            myDoc.LoadXml(sXML);
            XmlNode nodeToDelete = null;
            XmlNode topNode = myDoc.SelectSingleNode("/Security");
            foreach (XmlNode UserNode in topNode.ChildNodes)
            {
                foreach (XmlNode kid in UserNode.ChildNodes)
                {
                    if (kid.Name == "Username" && kid.InnerXml == "jon")
                    {
                        nodeToDelete = UserNode;
                        break;
                    }
                }
                
                if (nodeToDelete != null)
                    break;
            }

            if (nodeToDelete != null)
            {
                topNode.RemoveChild(nodeToDelete);
            }

            System.Console.WriteLine("Edited XML: " + myDoc.OuterXml);
        }
    }
}
mcriscolo 47 Posting Whiz in Training

Looks like someone over at "social.answers.microsoft.com" is already answering this....

But, to be complete, I pasted the code into a new VS2008 project and ran it on my 64-bit Windows 7 installation, and it ran just fine.

On a subsequent run, I deliberately messed up the machine name but in that case got an error code 53 - ERROR_BAD_NETPATH.

What version of Visual Studio are you running? What version (32-bit/64-bit) of Windows 7 are you using?

mcriscolo 47 Posting Whiz in Training

The only potential issue I see is that if you call "addnode" twice. The method does not check to see if "start" is pointing at anything. If called a second time, you will lose the context to the node that was established in the first call.

You can really just do away with "addnode" and just use "addatbeg" to add nodes, even when the list is empty.

mcriscolo 47 Posting Whiz in Training

Is the data coming in to you sorted? Or, can you sort it?

If so, then you can use standard break totaling. That is, you have "holder" variables for the vendor and the budget period. Then you process each row of your set, totaling up the values for your financial fields until the budget period of the current record doesn't match the hold version of the budget period. This means you are about to process a new budget period - you then output a line with the hold vendor, hold budget period and the totals. You then zero out the totals, replace the hold budget period with the current budget period and continue. You will also check to see if/when the vendor changes, and do the same sort of thing.

FInally, when you reach the end of your dataset, you output the values for hold vendor hold budget period and your accumulated totals. No need to create an array of the data, since you will process it as you go.

mcriscolo 47 Posting Whiz in Training

On line 58 of your server.cpp, you are hanging on the "accept" call. That is, first time through, you accept the connection from your first client. It's running through your loop below, but there's no data, so it goes back to the top and hits the "accept" again, waiting for another connection. Only after the second client connects do you go through the loop, check the input and send the response back to the first client.

You will need to use a multiplexing function like "select" to check the readability of the sockets (including the "server" socket) so you don't hang on inbound connections. You will instead use the select function to test the sockets (you pass in an array of socket handles), and the return from the select call will indicate which handles are ready for reading (or accepting). This way, you can service data from connected clients without having to have new connections kick you off the accept call.

The GNU site has an example of a C/C++ socket server that uses select:

http://www.gnu.org/s/libc/manual/html_node/Server-Example.html#Server-Example

mcriscolo 47 Posting Whiz in Training
mcriscolo 47 Posting Whiz in Training

You will have to handle the "Draw" event for the tooltip and render it yourself. See the link below for the code:

http://social.msdn.microsoft.com/Forums/en-US/winformsdesigner/thread/19994c9f-bdaa-4c4c-bcb4-5c60cb241134

mcriscolo 47 Posting Whiz in Training

I'm not completely sure I follow you... Are you saying:

1) You need to login to a page with the first username/password, wait until the page loads, then (somehow) login again using the second (different) username/password,

or

2) You need to use 2 webbrowser controls, one for the first set of credentials, and another for the second set.

I guess I'm trying to figure out why you need to login twice.

mcriscolo 47 Posting Whiz in Training

If it's a Windows Forms app, yes, you can use the Timer object and set the "Interval" property to the desired value, in milliseconds, then call the "Start()" method to start the timer. It will fire the "Tick" method when the interval is reached. From there, you can call any method you like.

If you want to do it all in code, you can use the System.Threading.Timer object. Plenty of examples on the web of how to use that facility, but generally:

Timer myTimer;

// myTimerCallBack - method to call
// someData - blob of data that will get passed to the callback (can be null)
// timeBeforeFirstExec (in milliseconds)  - time before the first time the timer fires
// period (in milliseconds) - recurring interval to fire the timer
myTimer = new Timer(myTimerCallback, someData, timeBeforeFirstExec, period);

public void myTimerCallback(Object obj)
{
    // obj is the "someData" from the call, above
    // Do timer stuff
}

Hope this helps.

mcriscolo 47 Posting Whiz in Training

One issue - the code:

string year = reader2[indexYear].ToString();

Is indexing the row using an integer value. For example, if "indexYear" is 2001, you will be trying to get the 2001st column of the row - of course, your row only has one column in it, hence the exception. Try this:

string year = reader2[indexYear.ToString()].ToString();

This will index the row by column name, rather than by number.

mcriscolo 47 Posting Whiz in Training

can i transfer the data in text file to sql to be in table format not as a whole textfile.

That depends on how you need to access the data afterward. You could shove the entire text blob into a database table as one column, or, if you've split out the extracted data into fields (like name, address, phone number, etc.), you could set up a database table with columns for each of those fields, then insert a row containing that data.

Usually, it's better up front to parse and cleanup the data you've extracted, separate into fields, and then setup a table that holds that data. Makes the "downstream" process of using the extracted data easier.

Does that help?

mcriscolo 47 Posting Whiz in Training

Have you hand-run your SQL statement to see what results it produces? It appears to me that the statement will only return a single column. However, in your statements after the "reader2.Read()", you are accessing multiple columns. If there's only one column in the result set, that code will definitely generate an IndexOutOfRange exception.

mcriscolo 47 Posting Whiz in Training

If I understand correctly, rather than having the user press a button to bring up the page in the WebBrowser control, you could put "webbrowser1.navigate" statement into the "Form_Load" method of the form. Just double-click in a blank area of the form and the code window will appear, with the cursor in the "Form_Load" method.

This way, when the form loads and control is given to the user, the WebBrowser control will already be populated with the page you want.

mcriscolo 47 Posting Whiz in Training

First, does the IDE tell you what line you're getting the NULL reference exception on?

Not sure how you want this to work, but when you check the XML node in your first "if" statement - if it's true (that is, the node is NOT null), you do this:

c = null;

Then exit the function, returning "c". If the caller of the function is not expecting the return value to be NULL, you have a problem. Also, if the value of the node is NULL, you go to the trouble of pulling various items out of the XML, assigning them to the local variable "cond" - but then you don't do anything with it.

mcriscolo 47 Posting Whiz in Training

As always with this stuff, there are many ways to skin the proverbial cat. Using the timestamp method, you could even go as far as this: when you attempt to apply the update but find the record's been updated under you, re-read it into another buffer and compare the appropriate values, highlighting any differences and display to the user. Of course, that's a lot of elbow grease. More simply, you could just put a message out to the user saying "Another user has updated the record; please re-enter your changes" and re-display the form to the user with the new values from the newly-updated record.

mcriscolo 47 Posting Whiz in Training

I guess I need to understand what you are looking for. Do you want multiple pictureboxes that are clickable? Or do you want to have multiple images cycle through a single picturebox when it's clicked?

mcriscolo 47 Posting Whiz in Training

One simple way is to use a DateTime or Timestamp column. When you update the row, check the timestamp to see if it matches the value you got when you pulled the record for editing. If it does not match, you know someone else updated the record while you were working on it.

mcriscolo 47 Posting Whiz in Training

You could use the "Startup" folder for a user. Be aware that folder will be at different locations based on the OS being used (XP, Vista, Windows 7, etc.)

However, even though your scripts are written in C#, you may get more answers if you post this in the "Microsoft Windows" forum.

mcriscolo 47 Posting Whiz in Training

Good point, you can specify an IP address for the server manually (like was done in the example), or, you can use this syntax:

m_IpEndPointLocal = new IPEndPoint(IPAddress.Any, 5000);

This would cause the default adapter to be used. To your point, if your machine has more than one network adapter, then by specifying the IP address manually, you can "nail down" the socket to a specific adapter.

mcriscolo 47 Posting Whiz in Training

Yep, that's pretty much it.

mcriscolo 47 Posting Whiz in Training

The .NET Framework, in conjunction with Visual Studio has a facility to generate a proxy class for a WSDL-based SOAP web service. First, can you reference the WSDL of the service? You should be able to get to it with HTTP syntax like: http://www.somesite.com/someservice?WSDL That will differ from site to site, but if you can get to the WSDL, the tool in Visual Studio will be able to generate the proxy class.

Then, in Visual Studio, in your Solution Explorer, you should see an item labled "References". Right-click and a menu will appear, with an option for "Add Web Reference...". It is in here that you will use the URL to the WSDL of the site in question. Once the proxy class is generated, you should see methods in the class that correspond to the functions of the web service.

mcriscolo 47 Posting Whiz in Training

You will want to research the .NET "Process" class. This class encapsulates many methods to handle starting and stopping processes.

mcriscolo 47 Posting Whiz in Training

I'm assuming you mean "UDP".

byte[] data = new byte[1024];
string sData = "<the packet data - fill with what you want>";
IPEndPoint ep = new IPEndPoint("127.0.0.1", 8000); // change to the IP address and port of your server

Socket gameServer = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
data = Encoding.ASCII.GetBytes(sData);
gameServer.SendTo(data, data.Length, SocketFlags.None, ep);

Of course, there are all sorts of things that can go wrong - you need to put in exception handling to make sure you catch any issues.

Now, if your data is not string data and is already binary, well, you can just serialize the data into the byte array and send it along.

mcriscolo 47 Posting Whiz in Training

Well, first, is this program the client or the server? To really run it with two processes, you'll want one program to be the client, and another to be the server.

The server program should execute the Bind, Listen and Accept; while the client program executes the Connect method to connect to the server program. You appear to be doing both in the same program. You can actually do that...

In the server program, you need a local Socket object to perform the Bind and Listen. You also perform the Accept (this is where the server "comes alive" when a remote client connects to it), and the return value from the Accept is *another* socket - the socket to the remote client that just connected. The original socket can then go back to the Listen and wait for another client to connect.

When you have the programs separated, execute the server program first, then execute the client. If coded correctly, the client will connect up and you will be able to pass data back and forth.

Client:

m_IpEndPointForeign = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 5000);

m_SocketForeign = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
m_SocketForeign.Connect(m_IpEndPointForeign);

m_Stream = new NetworkStream(m_SocketForeign);

// Read & Write operations
m_Stream.Write(...);  // Implementation left to you...

m_Stream.Close();
m_SocketForeign.Shutdown(SocketShutdown.Both);
m_SocketForeign.Close();

Server:

m_IpEndPointLocal = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 5000);

m_SocketLocal = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

m_SocketLocal.Bind(m_IpEndPointLocal);
m_SocketLocal.Listen(10);
Socket m_SocketClient = m_SocketLocal.Accept();

m_Stream = new NetworkStream(m_SocketClient);

// Read & Write operations
m_Stream.Read();   // Actual Read() implementation left to coder...

m_Stream.Close();
m_SocketClient.Shutdown(SocketShutdown.Both); …
mcriscolo 47 Posting Whiz in Training

You need to define your "System" class like you did the other two; a header file to declare the class, and an implementation file to define the methods of the class. Your methods for "System" then need to be implemented like:

void System::Menu()
{
   // Code
}

string System::convertUp(string& lower)
{
   // Code
}

etc.

mcriscolo 47 Posting Whiz in Training

First, when you say "method isn't fired at all" - are you talking about the timer, or the method the timer is supposed to call? Can you validate that at least the timer is firing?

Also, do all of the machines have the same version of the .NET Framework, with all patches/updates installed?

mcriscolo 47 Posting Whiz in Training

In your case, you haven't done anything with the IPEndPoint instance, so it depends.

If you want to connect to a remote client (the rest of your code appears as such), you need to issue the "Connect" call from the socket, using the IPEndPoint instance:

m_socket.Connect(m_IpEndPoint);

right after line 3 in your post (of course, you will also put this into a try/catch block in case of exceptions). This will connect your program to the end point described by host IP "127.0.0.71", on port "5000" (which answers your question - in this case, it's a foreign - or remote - address).

Now, the IPEndPoint can refer to a local address and port, if you were to do something like this, after line 3 in your code:

m_socket.Bind(m_IpEndPoint);
m_socket.Listen(10);
Socket m_client = m_socket.Accept();

assuming your machine's IP address is "127.0.0.71", this code would set up a listen on port 5000 so other programs could establish a connection to this process (again, you will enclose this code in a try/catch block to grab any exceptions). You would have to change the rest of your code to use "m_client", as this will be the object pointing to the socket a remote client would actually be "attached" to, for you to perform your reads/writes.

mcriscolo 47 Posting Whiz in Training

You then use:

printf("%4.3f", myFloatVar);

But note that if the value in "myFloatVar" has 2 digits left of the decimal, you'll get those two, along with the 3 past the decimal.