mcriscolo 47 Posting Whiz in Training

Check out this part of your code:

...
bool radioButton1_CheckedChanged = true;
bool convertToCelsius_CheckChanged = true;

if (radioButton1_CheckedChanged == true)
{
    convToF(double.Parse(Current.Text)); 
...

Won't this always be the case...? Should the first 2 statements be moved elsewhere?

mcriscolo 47 Posting Whiz in Training

OK, I didn't see a class declaration in the post; perhaps it got left out.

A while loop loops while the condition in the parentheses is true. So, "while(1)" will loop forever. However, in the example I posted, if the user types a "q" or "Q", it will call "System.exit(0)", and end the program. You can have code like this, just as long as you be sure to break out of the loop somehow, either using the "break" statement:

while(1)
{
    if (a.equalsIgnoreCase("q"))
    {
        break;
    }
}

// execution will continue here..

or, as was done in my previous post, calling "System.exit(0)".

mcriscolo 47 Posting Whiz in Training

I don't see a class declaration at the top of the code. It should be just before your first curly brace ({) at the top. Something like:

public class Teller

When I put that in, the code ran.

You really should have one outer loop that takes in the user's input, then compares it to your menu choices. In your example, you show the choices, get the user's choice, then after the operation (in this case, a balance inquiry), you enter a loop to get the user's next choice. With one big loop running the entire program, when you are done with an operation (balance, deposit, etc.), you just go back to the top of the loop and get the next choice. Something like:

// Do this until the user presses "q" or "Q"
while (1)
{
	// Get choice
	String a =(JOptionPane.showInputDialog(null, "Automatic Teller Machine\n [B] Balance Inquiry\n [D]Deposit\n [W] Withdrawal\n [Q] Quit\n Select you Options:  ","Automatic Teller Machine",JOptionPane.PLAIN_MESSAGE));

	// Exit?
	if(a.equalsIgnoreCase("q"))
	{
                // Do exit stuff...
		System.exit(0);
	}

	// Balance
	if(a.equalsIgnoreCase("b"))
	{
		// Do balance stuff...
	}

	// Deposit
	if(a.equalsIgnoreCase("d"))
	{
		// Do deposit stuff...
	}

//end of main loop
}
mcriscolo 47 Posting Whiz in Training

Ah, but they don't have the same *values* - you are constructing arrays of *objects*. Now, the objects may contain the same values, but that's it. Each object is different. You can either change over and make the arrays out of integers, or provide a comparison function that, when you go to compare the arrays, checks each element and compares the values contained in each object at each position.

Your commented-out function in the first chunk of code was almost correct - if you change that to call your "getInt()" property on each object in the arrays, you should have it.

mcriscolo 47 Posting Whiz in Training

You can't declare an instance of a variable more than once. That's what's happening. Try this:

// Secondary.h
#ifndef SECONDARY_H
#define SECONDARY_H

#include <iostream>
using namespace std;
#include <string.h>
extern string HelloWorld;

void HelloEarth();

#endif

Change Main.cpp and Secondary.cpp to include "Secondary.h", remove the function declaration of "HelloEarth" from Main.h, and remove the include for Main.h in Secondary.cpp. This allows you to declare the variable once in Main.h, and reference it from other places.

Chuckleluck commented: Got straight to the point and showed me what was wrong with my code +2
mcriscolo 47 Posting Whiz in Training

In Panel.java, as the new last line of the constructor, type this:

ingredientScroll.setPreferredSize(new Dimension(200, 100));

Of course, you may want to interrogate the parent (Frame) to get the dimensions and set the size of the JScrollPane appropriately.

mcriscolo 47 Posting Whiz in Training

Your code is "converting" the object at element position 0 (an instance of MyDataType) to a string - but since it's an object, you are getting the type name.

I'm assuming you want "nut" to appear in the text box. If so, the code that does this is:

textBox1->AppendText(arrayObject[0]->name);

If you add a "toString" method to your "MyDataType" class, you could change your code to:

textBox1->AppendText(arrayObject[0]->toString());

Assuming, of course, that your "toString()" method returns a string with the data contained in the "^name" property.

mcriscolo 47 Posting Whiz in Training

Sounds like you need something like a "MultiMap". Check out this link.

mcriscolo 47 Posting Whiz in Training

How else would you? I mean, are you looking to load each "Student" into some sort of object, and then be able to say something like:

if (firstPerson.Age == secondPerson.Age)
{
    ...
}

If so, you will still have to process the XML to load the objects.

mcriscolo 47 Posting Whiz in Training

Have you seen this article? (Not sure what the goofy photos are all about). Seems to cover some of the basic aspects of working with table adapters. It's in VB.NET, but should be easily translated to C#.

mcriscolo 47 Posting Whiz in Training

"~" in Windows won't work (unless you are doing this in Mono, on Linux?)

In the framework, there is an enumeration of "special folders", the items like "My Documents", "MyPictures", etc. You use it like this:

Console.WriteLine("GetFolderPath: {0}",               Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));

