Ketsuekiame 860 Master Poster Featured Poster

It might be a bit extreme, but where you set isFinished, could you just return; and exit the method?

Otherwise, you will need a second boolean check.

if (!isFinished)
            {
                // If the level has arrived at the current destination node and not at the final node
                // Destination node is based on the interpolated points on the spline
                if (AtNode(catmullRomSpline.InterpolatedPoints[nodeIndex], node))
                {
                    // If we have not reached the final node/interpolated point on spline
                    if (nodeIndex + 1 < catmullRomSpline.InterpolatedPoints.Count)
                    {
                        // Increase the node index
                        nodeIndex++;
                    }
                    else
                    {
                        return;
                    }
                }

                // Now move object unless finished is true

or;

if (!isFinished)
            {
                // If the level has arrived at the current destination node and not at the final node
                // Destination node is based on the interpolated points on the spline
                if (AtNode(catmullRomSpline.InterpolatedPoints[nodeIndex], node))
                {
                    // If we have not reached the final node/interpolated point on spline
                    if (nodeIndex + 1 < catmullRomSpline.InterpolatedPoints.Count)
                    {
                        // Increase the node index
                        nodeIndex++;
                    }
                    else
                    {
                        isFinished = true;
                    }
                }

                // Now move object unless finished is true
                if(!isFinished)
                {
                   // Do Stuff
                }
            }

You have a check for "isFinished" up at the top also, is this necessary? I don't know how you're handling things outside this local block so I can't say for certain, but if you thought it may exit immediately once isFinished becomes true inside the block, that is incorrect.

Geekitygeek commented: covers both the solutions i would have offered..good post :) +1
Ketsuekiame 860 Master Poster Featured Poster

Good, don't =)

But if that's true why did you repost it? :P

Ketsuekiame 860 Master Poster Featured Poster

1. Your code is badly formed and partially incorrect.

2. We are not here to solve threads as quickly as possible or to rack up a huge "Thread Solved" count on our profiles. We are here to help inexperienced developers learn how to improve their code and problem solve better. Also, to use our experience to help them learn advanced functionality (Remember having to learn how to implement Threading by yourself?)

3. Feeding code to people who show little or no effort, do not learn. Also, you are assisting in plagiarism. I know several University lecturers in the UK who read Daniweb for such an occurrence. I cannot say for sure about other countries but I imagine some do. Therefore, handing out code is liable to make them fail, or worse, be kicked off the course.

As for the OP: Firstly, if you do not know how to calculate the area of a square, use Google. It's very simple.
Secondly, I imagine it has not been thoroughly explained because it is a very simple task. The only place you would really fall down on are the input and error checking.
In cases like this one, you should really talk to your professor first as they're the ones most likely to give you the best help.

Nick Evan commented: Good +15
jonsca commented: Seconded +4
Ketsuekiame 860 Master Poster Featured Poster

EDIT: Deleted the original question. After reading, I realised that I would have to paste so much additional code that it would take someone a couple of days just to understand what was happening in my own code that it may detract from the issue at hand.

Problem: When I add an object to a collection (many-to-many relationship) the object is saved and committed to the database. However, if I then try and retrieve that object somewhere else (on a different thread) the object state is incorrect and the collection does not contain the recently added item.

Checking the database shows that the item has been added successfully.

Does anyone know what would cause NHibernate to do this? Googling revealed that it's generally a problem with not having an Inverse relationship. However, I've tried with and without and inverse map and the problem still occurs.

Also, the problem ONLY occurs if I attempt to retrieve data from a different object/method than the one that originally saved the data.

I would post code, but it really wouldn't be helpful and I would have to post about 1,000+ lines just so that you could get the context. (The Domain Objects, the Interfaces, the NHibernate Data Access Objects, the Service Code, the Test Code etc.)

There is a lot ^^

Ketsuekiame 860 Master Poster Featured Poster

The above link has everything you need. But it needs an active internet connection.

Alternatively store your text strings in a resource file and use localisation.


No I will not give you instructions/code on how to do it. You probably looked at the above link thought "too much effort" and asked for code. This site isn't a code factory for lazy programmers.