Check out the doc - there may be something here for you to use, when you don't know the structure of the the target computer you are going to install your software onto.

http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx

mcriscolo 47 Posting Whiz in Training

Well, that's because you can only send one "piece" of data through when you start the drag. May be a bit of overkill, but can you do this in "button1_MouseDown":

button1.DoDragDrop(button1, DragDropEffects.Copy);

Then, in "button2_DragDrop":

Button oButton = (Button)(e.Data.GetData(typeof(Button)));

Now, you have a reference to button1, and all of the props within it.

mcriscolo 47 Posting Whiz in Training

When you specify a path in a string in code that contains the backslash character, you must "escape" it. So, if you want to save a file named "gunk.txt" to the root of the C: drive, you would have to type:

string sPath = "C:\\gunk.txt";

That will be suitable for using in a function that takes a file/path string.

mcriscolo 47 Posting Whiz in Training

Sounds like a plan. One class per command keeps it straightforward. Good luck!

mcriscolo 47 Posting Whiz in Training

Your deletion routine is not correct - you are leaving the pointer from the previous entry in the list dangling. Example: if you enter the values 3, 2, 1 in your list, you will have a list in order from head of 1 - 2 - 3.

When you go to remove the even numbers, you will start at 1 (head) and see that it doesn't need to be removed, so you move to 2. That should be removed. You set "step" to point to the 3, then remove the 2 - but the pointer from 1 - it's still pointing to where 2 was (it has an address in it, though it is invalid).

One way to do it is to have a "trailing" pointer (call it "prev") and set it to NULL. Each time you increment "step" WITHOUT deleting a node, you set "prev" equal to "step" BEFORE you increment "step". Then in the deletion logic, you set "prev->next" equal to "step->next", so the pointer from the previous node now points to the node after the one just deleted.

mcriscolo 47 Posting Whiz in Training

You can trap the "ClientSizeChanged" event on the RichTextBox. In both cases (when the scrollbar appears and disappears), this event will fire.

Momerath commented: My example came from your statement so you deserve credit +3
mcriscolo 47 Posting Whiz in Training

Not at all. However, when you talk about "serializing", I'm assuming that you mean a good chunk of the discussion we've had in this thread, not necessarily the .NET version of serialization. First, I'm not as familiar with that, as I've stated earlier, but I feel certain that you can do that over a socket (any stream, for that matter).

The approach I've used is a custom serialization process. I wouldn't be able to use .NET serialization, since I have UNIX processes as some of the endpoints, and didn't want to have to "invent" the serializer/deserializer on that platform, or perhaps, attempt to use Mono or something like that (OK, the real truth is the UNIX side of the software was written before .NET was even invented). It works for me, and should work in most applications where you're having to send data over sockets to various processes.

As far as size is concerned, you'll have to do some tests to see how large your objects are and determine if that's the best approach. However, how else would you do it? If you have to get the data to a process on another machine, it's going over the network somehow - either directly, via your soon-to-be-developed solution, or via FTP/SCP/Samba/E-Mail - i.e., file transfer - but one way or another, the data's got to get there.

Start small, run some tests and see what results you get. Hopefully, you can gather enough data to help make a …

mcriscolo 47 Posting Whiz in Training