kvprajapati commented: Words!!! +10
Ketsuekiame 860 Master Poster Featured Poster
Nick Evan commented: What's this thing? Google? Never heard of it +13
Ketsuekiame 860 Master Poster Featured Poster

Personally I would continue to learn the unmanaged C++ as this is a more general language (and can be applied to Linux/Unix/Windows)

C++ .net (or managed C++) is, in my opinion, verging on pointless. C# is simpler and quicker (to code) than Managed C++. With the ability for C# to use Platform Invoke (P/Invoke) you have access to the Win32 API and unmanaged code.

If I were you, and remember this is personal opinion I would continue to use C++ (unmanaged) and also begin to learn C#. If you later need to learn Managed C++ it will be much easier, but rarely used.

The way in which I would do the above is to first write a program in C++ and then translate it to C# or vice-versa.

In response to your wanting to use OpenGL. Even if you wanted to use OpenGL in Managed C++ you would need to use the managed libraries (TaoGL), or, create a Managed to Unmanaged proxy so you could use unamanged OpenGL in unmanaged code.But this would also work equally well with C#. Also, Microsoft has a very powerful (and fast) Managed DirectX SDK and the XNA Game Developer Framework.

Tl;Dr - Stick with plain C++ and begin learning C#. In the rare case you may ever need Managed C++, learn it then.

jonsca commented: Agreed +4
Ketsuekiame 860 Master Poster Featured Poster

SerialNo=@TextBox41 You haven't added the parameter for TextBox41.

This is very bad coding form by the way. Please name your controls, variables and methods so that people who look at your code can tell what it supposed to be happening at a glance.

Lusiphur commented: good catch!! +1
Ketsuekiame 860 Master Poster Featured Poster
nick.crane commented: Nice +1
Ketsuekiame 860 Master Poster Featured Poster

Well you will need an application running on the target machine.

This app needs to get the details of all the current running processes. What you may actually want to do is get a list of the current open windows. Unfortunately the computer cannot distinguish between a normal app and say winlogon.exe.

As for locking the computer, you need to make a modal window, that's full screen and can only be closed with a certain keycode. Unfortunately control alt delete will still be in effect, unless you write a keyboard filter driver to intercept the keypress.

Note: Any attempt to block, capture or redirect keyboard input WILL be flagged by most anti-virus software as a virus/trojan.

Have fun :)

Ketsuekiame 860 Master Poster Featured Poster

<< I'm using Visual Studio 2008 C++

From the Visual Studio's menu, can you find an option titled
Debug / Exceptions

If you can, then select it, and in the dialog box that opens, select the option;

Win32 Exceptions
..... c0000005 access violation

(I'm looking at VS 2005 at the moment, so your GUI may be different)

After that, just run the game in the debugger and once the access violation occurs, you should be able to locate the code that's causing the exception. See how it goes.

The debugger itself in 2K8 and onwards will give you the line the exception is thrown on and the stack trace will show you what's been called up to that point.

The problem, in my opinion, is that his pointer is either A) Being re-assigned, B) Being over-written C) Has a pointer overlap problem where something else has partially over-written the memory.

I'm not 100% sure but looking at the thread that's the only explanation I can think of as people have tried most of everything else.

mitrmkar commented: A good catch. +5
Ketsuekiame 860 Master Poster Featured Poster

It looks fine so far, but you may want to create a semaphore or look into using CriticalSections.

At the moment you're waiting for a thread to exit. You need to wait for a thread to signal. Using a mutex is one way, but I wouldn't go that way. Using CriticalSections or Creating Semaphores is another way which I think would be more applicable to you.

Here's a bunch of Synchronisation Functions that are available in the Windows API

Two important ones are Here and Here

nbaztec commented: :) +1
Ketsuekiame 860 Master Poster Featured Poster

I refrain from using C as it puts it in the local culture currency. It's very easy to forget to switch cultures ^^

I use #,##0.00 with the correct currency symbol for whichever currency it is.

Typically though, you are correct, and you should format with 'C' and the correct culture.

ddanbe commented: Very well +6
Ketsuekiame 860 Master Poster Featured Poster

It's good practise in cases like these to keep your DomainObjects (for example a Person would be a DomainObject) and your DataAccessObjects separated.

So I could have a PersonDao and this class has a "GetById(int id)" method. So I can call PersonDao.GetbyId(25) and it will pull back that person for me.