All valid concerns. However, at some point, you'll have to get started with things :). I don't think there's a single system I've ever developed where I didn't want to go back and redo some aspect of it after the fact. That "hindsight is 20-20" thing is very prevalent in software development!

All that said, I would suggest going with a more simplistic approach on the messages, rather than a message that would have a whole lot of data in it - and you may only be using a portion of it. That is, I'd treat the network as a precious resource - and only send over data that you know you are going to use. Some may argue that today's networks have tons of bandwidth - and they do - but if you design your software like that you almost always run into trouble later down the road.

Yes, a lot of smaller messages may be more of a management issue, but if you pile everything into one message - and then have to make changes to it - you risk possibly breaking code that was dependent on an earlier version of that message.

Even if you have to send multiple small messages to accomplish a task - that may be better from an "atomicity" (is that a word?) standpoint than sending a larger data package that you have to pick through. Perhaps at a later time, if you find that for a certain transaction, you …

mcriscolo 47 Posting Whiz in Training

Alan,

The byte array has its own length. This works:

for (int i = 0; i < baData.Length; i++)
{
    byte bByte = baData[i];
    // Do something with "bByte"
}

but so does this:

foreach (byte bByte in baData)
{
    // do something with bByte
}

It just depends if you need the location in the array; if so, then the first approach is better.

Use the "Length" property on the byte arrays to ensure you don't try to grab an element that's not there.

but I am getting error statements that indicate that the program doesn't know where the arrays are

Are you talking about using the "baData" and "baAnswer" arrays in another part of your program? If so, you need to make sure that from a scoping standpoint, you can "see" those variables. In other words, let's say you have another class, called "Analyze", that operates on the two arrays. If you just declare the class "Analyze", like this:

public class Analyze
{
    public void doAnalysis()
    {
        for (int i = 0; i < baData.Length; i++)
        {
            byte bByte = baData[i];
            // Do something with "bByte"
        }
    }
}

That won't work - the "Analyze" class doesn't "know" about the byte array in the "Form1" class. You would have to do something like this:

public class Analyze
{
    public void doAnalysis(byte[] testArray)
    {
        for (int i = 0; i < testArray.Length; i++)
        {
            byte bByte = testArray[i];
            // Do something with "bByte" …
mcriscolo 47 Posting Whiz in Training

Here's the code. You will have to put a form up with the names for the textboxes, buttons, etc. to match the names in the code, as well as the events.

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace TestShell
{
    public partial class Form1 : Form
    {
        private byte[] baData;
        private byte[] baAnswer;

        public Form1()
        {
            InitializeComponent();
        }

        private void cmdDataBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (ofd.FileName.Length > 0)
                {
                    txtDataFile.Text = ofd.FileName;
                }
            }
        }

        private void cmdAnswerBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (ofd.FileName.Length > 0)
                {
                    txtAnswerFile.Text = ofd.FileName;
                }
            }
        }

        private void cmdTest_Click(object sender, EventArgs e)
        {
            if (txtAnswerFile.Text.Length == 0 || txtDataFile.Text.Length == 0)
                return;

            // Load up the byte arrays with the data from the files
            try
            {
                baData = File.ReadAllBytes(txtDataFile.Text);
                baAnswer = File.ReadAllBytes(txtAnswerFile.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERROR");
                return;
            }

            // Run the test with the 2 byte arrays
        }
    }
}

You'll need:

3 Buttons (named "cmdDataBrowse", "cmdAnswerBrowse" and "cmdTest")
2 Text Boxes (named "txtDataFile" and "txtAnswerFile")

mcriscolo 47 Posting Whiz in Training

Well, we have a strict policy that new messages go at the end of the list. I don't know how many folks you'll have modding your code, but I'd try to go with something like that.

Strings - you really have to specify a length for each one in your classes. Think of a pure C/C++ struct - you *could* use "char *", but really, the structs will have a field and a defined length, like "char myString[24]".

In C#, you just need to set sizes for each string. I use constants at the top of each class, and in the encode/decode methods, use those constants to set the size of the strings as you put them on and take them off the wire.

mcriscolo 47 Posting Whiz in Training

That's exactly how I do it. I actually have a class that just has the enums in it. We have just over a hundred different commands, so yeah, just trying to remember the IDs would be a hassle.

mcriscolo 47 Posting Whiz in Training

Try this one. I used 7-Zip to zip it, but normally you shouldn't have trouble with it.

mcriscolo 47 Posting Whiz in Training

Is the data in your file actual binary data, or is it hex strings?

I've attached a small shell program that will let you browse for 2 files and convert the contents of the files to a byte array. It assumes the data in the file is binary format (actually, it just reads in the bytes of the supplied file). However, if your data files are text files of hex strings, then the load of the data will not occur properly.

If using hex strings, you will have to read in the data 2 characters at a time and convert each 2-char sequence to a byte value, like this:

string sData = "F2";
byte bData = null;
if (!byte.TryParse(sData, System.Globalization.NumberStyles.AllowHexSpecifier, System.Globalization.CultureInfo.InvariantCulture, out bData))
{
    // Error converting byte data
}

Hope this helps!

mcriscolo 47 Posting Whiz in Training

Attached is some code that implements the base concept. Using the DLL, declare a new class, and have it implement the "IMsg" interface, and subclass the "BaseMsg" class, like so:

public class MyDataMsg : BaseMsg, IMsg

You then implement the "encode" and "decode" methods to put your object's specific data into the data stream. Finally, you use code like this:

byte[] baData = oMsg.encode();

to extract the data for your object as a byte array. You can push this over a socket, write it to a file, etc. When you want to decode it, you read the data into a binary array, then execute code like this:

MyDataMsg oNewMsg = new MyDataMsg();
oNewMsg.decode(byteArrayOfData);

Of course, there are always provisos. When you read the data from a socket, file, etc. - how do you know what type of object it was? The first 8 bytes of the data is the length and the "command id", respecitvely. Both are 4-byte integers, encoded onto the stream in Network (big-endian) format. When you read in the data, you extract the 2 ints, convert them to host format, then examine them to allocate a byte array large enough to hold all of the data, then use the "command id" to allocate the correct descendant of "BaseMsg". Finally, you can call the "decode" method to un-marshal the data and produce a new object with the data intact.

The sample program creates an object, writes it to a file, reads it back into …

mcriscolo 47 Posting Whiz in Training

They will always be there - IF - the corresponding version of the .NET Framework is installed on the target machine.

So, you would not include any of the individual DLLs with your application - you would check to see if the required version of the Framework is installed, and then use the Microsoft redistributable package to install it if needed.

Or, you can make it a prerequisite of your program, and impress upon the user to install the correct version before using your program.

mcriscolo 47 Posting Whiz in Training

Take a look at this post:

http://stackoverflow.com/questions/575977/choosing-between-immutable-objects-and-structs-for-value-objects

Be sure to read the comments under the second post - goes into a lot of detail concerning your question.

mcriscolo 47 Posting Whiz in Training

The main reason you see strings in all of these examples is that strings require the least amount of marshaling to push them across a connection. A string-based protocol is not necessarily a bad implementation; however, if you are in control of the client and server, then you can be a bit more elegant.

You may be able to use .NET object serialization. You declare your class then mark it as [Serializable]. You can then use the BinaryFormatter class to serialize and de-serialize your class to a stream. There are a lot of examples of .NET serialization on the web to examine.

Another approach is to create your own classes that wrap up the details of formatting your data into a byte array suitable for transmission over a socket. You can create a basic object – call it a "NetMsg" object that handles the basics of wrapping a message up into a byte array – for example, every message will probably have a distinct message type and a length. You can then derive a subclass from this class and add the details for the specifics of that type of message. You could have a "SaveDataNetMsg" object, for example. This message would override an “encode” method from the parent that would take the specifics of a “SaveData” message and encode them into a byte array (the base class would take care of encoding the length and the message type).

Once you have the object's data in a byte …

mcriscolo 47 Posting Whiz in Training

Implement each function in it's own class. But the structure of the program would change a bit.

First, create a new .cs file - you will put your function in this file (for example, call it "FirstClass.cs"):

public class FirstClass
{
    public FirstClass()
    {
        // default constructor
    }