The great thing about DAOs are that you can then implement GetBy<Whatever> and include functionality for that.

The Design pattern is good, but how you implement it will be different :)

DAO Design Pattern

(Separation will remove a lot of the circular dependency you talked about, which is why I'm mentioning it :))

Ketsuekiame 860 Master Poster Featured Poster
Ketsuekiame 860 Master Poster Featured Poster

Ok what you need to do is at the beginning of the header file for one of the classes. You need to declare that there "will be a class of this type". You then drop the include for that class from the file.

So take HClass1:

#ifndef _HEADER1
#define _HEADER1


namespace HNamespace
{
        class HClass2;

	class HClass1
	{
		public:
			HClass1()
			{
				
			}
			
			~HClass1()
			{
				
			}
			
		HClass2 * A;
		
	};
}

#endif

You can then leave your HClass2 file as it is.

Edit: You need to make sure your HClass2 file is included somewhere else in the program

Ketsuekiame 860 Master Poster Featured Poster

@AncientDragon: Yeah you can, but that's not the problem here if I saw correctly.

@Op: You need to create a Solution and a Project for that file. You cannot compile individual files like you would in say gcc.

Goto File, Create new project, it will automatically create a solution for that project. Just make an empty console project. Once that's done, right click the project, then click Add Existing Item...
Go find your file, select it and click Add.

You can then build your file :)

Ancient Dragon commented: nice catch :) +28
Nick Evan commented: Haha, I totally missed that :) +13
Ketsuekiame 860 Master Poster Featured Poster
Ketsuekiame 860 Master Poster Featured Poster

If you can't answer this question yourself, stop now, before it's too late.

Alternatively, Google

Ketsuekiame 860 Master Poster Featured Poster

I have not used this API either. However in your callback you are trying to change the forms Text property.
The callback is probably executing on a sepearte thread to the UI and thus causing a problem.
As this is just a test program try using Debug.Write or Console write methods instead.
Normaly you should invoke the UI delegate to set UI control values.

I've told him to do that already.

However, if his app is crashing exactly when he calls hook.StartHook(); then there is a high probability something is going wrong with the API.