    public void doFirstThing()
    {
        int x = 3;
        int y = 5;
        Console.Out.WriteLine("The total is: {0}", (x + y));
    }
}

Then, in your main, you would do this:

FirstClass oFC = new FirstClass();
oFC.doFirstThing();

You can create new .cs files for your other functions, and use the same convention as above to include them and call them in your code.

mcriscolo 47 Posting Whiz in Training

I'm not 100% sure I understand, but what I think you're trying to say is: you have 2 (or 3) programs (console apps), that do all of their stuff in "main()". You need to combine them into one program, so you can run it and it will do all 2 (or 3) things.

If that's the case, first, in each project, create a function and move all of the code from "main" into it. Then, from "main", all you're doing is calling the function that does all of your stuff. Example:

Old way:

class Program
{
    static void Main(string[] args)
    {
       int x = 3;
       int y = 5;
       Console.Out.WriteLine("The total is: {0}", (x + y));
    }
}

New way:

class Program
{
    public void doFirstThing()
    {
       int x = 3;
       int y = 5;
       Console.Out.WriteLine("The total is: {0}", (x + y));
    }

    static void Main(string[] args)
    {
        Program p = new Program();
        p.doFirstThing();
    }
}

Once you have that, you can create a new project that has all 2 (or 3) of your functions in it, then your "Main" looks like this:

static void Main(string[] args)
{
    Program p = new Program();
    p.doFirstThing();
    p.doSecondThing();
    p.doThirdThing();
}

Hope this helps!

mcriscolo 47 Posting Whiz in Training

I ran the program with your data, and lo and behold, I started to get the same results! After looking at it for some time, and monkeying around with the structure, and other things, I happened to look at the top of the program:

fstream inOutPlayer ( "player.txt", ios::in | ios::out );

You're reading and writing data via structs (i.e., binary mode)! So, try this:

fstream inOutPlayer ( "player.txt", ios::in | ios::out | ios::binary );

Your code should work much better.

mcriscolo 47 Posting Whiz in Training

I ran the code in Visual Studio 2010 (full version, not Express), and I'm running Win 7/64-bit.

Here are the steps I went through with my setup:

1) In VS2010, from the "File" menu, select "New | Project"
2) In the box, click on "Visual C++", and in the right-hand side, select "Win32 Project".
3) Type a name for the project and press OK.
4) In the wizard, press "Next >".
5) Change the type to "Console application". Press "Finish".
6) Overlay the code in the main C++ code file (whatever you named the project), with the code from your post.

I just did it again (to write the above steps) and it works fine. I've attached my "players.txt" file - put it where your program can get it and see if you can read it with your version of the code.

mcriscolo 47 Posting Whiz in Training

Instead of separating the fields with spaces, use commas. Then rather than writing to the console, write to a file with a ".CSV" at the end. It's that simple. See this link: http://www.javapractices.com/topic/TopicAction.do?Id=42 for examples of writing to a file.

mcriscolo 47 Posting Whiz in Training

On line 12, you read the first line of the file. When you go into your "while" loop at line 16, you read the file again, thereby destroying the first line you read from the file without processing it. Delete line 12.

Second, when you output your results, it's outside of the "while" loop. The "ResultStr" will have all of the matches for the entire file, with no CR/LFs in them.

1) If the term starting with "52=" is always the end of a "line", then you can add a CR/LF when you put the value into the "ResultStr";
2) Otherwise, move the "Console.WriteLine(ResultStr)" into the "while" loop, and after you print it, clear the contents of "ResultStr", so you are ready to process the next line.

mcriscolo 47 Posting Whiz in Training

I copied your code down and compiled it; it seems to work fine for me. I added 3 players, and I can run the code and display all three just fine. I stopped the program and ran it again, and all of my data was still intact.

I did have to make some changes to get your code to compile. It looks like a windows console app; but it was attempting to include "stdafx.h", as well as it had the "_tmain" entry point, and "_TCHAR* as the type for "argv"; I removed all of these, replacing them with "main" and "char *", and compiled it as a straight C++ console app.

I then created a new Win32 project, and in the wizard stated I wanted it to be a console app, and was able to get your code to compile straight from your submission.

In both cases, the program ran fine. I copied the data file from the first project to the second, and was able to successfully browse the data.

Structurally, the code appears to be fine. Couple of notes:

1) the program just quits if it can't load "players.txt". You could just create a new, empty file in that case, instead of making me do it ;)
2) I'm a baseball fan, but not a huge baseball *stats* fan, so, in the code when you ask when a player is a pitcher, catcher, etc. - are these mutually exclusive, or can a …

mcriscolo 47 Posting Whiz in Training

Can't say if one is better than the other - I suppose it just gives the developer the flexibility of choosing a method based on the data he/she has in-hand. Methods 1 & 2 are closely related to each other (build an object and hand it in via a single "Add" call), while 3 & 4 are closely related (use indexes/iterate the collection to insert at a given location).

Of course, there is also the ability to load an entire data set into a DGV in one shot:

private void AddMethod5()
{
    dataGridView1.Columns.Clear();  // Remove the defined columns from the DGV

    DataTable dt = new DataTable();
    DataRow dr = dt.NewRow();
    for (int i = 0; i < 3; i++)
    {
        dt.Columns.Add("Column" + i.ToString(), typeof(String));
        dr["Column" + i.ToString()] = "RowCell" + i.ToString();
    }
    dt.Rows.Add(dr);
    dataGridView1.DataSource = dt;
}

At this point, I'm not truly in the spirit of what you originally proposed:

...adding a row to a DataGridView consisting of textboxes.

This is using the DGV as a viewing mechanism on a separate data source. As the comment indicates, it removes any column definitions in the DGV. But, it *is* yet another way to get a DGV to display data. And, of course, there are a lot of different ways to construct data sets/tables - from a database, from code, etc...

A lot of ways to skin the proverbial cat.

mcriscolo 47 Posting Whiz in Training

Try this:

// Convert &lt; &gt; etc. to HTML
String sResult = HttpUtility.HtmlDecode(sData);
// Remove HTML tags delimited by <>
String result = Regex.Replace(sResult, @"<[^>]*>", String.Empty);

If you are using a .NET Forms app, you will have to specifically reference "System.web" in order to get your hands on "HttpUtility". "Regex" is in "System.Text.RegularExpressions".

mcriscolo 47 Posting Whiz in Training

In the message, your excerpt from your "sample.log" file seems messed up. What are the field separators? Are they commas, or tabs, or something else?

Assuming they are commas or tabs, you need to split the string that you read in on that delimiter. See this post on how to do that.

Once you have them in an array of strings, you can select the ones you want.

mcriscolo 47 Posting Whiz in Training

Take the "ios::app" option out of your open statement. It's forcing all the writes to go to the end of the file (for adds that's OK, but when you delete or modify a record, it's actually writing them to the end of the stream). Once you do that, it should work a lot better.

mcriscolo 47 Posting Whiz in Training

Just make a new instance of the "Service1SoapClient", like this:

Service1SoapClient myWS = new Service1SoapClient();

Then, you should see your methods on the "myWS" variable:

string sResult = myWS.CelsiusToFahrenheit("25");

You may have to include the namespace, if you did not put it in the "using" section:

ServiceReference1.Service1SoapClient myWS = new ServiceReference1.Service1SoapClient();

However, after you have instantiated the class, you can call the methods on it.

mcriscolo 47 Posting Whiz in Training

Your seekg positioning is off. When you add records, you use:

fio.write((char*)(&t1), sizeof(t1));
    fio.write((char*)(&active), sizeof(active));

but when you look for records in your modify and delete, you use:

fio.seekg((number + 1) * sizeof(t1));

all well and good, but you are not accounting for the 1 byte boolean (active) that you write at the end of each record. Your seek code should look like:

fio.seekg((number + 1) * (sizeof(t1) + sizeof(active)));

You might consider moving the "active" flag inside your tool class - then your calculations work.

Some other things - the "tool" instance you pass into your getInput method is useless (other than to calculate the size of the tool object) - also the calculation is incorrect here, as well. You can use "sizeof(tool) + sizeof(boolean)".