To eliminate the possibility you should change your Text update to an Invoke. this.Invoke(new MethodInvoker(delegate { //Change Text Here })); should do fine

Ketsuekiame 860 Master Poster Featured Poster
Ancient Dragon commented: ++ +28
Ketsuekiame 860 Master Poster Featured Poster

You really don't want to use hooks unless they are absolutely necessary.

The Windows.Forms class actually allows you to override the WndProc message pump. So all messages sent to that window can be intercepted.

The signature is protected override void WndProc(ref Message msg) You can get the message code from msg.Msg the WM_* codes can be found at pinvoke.net

After you have processed the message, please end the method with base.WndProc(ref msg)

Ketsuekiame 860 Master Poster Featured Poster

Then I would simply ask for a decimal value to begin with. That would reduce your control size to 26 text boxes.

Alternatively, request it in Binary representation and parse that into a decimal. It's pretty much this in reverse.

Another alternative is to have a drop down list/treeview/similar of addresses and 8 check boxes. Select the address you wish to set, then enable the checkboxes. Disable them after the data for that address has been sent/saved. This way you can get and set the values on the same 8 check boxes.

Ketsuekiame 860 Master Poster Featured Poster

Ah ok I know what you want now but I'm going home in about 2 minutes...

Basically you need a recursive for loop (it may be wise to put it in its own method). You need an outer loop that iterates n times followed by inner loops that iterate vec.size() times.

It can be done but I don't have time to write it all out. I will be home at around 9pm British time. If someone else can do this, please help them =)

Ketsuekiame 860 Master Poster Featured Poster

When you say that you need to add that data to another database, did you actually mean table?

When you use a DataSet you can simply Add new rows onto the end. So... DataSet.Table.Rows.Add(NewRow); will add a new row to that table.

The SqlConnection commands are used when you have another type of data source. You can put SQL Queries to an SQL Connection. They are under the System.Data.SqlClient namespace

Edit: LINQ stands for Language-INtegrated-Query. It's almost like performing SQL commands on objects in your program. LINQ can be used in many situations. For example; let's say I had a List of type MyClass and MyClass has a property called MyInt of Int32. The list is called myList and I wanted to get all the entries that had MyInt set to "15"

var myResults = from resultSet in intList
                where resultSet.MyInt == 15
                select resultSet;

This would return an IEnumerable of type MyClass.

Let's do that again, but this time MyClass has a String type called MyString and I ONLY want the contents of MyString where MyInt is 15.

var myResults = from resultSet in intList
                where resultSet.MyInt == 15
                select resultSet.MyString;

would return an IEnumerable of type String containing all the MyStrings where MyInt was equal to 15.

You can also use it with lamda expressions...

foreach(String myString in myList.Where(s => s.MyInt == 15))
{
   Console.WriteLine(myString);
}

It's very very powerful and extremely flexible.

For example; This Guy …

Ketsuekiame 860 Master Poster Featured Poster

Before launching into the code, you need to decide on a protocol by which your client/server will communicate (and I don't just mean TCP or UDP). Which is exactly the question you've just asked in number one.

This is something only you can decide and it can be anything you want it to be typically (so long as it's feasible) for example. byte 1 = command byte, byte 2 = target length, byte 3 to targetlength + 3 = target etc.

The way you decide to do it is up to you and there's no "right" way to do it. Obviously the wrong way to do it, is to send 4Mb of data for a login command ;)

Number 2 is exactly the same thing. Just decide for yourself how you want to do it.

Ketsuekiame 860 Master Poster Featured Poster

I am not very experienced in programming, but I think you can do this without using any of the functions like atoi(), etc....
Here's what comes to my mind:

1. Input the 'number' in the form of a string
2. for each character in the string, u can check if the ASCII value lies b/w 48(ASCII for character '0') & 57(ASCII for character '9') till you reach '\0' (if the condition is false at any point, u display the error message)
3. Otherwise, it means the user has input an integer. You can simply convert from a string to an integer by something like this:
multiply the character just before '\0' with 1 and store in an int (say int i=0), then the character 2 places before '\0' with 10 (then simply do i+=result), and so on....also note that before multiplying a character with 10,etc. subtract 48 from it....

I think this is simple enough....

Using stringstream is far easier.

1. Load text into stringstream
2. Output text to int type variable
3. Check stringstream fail flag

Ketsuekiame 860 Master Poster Featured Poster

Unfortunately I'm not too heavily into DirectX, but This may help

Unfortunately that's about as helpful as I can be on DirectX ^^

kirennian commented: Problem solved, nice one! :) +1
Ketsuekiame 860 Master Poster Featured Poster

Honestly, Google is your best bet.

Then if you're still stuck and you're using Visual C++ (Visual Studio et al.) then use the MSDN and look up functions specifically.

CPP Reference may be another good place to start

Ketsuekiame 860 Master Poster Featured Poster

Anuragcoder, do you mind if I ask where you're getting all this source code from?

The problems you're having and the questions you're asking don't seem to match with the level of the code you're pasting.

First with the syntax highlighting, then with the press enter twice, now with this network code. Also, I see before you claim to have written a full cashier interface.

These are simple problems and errors that someone of the calibre that can write (or is expected to write) programs of that nature should not be having an issue with.

Ketsuekiame 860 Master Poster Featured Poster

Edit: Moved to PM as off-topic

Ketsuekiame 860 Master Poster Featured Poster

atoi() returns 0 on error. strtol() is the same function but converts it to long int.

If the text length is greater than 1 and the output is 0, that would indicate an error. Unless someone really wanted to put 000 in there or something.

Using stringstream to cast to int will also fail with output of 0 if the characters are not digits. Admittedly, stringstream is the more C++ way to do it.

Ketsuekiame 860 Master Poster Featured Poster

Yes you understood me correctly =)

the Primary Key is indeed unique and should be used to identify each unique row in the table.

So even if you have two rows of identical data, the primary key will be different. Using the primary key, you can select the correct row.

You can do this using the WHERE keyword. SELECT * FROM MyTable WHERE Id = 12; would select all the columns from the table, but only the row where the Id is 12. The Primary Key can be called whatever you want, I just chose Id for that example.

Same goes for UPDATE and DELETE. UPDATE MyTable SET Name = "Bob" WHERE Id = 12 would update the row that has an Id of 12 and set the Name column to "Bob". DELETE FROM MyTable WHERE Id = 12 would delete the row with Id 12 from the table.

So you can do something akin to this;

{
   ... // Code that selects the ListViewItem
   Int32 id = (Int32)lsvItem.Tag;
   String name = lsvItem.SubItems[0];
   String myQuery = String.Format("UPDATE MyTable SET Name = '{0}' WHERE Id = {1}", name, id);
   SqlCommand myCommand = new SqlCommand(myQuery, myDbConnection);
   myCommand.ExecuteNonQuery();
}

Hope that helps.

kvprajapati commented: Helpful! +9
ticktock commented: Very helpful +1
Ketsuekiame 860 Master Poster Featured Poster

Yes

Ketsuekiame 860 Master Poster Featured Poster

Well, as the txt file is non-executing, you will need to decide what program you wish to open it with.

You can then open the programs using CreateProcess using the correct parameters.

If your lecturer didn't know how to do this, I would be worried...

little_grim commented: Gave me a great site for C++ information +0
Ketsuekiame 860 Master Poster Featured Poster

If you have queries make threads. This is a community site so keeping potential help from other people is something I don't agree with =)

To know more from here there's a lot of tutorials on the web that can help you. Or you can get a decent programming book from Amazon or your local shop.

Ketsuekiame 860 Master Poster Featured Poster

Ok I'll give a quick lesson on classes and inheritance.

(This will come in handy for your PHP as PHP5 and above uses classes also)

If we ignore the fancy definitions for a minute and go back to something more common in English.

Think of a class as an object. Something that is sat on your desk (not the C# keyword).
Your keyboard for example. Let's say we want to make a class out of your keyboard

public class MyKeyboard
{
    Keyboard();
}

The empty Keyboard function you see there is the Constructor. At the moment it doesn't do anything, but it gets called whenever you "make" (instantiate) a keyboard.

So consider what your keyboard is like. It has a colour and it has keys.
So we modify the keyboard class to represent this.

public class MyKeyboard
{
    Keyboard();
    public Colour KeyboardColour;
    public List<String> KeyboardKeys = new List<String>();
}

(If you don't know what a list is, it's like an array, but you can make it grow or shrink as you need to)

As you can see we can now assign the keyboard a colour and give it some keys represented as strings ("Q", "W", "E", "End", "Escape" etc)
Things your keyboard HAS are called Properties and are your individual bits of data that describe your class. A person would have the following properties, Name, Age, Height, Job and then some.

Ok so now consider what can you keyboard …

Veneficae commented: Very helpful post, helping me wrap around code that I'm new to. Thanks again! +1
Ketsuekiame 860 Master Poster Featured Poster

Look up strings and their manipulative functions. You should be able to split the string into its separate words and count the result.

Nick Evan commented: Sounds like a plan +12
Ketsuekiame 860 Master Poster Featured Poster

The only thing close is to use Triggers. Triggers are fired on an event you specify. The only problem is they can't connect back to your code.

The only possible combination is to use triggers with a messaging server using plugins that can be found in the UDF Sources. This way the trigger can notify the messaging server and the server can notify your application.

Unless someone has already written one for C#...But I couldn't see one.

Ketsuekiame 860 Master Poster Featured Poster

I would begin by designing something that could become quite large.

I don't mean full scale design though.

For example. I would treat everything as a GameObject where GameObject has some basic data like "Description", "Position" etc and some basic functionality like "PrintDescription", "Push", "Pull" etc.

Then specify more; so if you had a Banana and a Room.

public class Banana : GameObject
{
    // Still have all GameObject methods etc
    StepOn(){ Console.WriteLine("You slipped on a banana!");
}

public class Room : GameObject
{
    // Still have all GameObjects basic stuff
    public WalkNorth();
    public OpenDoor(int doorNumber);
}

etc etc.

This way you can componentise just about every aspect, meaning less repeated code.
(eg. you only have one PrintDescription method rather than 20 with different text in)

I would bear this in mind when you start coding it again =)

Antenka commented: Good job. Stimulating newbies to prevent the coding with desing would save a lots of time :) +2