Your "getInput" method - when you add a new record (when "modify" is false) - what happens when I add 2 records, and I type in a record number of "1" for both? It appears that I will overwrite the first record with the second. An add operation should seek to EOF and add there.

That should be enough to get you going.

mcriscolo 47 Posting Whiz in Training

Really? I ran this and I got 0x01. Here's the code (Eclipse Helios on Windows 7):

public class ArrayRefTest 
{
	public ArrayRefTest()
	{
		//Default Constructor
	}
	
	public static void main(String[] args)
	{
		ArrayRefTest a = new ArrayRefTest();
		a.foo();
	}
	
	public void ChangePrimitiveArray(byte bytes[])
	{
	    bytes[0] = 1;
	}

	public void foo()
	{
	    byte bytes[] = new byte[2];
	    bytes[0] = 4;
	    ChangePrimitiveArray(bytes);

	    System.out.printf("bytes[0]=0x%02x\n", bytes[0]);
	}
}

Check this out:

http://www.javacoffeebreak.com/faq/faq0066.html

VernonDozier commented: Thanks. +13
mcriscolo 47 Posting Whiz in Training

Are you checking the contents of the output file while the program is still running? Normally, when the file is closed (either explicitly, or when the object is disposed and the GC cleans it up), the buffers will be flushed.

If you want to check the status of your output file while the program is still running (e.g., you have a long-running process that's, say, writing a log file), then you will want to call "Flush" on the stream to push the data onto the disk.

A lot of things can affect when the data from a stream is actually written to the file (how long the process runs, how much data you are writing, etc.)

Does one program write more data than the other? A stream has a buffer, that, when it fills up, will be flushed to the disk. If one program is not writing a lot of stuff and you check it while still running, your file may be empty.

kvprajapati commented: Good point. +11
mcriscolo 47 Posting Whiz in Training

Depending on the complexity of the task, I can think of 2 ways off the top of my head:

1) Write a C# process that does your check and updates the required tables (most likely a Windows Console application). Set it up to run on your server as a Windows Scheduled Task, in the interval you need to check.

2) Develop a database procedure (e.g., in SQL Server, a stored procedure) that does your check and update. Set up a scheduled database job that runs your procedure.

Hope this helps!

mcriscolo 47 Posting Whiz in Training

First, that semicolon on line 8 (between the end of your method implementation and the curly brace) is going to be a problem....

"blabla.date" is "const char *". So, one of 2 things: either cast the return value as (char *), so it will match the method prototype:

return (char *)blabla.date;

or, change the method prototype to return a type of "const char *":

class Bla{
private:
   char date[9];
public:
   const char* ReturnDate(const Bla& blabla);
};

const char* Bla::ReturnDate(const Bla& blabla){
   return blabla.date;
}
mcriscolo 47 Posting Whiz in Training

Knowing nothing more about your code that what you wrote, an extremely high-level solution could look like:

1) Convert your main() function to C# in a new C# Console Application project.
2) Create a new C++ "Class Library" project.
3) Copy all of your C++ code, minus the main() function, into the new project.
4) Attempt to build the C++ library.
5) In your C# project, set a reference to the new C++ Class Library.
6) Run the C# program and see what happens.

Again, that's extremely high-level, and discounts any possible non-portable constructs that may be in the C++ code that will have to be modified/rewritten to work with the CLI. It also assumes that the main() function in your current C++ program is relatively straightforward and can be converted to C# easily.

That's the way I'd start out, at least.

Good luck!

jonsca commented: Good suggestions. +6
pseudorandom21 commented: Helpful, and interesting post. +0
mcriscolo 47 Posting Whiz in Training

Here is a link that describes a situation similar to yours:

http://www.dotnet4all.com/dotnet-code/2004/12/serialization-headaches.html

The poster suggests that perhaps you develop a separate assembly (DLL) that does all of the serialization/de-serialization. Then call that from your CreateData and ReadData programs.

If you examine the contents of "DataFile.dat" in an editor capable of viewing hex, you can see that the "CreateData" assembly is tagged to the data in file. When your ReadData program comes along and attempts to read the data, you get the error.

One assembly that reads and writes the data would alleviate that issue.

Hope this helps.

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

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.