JasonHippy 739 Practically a Master Poster

Well as far as I understand things, the bigger *nix based open-source companies like Red Hat (makers of Fedora) and Canonical (Ubuntu) make their money from paid technical support.

So for example, a company/business which uses Ubuntu on their systems/servers can pay Canonical a subscription each year, which entitles the company to professional technical support directly from Canonical.

Home users can also pay for support if they want to, but generally most home users will use the free public forums / IRC channels for support. But for companies and businesses, paid support is the best way to go as it ensures a timely and technically accurate response in their time of crisis.

I'm not sure how much their support packages cost, but I'd imagine it would be rather expensive and they must sell a lot of them!
So that's one way, selling technical support for your product.

Another way of making money from an open source project is to set up a paypal donation page so people can donate money directly to the project.

Due to the nature of donations the downside here is; you aren't guaranteed any kind of regular income, if any at all. Many small open-source projects get next to nothing. But if you manage to create something exceptional, which is used by a lot of people and particularly if your software has commercial uses; you could get a lot of donations, which even if only small, could still add up …

JasonHippy 739 Practically a Master Poster

What Salem meant was, have you added mystack.cpp to the project tree in your solution? I'm with Salem here, I strongly suspect you have not!

In Visual Studio, take a look at the solution explorer window and see what files are listed in there. You should have myStack.h listed under "Header Files" and main.cpp and myStack.cpp listed under "Source Files".

If you don't see mystack.cpp listed, right-click the "Source Files" folder in the solution explorer and select "add->existing item", then navigate to the location of mystack.cpp, select the file and hit ok. That will add mystack.cpp to your solution.

Also if you haven't added myStack.h to the list of header files in the project tree of the solution explorer either, you should add that too by right clicking on the "Header Files" folder, select "add->existing item", navigate to the location of the header, select the header file and click OK and that file will also be added to your solution.

Once you've correctly added all of the files to the solution, try re-compiling your project and it should compile without any further linker errors.

Basically the problem was the compiler found the myStack header file, but it didn't know where to look for the actual implementation, i.e. the myStack.cpp file. And it was this that caused the linker errors you were getting.

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

I've used Monodevelop on *nix briefly...And not for anything particularly serious either. More out of morbid curiosity than anything else I suppose.

Primarily I'm a C++ programmer by trade, but as a one-off I did some pretty heavy .NET development in C# a few years ago for one of my previous employers (using VS2005).

Now, I've not done any serious C# development since then, but I'd recently heard about Monodevelop as an alternative IDE for C#. And I've been quite impressed by some of the *nix apps that have been created for the Mono runtime (Tomboy Notes, F-Spot etc.). So I figured "What the hell, let's try it out!".

So I installed it on one of my Ubuntu machines.
After installation, I fired up the Monodevelop IDE and managed to successfully import the VS2005 solution for a multi-monitor screensaver I wrote back when I was learning C# (in preparation for my previous employers big project!). And lo and behold it built and ran with no problems. No modifications whatsoever were needed to the code...Great!

I've since tinkered about, creating a few other random apps and overall the Monodevelop IDE seems to me to be rather well featured. But personally, I don't think Monodevelop is quite as fully featured, or as powerful as Visual Studio. However, it is certainly a very viable, not to mention FREE alternative to Visual Studio.

Definitely worthy of consideration whatever OS you run IMHO! It's great for anybody starting out …

JasonHippy 739 Practically a Master Poster

I would use

Calculate = sum

instead of the above code ;)

Heh heh, good point Gribouillis, that's far better! I completely forgot about sum {slaps forehead!}. That completely eliminates the need for the calculate function and brings the OPs main function down to just 2 lines of code! Well spotted, my hat's off to you sir!

def main():
    myArray=(0,5,10,15,20)
    print "The answer is", sum(myArray)

main()
JasonHippy 739 Practically a Master Poster

When you get to the login screen, will the system allow you to change the default session to Gnome?

If so, simply boot your pc and then when it gets to the login screen, change the default session to Gnome before logging in.
Once you get to the Gnome desktop, as long everything still works properly without crashing or anything, then you should be pretty much sorted.

If you are unable to change the default session to Gnome, or if Gnome is totally borked, perhaps you could try re-installing Gnome. Once Gnome has re-installed, you could then try rebooting and changing the default session to Gnome before logging in. That should sort you out nicely.

Once you know Gnome is OK, you can then uninstall the KDE desktop if you want (or you could leave it in case you decided to go back to it and try it again at some point)!

Otherwise, worst case scenario: Back up all of your personal files and any major customisations you've made (I usually back up custom themes and screensavers I've made and a few other bits 'n bobs as well.) and then re-install Ubuntu. But obviously this is pretty much the last-ditch solution!

Personally I'm not a fan of KDE either! Far too many configuration options to customise the desktop to the way I like it. It also seemed really clunky, unintuitive and slow! I especially hate the main start menu...Yuk! I find Gnome far simpler …

JasonHippy 739 Practically a Master Poster

Are you sure that the code you've posted even compiles??
I've not looked at your code in great detail, but from briefly looking at it I've spotted a few obvious errors that shouldn't allow this code to compile, let alone run and segfault!

For starters there's your misuse of the 'class' keyword in the for loop at line 149. You aren't declaring a class here, you're creating an iterator. I would've expected this line of code to throw a compiler error. Remove the class keyword there, that should solve that problem.

Also at line 371 you're declaring a C-style char array, but it isn't using a constant value. This should be throwing an error at compile time too. Arrays in C/C++ require a fixed value for their size. Variable length arrays cannot be created in this manner. Besides, if you need a variable length array in C++ it is far better to use one of the std::library containers like std::string, std::vector, std::deque which can robustly do their own memory management (so you don't have to!).

In fact, actually looking at your code, you don't really need cval at all:
It's obvious that cval is a C-style char array copy of whatever is stored in val and val is a std::string. And the thing to bear in mind here is that the std::string class has a c_str() member function which returns a C-style char array.

So in other words, you can completely remove cval. Rip …

Ancient Dragon commented: Nice comments +27
JasonHippy 739 Practically a Master Poster

With 'songbird' (i.e. the actual songbird executable, the file with no file extension), have you ensured that it is flagged as executable?
Try right-clicking on it from the desktop or Nautilus, open up the properties and ensure that the tickbox to allow execution is checked.
That may help.

Otherwise open up a terminal, navigate to the location of the songbird executable and try running it from the command line. See what that does. Running from the command line in a terminal should allow you to see any error messages that are thrown in the event that the program exits abnormally. (whereas running from Nautilus/the desktop, you might not see any error messages or any reasons for the programs failure.) Perhaps there are one or more dependencies that are not met, or some other problem.

If the program just fails silently from the command line (i.e. program fails and produces no output), then I guess you're out of luck. Perhaps the best bet in that case would be to contact the songbird developers to try and find out what the problem might be!

I was going to have a go at installing Songbird on one of my Ubuntu machines to see if I could get it working and guide you through the steps required. But after looking at the songbird website and seeing the minimum requirements for songbird, I'm more inclined to stick with VLC and Rhythmbox for my *nix multimedia needs.

But I've found …

JasonHippy 739 Practically a Master Poster

I've not used tinyXML++, but I endured the terrible tutorial in Ancient Dragons link a while ago.
I was looking at it a few months ago and had a bit of a mini nightmare with it! Whoever wrote that piece posted some badly untested code. I couldn't get it to compile on any compiler on any of my machines.
Fortunately a little bit of digging allowed me to work out and solve the problems with it.

To save others from having to suffer what I did, here's something I came up with. It's based loosely around the tutorial/documentation in AD's link. The only difference is, this actually does compile and work!

BTW: I aught to make it clear here, I'm not having a go at AD in this post; but rather the poor quality of the article in the link, which is the original authors fault, not AD's! ;)

I created this example in VS2003 when I was originally trying to get my head around the boost vs XML thing. Apologies if there are any minor non-portable bits of code in there. Most, if not all of it should be pretty standard! It should certainly work with any recent version of Visual studio. I managed to get it working in VS2008 with no modifications to the code.

gcc and any other up to date, standards-compliant compilers should also be able to compile it without error (but I've not tested it with anything other than …

Ancient Dragon commented: Nice -- thanks for not blaiming me for the code in that link :) +26
JasonHippy 739 Practically a Master Poster

Jonsca PM'ed me and brought something to my attention that raises a very good point regarding this thread.

We've both recommended that the OP uses 'new' to create a new instance of the complex class in the operator+, but this would actually cause a memory leak as the memory allocated by new never gets deleted.

After a few messages back and forth, I came up with this solution which should completely avoid a memory leak.... I think!

#include<iostream>

class complex 
{
	float x;
	float y;
	public:
	   complex(){}
	   complex(float real,float imag)
	   {
   		x= real,y=imag;
   	}
  complex operator+(const complex)const;
   	   void display(void);
};
 complex complex::operator+(const complex c)const
 {
	complex temp(*this);
	temp.x+=c.x;
	temp.y+=c.y;
 	 return(temp);
 }
 void complex::display(void)
 {
	 std::cout<<x<<"+j"<<y<<"\n";
 }
 int main()
 {
 	complex c1,c2,c3;
 	c1=complex(2.5f,3.5f);
 	c2=complex(1.6f,2.7f);

 	c3=c2+c1;
	std::cout<<"c1=";c1.display();
	std::cout<<"c2=";c2.display();
	std::cout<<"c3=";c3.display();
 	return 0;
 }

So the major changes there are in the operator+. Instead of returning a pointer or a reference to a complex object, I've changed the signature to return a complex object by value. For the sake of const correctness I've also made the function and the parameter to the function const.

In the operator+ function, instead of creating a pointer to a new complex object, I'm using a temporary local complex object created using the this pointer. Effectively, that makes temp a copy of the left hand operand in the addition operation. We then add the passed in object (the right hand operand in the addition) to temp and return temp by value, so a copy of …

JasonHippy 739 Practically a Master Poster

iam unable to get the appropriate out put for this code.I think the problem is with the operator overloading.Could any one come up with solution??

The main problem I can see is in your operator overload at line 17. The pointer 'temp' is uninitialised, it doesn't point to anything.
You need to use:

complex *temp = new complex();

Which creates a new instance of the complex class and assigns the pointer to point to it. Now your calculation should work.

I also noticed that you're not qualifying the std::namespace for cout. I'm not sure whether or not your compiler needs the qualification, I'm assuming your one of those unfortunate students who've been forced by your institution to use an old borland compiler. It's been donkeys years since I used any of Borlands old compilers, so I really can't remember. But on the off-chance that it does, it might be an idea to put the following line of code underneath the #include:

using std::cout;

(Obviously if you aren't getting error messages about it, your compiler doesn't need it so don't bother!)

Looking at your code, you might also get some warnings about truncation from double to float at lines 29 and 30. (Again, if you're using an old Borland compiler you might not get the warnings. My memory doesn't stretch back that far!)
On the offchance that you are getting warnings, you can get rid of them by doing this:

c1 = complex(2.5f, 3.5f); …
jonsca commented: Above and beyond +2
JasonHippy 739 Practically a Master Poster

Thanks for the help guys. Jason, I will consider saving my code in CS3 next time so you can get a chance to look at it LOL.

Heh heh, bit of a moot point now...Looks like our one and only Windows (XP pro) machine at home has finally given up the ghost and died...I spent many hours last night trying to ressurect the damn thing, but to no avail. Part of the problem appears to be with Windows, a few files used during boot/windows startup have corrupted, looks like one or more of the device drivers have gone a bit wonky. It also looks as though the hard drive has almost completely packed up too (old age!). There are no viruses or malware on there, so no foul play is suspected. I think the corruption is due to the HD's old age.

I managed to get most of our important docs off of it, but as the PC is really old, I'm thinking of perhaps putting a new drive in and slapping linux on there, I've had enough of Windows and the constant need for updates, patches and workarounds!
It noticeably slowed down after service pack 2 was installed on it, and after service pack 3 it was even worse. So I think linux will run a lot better on the tired old thing. We'll be able to get things done a lot faster on it without windows!

So it looks like I'm gonna be doing all …

JasonHippy 739 Practically a Master Poster

I'm afraid I'm out of this one...Looks as though your file was made with CS4 which I don't have! I've got a .swf decompiler on my work pc that should allow me to decompile it to a flash CS3 compatible .fla or pure AS3/flex. I'll have a go at that tomorrow morning, unless raja posts something in the meantime!

Cheers for now,
Jas.

iamthwee commented: Next time I'll compile it for AS3... +11
JasonHippy 739 Practically a Master Poster

That's cool, at least we're making headway.
Do you know exactly which line of your code is throwing the error inside vector?
Try running in debug mode. When the error occurs and you get a message box about the error, select whatever option it is to break out of the program and into the offending line of code, that'll bring you out to the code you've highlighted in vector.

Sorry, I should point out, I've had a few ciders this evening, so I'm not fully compus mentis ATM. so apologies if I'm not entirely coherent in this post!

Anyway next, take a look at the call-stack and it should show you exactly which line of your code was responsible for causing the error to be thrown by the code in vector.

That should make it a lot easier to diagnose the problem.
If it doesn't become immediately apparent to you, then by all means post the details of the offending line of code and we can take a look!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

The answer is pretty simple.

1. Input a number as an int (as you're doing)
2. Cast the number to double in your log calculation and store the result of the calculation in a double variable.
e.g.

double calcVal = log((double)num)/log(2.0);

3. Create an int version of the result from the above calculation.
e.g.

int calcVal2 = (int)calcVal;

4. Subtract the int from the double, leaving you with the decimal remainder. (0.00003454865..or whatever)
e.g.

double decimal = calcVal - calcVal2;

5. Multiply the decimal remainder by something like 100000 or so and store the final value as an int. This will truncate the later decimal places, from the remainder thereby avoiding the inherent problems with floating point arithmetic.
e.g.

int final = (int)(decimal*1000000);

6. If the final value is 0, then your number is a power of two.

Cheers for now,
Jas.

jonsca commented: Nice +2
JasonHippy 739 Practically a Master Poster

Good Afternoon All,

I have a template that I'm working on with the same flash header on each page. The header contains the drop down menu to go to the other HTML pages in which the header is placed. I noticed this as one of the parameter lines

<param name="movie" value="../../../client%20websites/Kingdom%20Coaltion%20International/KCIF%20phase%202/MTech/cugb/header_v8.swf?button=2" />

Can someone explain what I have put in green please? With all the Flash I have seen and worked with this is my first for this.

Thanks for your time and assistance.

To put it very simply, the code you've highlighted in green is the name of the .swf and a parameter that is passed into the .swf.

Something in the actionscript inside the .swf will then use the passed-in value to initialise a variable in the script.

There are several ways of passing parameters to a .swf and this is one of them!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

I've recently been upgraded at work from VS2003 to VS2008 (woo hoo I can finally see inside STL Containers without having to use my own logging class!! :) ).

Visual Studio is a great IDE, the debugging features are second to none, VS2008 is definitely my favourite IDE on Windows.

But I mainly use my *nix laptop for developing at home, so Code::Blocks with gcc/g++ is the order of the day there. Debugging with C::B and gdb can be difficult, but it's worth the effort IMHO.
C::B is really fast to start up and has loads of different built-in project templates, so just like visual studio, you can get a new project up and running pretty quickly.
The wxSmith plugin for C::B is a godsend, allowing RAD with wxWidgets. C::B is very similar to VS in many ways, but perhaps not quite as powerful or as richly featured....But hey, it's free!
It's also cross-platform, so it works equally well on windows and mac too!

I have also tried Anjuta, Netbeans and Eclipse on *nix. I found that Netbeans and Eclipse were just too damn slow to start up (or to do anything with) and I never really got on with Anjuta... I just didn't like it.

Occasionally I'll use Emacs to edit and compile simple single-file programs (like when helping people with code here on Daniweb).
Or use gEdit and compile with the command line....Sometimes you've just gotta do it via the …

JasonHippy 739 Practically a Master Poster

Well you're very nearly there!
You said you wanted to find out how many items in the array were greater than 100, that would imply that you need some kind of counter, which is the missing ingredient in your original description.
So in your code:
You set your counter to 0
You use a for loop to loop through your array.
On each iteration of the loop, if the current item is greater than 100, increment the counter by one.

Once you're out of the loop, your counter holds the number of items which were greater than 100.

Cheers for now,
Jas.

EDIT: doh beaten to the punch!

JasonHippy 739 Practically a Master Poster

You can't pass the filename like that, that's just passing "args[1]" as a string literal you need to do something like this:

// build the string..
std::string command = "fc " + (std::string)args[1] + " ../o.txt";

// now execute the command..
code = system(command.c_str());

Now you're good to go!
Cheers for now,
Jas.

EDIT: Dammit, I knew I shouldn't have gone out to put the kettle on before hitting submit!

JasonHippy 739 Practically a Master Poster

Have you tried running your code through a debugger?

If you take the call to fabs out of your return statement in your operator== overload and store the result in a variable and then step through your code and take a look at the value, you'll see the problem.

Change your operator== overload to look like this:

bool operator==(const real& x1, const double x2)
{
	double x3  = fabs(x2 - x1.value);
	return x3 <= x1.error;
}

Step through the code and take a look at the values of x3 and x1.error.

Floating point mathematics strikes again!
This is down to the way that floating point values are handled in computer systems. In any computer system there are a finite number of numbers that can be accurately represented (depending on the architecture). Int values are quite straightforward and can be represented accurately, but floating point values are a bit trickier and are never exact, they are mere approximations. So not every possible decimal number can be accurately represented!

So although you've put 1.1 and 0.1 into your real class, these values are represented as something like 1.10000000000000001 and 0.100000000000000001.

fabs is giving you a result of 0.10000000000000009

Which isn't what you want when you're trying to compare one floating point number against another!

However, if you know how many decimal places you need to be accurate to (e.g. 4!), you could do something like this to compare the values:

bool operator==(const …
JasonHippy 739 Practically a Master Poster

Despite working as a programmer for several years, I wouldn't consider myself an expert per se. I'm still learning new things every day. But I'd have to echo what niek_e said and say that the main thing you need on the road to becoming an expert is experience with the language.

Some kind of formal qualification or degree in an IT/Software related discipline would also help, but is by no means essential!
I'm getting along fine without a degree, but I do hold a vocational qualification in 'C', which actually helped get me into my first junior C++ programmer position.

Anyway, the main thing is experience.

Experience can be gained through:
Designing and writing your own applications - This goes without saying. Although, I find that debugging your own programs is the most useful experience of all!

Looking at open source code - Possibly even contributing some code to an open source project. Any code submitted to an open source project is usually scrutinised by several other members of that project. So they'll point out any flaws in your code/logic and will give you good pointers on how to improve your code.

Participating in forums - like here on daniweb. Beyond just posting your own problems, check out the C++ forums and take a look at the code other people are posting and try to solve their problems yourself...Even if you don't feel confident enough to post an attempt at a solution, take …

Nick Evan commented: *nods* +10
mrnutty commented: Thanks for the info +2
JasonHippy 739 Practically a Master Poster

Your GetData and GetSize functions need to be declared const
e.g.

unsigned GetSize() const // This
	{
		return n;
	}
void* GetData() const // and this needs to be const
	{					
		return v;
	}

Because the parameter 'a' to the Allocate classes operator = override function has been declared as a constant reference to an Allocate object, then the GetData and SetSize functions have to be declared as const otherwise the compiler thinks that they might attempt to modify the Allocate object....If you follow me!

Cheers for now,
Jas.

edit:
Dammit, beaten to the punch again!

JasonHippy 739 Practically a Master Poster

I think that learning about tweening is a great idea, you should do it! heh heh!

When used properly tweening can make your animations look a lot more natural, realistic and life-like.

There are some great free tweening libraries available for AS3 (like tween lite http://blog.greensock.com/tweenlite/ ) which are actually more powerful than the built in tweening classes (and easier to use as well!)

Regarding your preloader question...Google it, there are loads of tutorials about creating flash preloaders all over the web (or at least there were the last time I looked). You certainly don't need to go buying a template! Why do that when you can create one yourself?!

The bar and % loaded indicators are quite straightforward to create, but there's nothing to stop you from doing something more elaborate while the file is loading.

I recommend that you do the following:
1. Take a look at some preloader tutorials (even if they are sucky bar and % indicators)
2. Understand exactly what they're doing and how

Once you've done that and you understand how they work, you can use that knowledge to create your own preloader...If you like you can make a monkey breakdance while the file loads, it doesn't have to be a bar and a %loaded indicator.
The only reason most flash files use simple bars and % indicators is to ensure that the preloader part of the .swf loads and starts running really …

iamthwee commented: I'll second this. +11
JasonHippy 739 Practically a Master Poster

Flash sucks
flash intros penalise in search, annoy your customers
anything that makes the page load longer, kills customer retention

heh heh, aside from that and actually staying on topic..heh heh!

I've never used after effects, so I couldn't comment on its functionality, but it's certainly possible to do an intro like that in flash. But you'd have to be bloody good to get something that looked as flashy looking as that behemoth of an intro!

That was a very professionally made intro..But its a shame it took so long to load...It should be noted that the flash intro you linked to there was more the kind of thing for use in a video presentation, a desktop flash app or perhaps a LAN based site rather than a web based flash site, it even said so on the web page.

If you're planning on doing an intro like this for a video presentation or a desktop flash app, then you should be OK, go ahead and give it a shot, the sky's your limit!

However; if you're doing this as an intro for a website, then you'd probably be better served doing something more optimised. As bob has already pointed out, if your intro doesn't load quickly, then potential users of your site will just leave...They won't wait!
Likewise, if the intro is too long (and especially if there's no 'skip intro' button), your users will just leave...unless the intro is really REALLY …

JasonHippy 739 Practically a Master Poster

dkalita has already explained it to you...Try reading his post again!

The function 'fun' returns an int.
But it takes a pointer to a function as a parameter.
The function pointer must point to a function which returns an int and takes no parameters.

main happens to be a function, it returns an int and it takes no parameters, so you can easily pass a pointer to main into the function. Even from within main!

Function pointers do have their uses and I've never seen a function which took a pointer to main as a parameter, but I guess there may be some practical applications, perhaps some recursive algorithms might call for something like this.

I've expanded on the example you posted. This little doozy uses a function pointer to implement recursion:

#include <iostream>

using namespace std;

// function declaration
int myFunction(int (*funcPtr)());

// global static int to stop us from recursing too far
static unsigned int count=0;

int main()
{
	cout << "inside main" << endl;

	// now we'll call our function passing a pointer to main
	myFunction(main);
	
	cout << "exiting main" << endl;
	return 0;
}

// myFunction:
// calls a function pointed to by the input parameter (a function pointer)
// \returns<int>
// \param<funcPtr>takes a pointer to a function which returns an int but takes no parameters
int myFunction(int (*funcPtr)())
{
	cout << "inside myFunction!" << endl;

	// increment the counter
	count++;
	// if count is less than 3:
	if(count<3) …
JasonHippy 739 Practically a Master Poster

Aha,
I've just fired up one of my linux boxes, I've created a project in codeblocks using your files. I've made my suggested changes and and tried compiling... And there are still compiler errors.

The problem seems to be regarding the base class members (from ArrayQueue.h) in the Deque class. For some reason g++ doesn't seem to recognise the protected members from ArrayQueue.h like front, back, count, items etc.

I'm not sure if there's a compiler switch to enable the compiler to recognise these correctly, but I've found that if you reference the base-class members using the 'this' pointer in Deque.h, then the compiler errors disappear.

Here's a snippet from Deque.h to show you what I mean:

template <class T>
bool Deque<T>::dequeueBack(T &itemRef){
	if (this->isEmpty()){//cannot dequeue
		//cout<<"Empty dequeueBack in Dequeue\n";
		return false;
	}
	else{//procede dequeuing
		itemRef= this->items[this->back];
		if (this->back==0)
			this->back = MaxQueue-1;
		else
			this->back--;

	}
	this->count--;
	return true;
}

Anyways, the program now compiles without errors or warnings on windows and *nix. A .zip is attached with my changes applied.

In order to ensure that my changes haven't introduced any bugs to your code (apologies if any have crept in there!); you might want to ensure that the program still works in the way you originally intended it to.

Cheers for now,
Jas.

[EDIT]
p.s. I'm fairly new to *nix programming myself...Up until recently I've only ever developed on Windows (so yes, I'm a bit wintarded!). The little *nix programming …

JasonHippy 739 Practically a Master Poster

Can Someone tell me why these files won't compile on unix but work fine (mostly) in windows?

It looks like unix-land doesn't load the variables from the inherited class QueueArray into the proper scope.

prog5.cpp is supposed to create 3 different types of Deque classes.
each Deque inherits from ArrayQueue

Your help is greatly appreciated =)
Thanks everyone

One thing that immediately strikes me is that you are using #pragma once, which as far as I am aware is a preprocessor command that is used solely by Microsoft compilers. So perhaps using traditional inclusion guards might help here. e.g.

#ifndef SYMBOLNAME_DEFINED
#define SYMBOLNAME_DEFINED

// The rest of your header code goes here

#endif // SYMBOLNAME_DEFINED

I'm thinking that because gcc doesn't recognise the #pragma command, it therefore sees no inclusion guards in your code. So perhaps that could be causing things to go a little screwy with gcc.

Also between lines 45 and 46 of the bool Deque<T>::dequeueBack(T &itemRef) function in "Deque.h" you need to add a 'return true', otherwise you'll get some errors or warnings from the compiler (in both *nix and microsoft environments.)

I've not got a *nix box in front of me at the moment, so I can't test this, but replacing all instances of '#pragma once' with traditional (gcc and MS compatible) inclusion guards and then adding the 'return true' to "Deque.h" would at least be a step in the right direction, if not the complete solution to your problem!

JasonHippy 739 Practically a Master Poster

Hey Tom.
Looking at the error messages and the fact that some of them are referring to a vector and then looking at line 3 of your final block of code:

std::vector<BaseEnt> entities(;

Note: You haven't closed the brackets ')' !!

I'm beginning to wonder if the compiler is getting a bit confused and is thinking that the code after the opening bracket are arguments to the constructor for the vector of BaseEnt's...Perhaps throwing the errors you're seeing....

What happens after you close the brackets and then try to recompile??

std::vector<BaseEnt> entities();

Give that a shot and see what happens!

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

I appreciate your quick response!

I haven't worked with vectors yet, but I see a little better now how to pass by reference.

So I'm going to need variables in main() that will get their values changed by the functions? I'm having difficulty understanding the difference between a global variable and what ever the variable is called in main() that changes.

How do I initialize variables in a function, then pass the values to values in main? don't I have to initialize variables in main for them to even compile?

OK well, to clear things up we'll take a quick look at how different parameter passing methods affect the way that parameters to functions are handled inside functions.

There are three main ways of passing parameters to functions.
1. Passing by value
2. Passing by reference
3. Passing a pointer

Here's a demonstration of passing by value:

#include<iostream>

void somefunc(int foo);

int main()
{
        int foo=4;
        somefunc(foo);
        cout << foo; // will ouput 4!
}

void somefunc(int foo)
{
        foo *= 2;
}

In the above code, somefunction takes an int as a parameter. The int parameter is passed by value. When passing by value the function creates a copy of the value passed into it. So in main the value of foo is passed into the function somefunc. Inside somefunc a copy of foo is created. Any changes made to the copy of foo inside somefunction are not reflected in the foo in …

kadji.kahn commented: Very helpful, and detailed +1
JasonHippy 739 Practically a Master Poster

I'm trying to make a program that will read two txt files, with GPA information (one for females and one for males) arranged like this:

M 4.0
M 3.7
M 2.9

I've been instructed to used pass by reference void functions with no global variables. My major issue is how do I make a function to open the files then another to initialize variables? Here's what I've got so far, it's pretty rough.

If some one can even just explain conceptually how to do something like this, that would be great.

//GPA.cpp
//CMP-110
//October 09'



#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>

    //Function Prototypes
void openFiles(
void initialize(
void sumGrades(
void averageGrades(
void printGrades(


int main()
{

openFiles()


}


void openFiles(ifstream& gpa)
{
    ifstream mData;
    ifstream fData;
    ofstream outGpa;

    mData.open("c:\\maleGPA.txt");
    fData.open("c:\\femaleGPA.txt");

    outGpa.open("c:\\finalGpa.txt");
    outGpa << fixed << showpoint;
    outGpa << setprecision(2);

    
}
    
void initialize(&)
{
    int mCount = 0;
    int fCount = 0;
    double mGPA = 0.00;
    double fGPA = 0.00;
    int countFemale = 0;
    int countMale = 0;
    double sumFemaleGpa = 0.00;
    double sumMaleGpa = 0.00;
}

void sumGrades(&)
{

OK, I'm not sure exactly what you're after here but this snippet might help you a little:

#include<iostream>
#include<fstream>
#include<string>
#include<vector>

using namespace std;

////////////////////////////////////////////////////////////////////////////////
/// opens a file and reads its contents into a vector of strings.
////////////////////////////////////////////////////////////////////////////////
/// \param<filename> const reference to a string
/// \param<content> reference to a vector of strings
////////////////////////////////////////////////////////////////////////////////
void readInputFile(const string &filename, vector<string> &content)
{
	ifstream infile;
	infile.open(filename);


	string …
JasonHippy 739 Practically a Master Poster

Aha, I've just quickly tested it and it seems to work!
Here's a little program I knocked up, loosely based around previously posted code in this thread:

#include <iostream>
#include <algorithm>
#include <deque>
#include <ctime>
#include <iterator>

using namespace std;

struct Str
{
	int a,b;
};

bool deq_test(Str& deq1, Str& deq2)
{
	if(deq1.a==deq2.a)
	{
		return(deq1.b<deq2.b);
	}
	else
		return(deq1.a<deq2.a);
}

int main()
{
	deque<Str> deq;
	srand(time(NULL));
	Str MyStr;

	cout << "Generating values and populating deque:" << endl;
	for(int i=0; i<6; ++i)
	{
		MyStr.a = rand()%10;
		MyStr.b = rand()%10;
		cout << "a = " << MyStr.a << ", b = " << MyStr.b << endl;
		deq.push_back(MyStr);	
	}

	cout << endl << "Sorting Deque..." << endl << endl;
	sort(deq.begin(), deq.end(), deq_test);
	
	cout << "Sorted values are: " << endl;
	for(deque<Str>::iterator iter = deq.begin(); iter!=deq.end(); iter++)
	{
		cout << "a = " << (*iter).a << ", b = " << (*iter).b << endl; 
	}
}

And some sample output is shown in the attached .png.
Looking at the png, you can see that there are several values which have an 'a' value of 2. These have successfully been sorted by their 'b' values.

Problem solved??

Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

Another thing that was pointed out by one of my math-geek colleagues was that my algorithm would also incorrectly flag 1 as prime.

Now I always thought that 1 was prime (it only divides evenly by itself and 1, so it kinda fits the criteria).
However, according to my colleague; traditionally that was the case, but nowadays there is a slightly different school of thought and 1 is no longer considered prime, for reasons I can't be arsed to go into! He did explain but I kinda zoned out...heh heh! What?! It's early! I haven't had any coffee yet!! ;)

Apparently 1 hasn't been considered prime since the 1950's or thereabouts...So not wanting to be stuck in the past (without a DeLorean fitted with a flux capacitor, heh heh!), we could alter my algorithm to flag 1 as not prime like this:

if(numIn==2)
        return true;
else if(!(numIn%2) || numIn==1)
	return false;

Incidentally, I was a little bored at work yesterday, so at lunchtime while I was waiting for a long build to finish I altered the function to work with unsigned long long integers and then created a quick little program which used my little function to calculate all the primes in the range from 1 up to the value returned by std::numeric_limits<_ULONGLONG>::max() (which on my pc returns as 18,446,744,073,709,551,615...a very large number indeed!) and output them to a text file....

I let it run for a few hours while I got on with some …

Gaiety commented: you gotta lot of energy...! +1
JasonHippy 739 Practically a Master Poster

OK, push_back definitely is the safest way of populating a vector. However, the method I'm about to show is not particularly good practice, but it can be done and it does have it's uses:

#include<iostream>
#include<string>
#include<vector>


using namespace std;

int main()
{
	// here are our original strings in an array of strings
        // for the sake of this example imagine that strs[] was
	// passed in as an argument so we don't know upfront how 
        // many strings are in the array 
	string strs[] = {"String1","String2","String3","String4","String5"};

	// But before we attempt to reserve some space on a vector,
        // we need to know how many strings there are..... 
        // trying to count them doing something like this
	// int count=0;
	// while (strs[count])
	//     ++count;
	// 
	// Would not work as std::string cannot be evaluated like 
        // that...So we actually need to know upfront how many there are
	// in order to reserve space in the vector.
	int count=5; // so this value would have to be passed-in too!

	// reserve 'count' spaces in our vector
	vector<string> vec(count);

	// now our vector has enough space to hold all of the strings in the passed-in array....
    // so we'll set up a loop to copy strings from the array to the vector:
	for(int index=0;index<count; ++index)
	{
                // This can be used, but it is dangerous
		//vec[index] = strs[index];

                // This is safer..Less likely to cause a crash if you 
                // overstep the mark with index!
                vec.at(index]=strs[index];
	}

	// …
Ancient Dragon commented: Yes, that will work too. +24
JasonHippy 739 Practically a Master Poster

Why don't you try using the shlobj.h function SHGetSpecialFolderPath to get the path to the users My Documents folder? It would save all of the messing about your doing there!

Try replacing the code in your main function with this:

int main()
{
    // get the path to the current users my documents folder
    // storing it in an LPSTR
    LPSTR userDocsPath = new CHAR[MAX_PATH];
    SHGetSpecialFolderPath(0, userDocsPath, CSIDL_MYDOCUMENTS, 0);

    // now copy the path into a std::string
    std::string path = std::string(userDocsPath);

    // delete the LPSTR as we don't need it any more...
    delete userDocsPath;

    // Now you've got the path to your users 'My Documents' folder
    // stored in path, you can append any further directories onto it. 
    // e.g.
    path.append("/OMG"); 
    // NOTE: using forward slashes works in file paths, double backslashes are not necessary!

    // Not sure you need to bother creating an 
    // LPSECURITY_ATTRIBUTES object seeing as you're setting it to null!
    CreateDirectory(path.c_str(), 0);
    cout << "\nFolder Created!\n";
}

For more info take a look at the following pages:
SHGetSpecialFolderPath:
http://msdn.microsoft.com/en-us/library/bb762204(VS.85).aspx
CSIDL values:
http://msdn.microsoft.com/en-us/library/bb762494(VS.85).aspx

Hope that is of some help!
Cheers for now,
Jas.

JasonHippy 739 Practically a Master Poster

To put dkalitas point a little more succinctly:
If you want to execute several statements under an if() statement, then you should enclose them with curly braces '{}'.
e.g.

if(condition)
{
    doSomething();
    something = something_else;
}
else
{
    foo=bar;
    bar=another_thing;
}

If you only want to use one statement under an if, then you don't need to use the braces...Braces are optional in that case!
e.g.

if (condition)
     doSomething();
else
    something = something_else;

or perhaps

if(condition)
    doSomething();

foo = bar;
bar = something;

if(foo==bar)
    doSomethingElse();

So in your code, because you haven't used any braces under any of your if() statements; The first statement under the if() will only get executed if the if statements condition is met...All subsequent statements will be executed regardless of the result of the if statement. (see dkalita's 2nd snippet. That's how the compiler will interpret your code without the braces!)

Cheers for now,
Jas.

dkalita commented: that was a detailed answer.... :) +1
JasonHippy 739 Practically a Master Poster

Yup you got it Raja, that's how you set up the path to the SDK and the path to the external flash player!

I've got my Flashdevelop set up to use the flashplayer10 debug executable!
Note: in the FlashViewer section of the program settings, ensure that the 'Movie Display Style' property is set to External!
'Popup' and 'Document' use the default player (fp 9 debug ActiveX)

In order to demonstrate tracing in flashdevelop, I've knocked a little example project together. (see attached files.)

To actually create the project, I've just gone to 'project->new project' in the menu and then in the dialog I've selected the 'AS3 Project' template and called the project Tracing.

Flashdevelop has now created a few directories (bin, lib and src) and files. Briefly exploring the generated files and folders:
The bin folder is where the final .swf will end up being built.
Initially the bin folder contains a html file which is set up to embed the final .swf using swfobject.js (found in the js sub-folder). It also includes expressinstall.swf, which is also used by the html page, in case people viewing the page have an older version of flash...in which case, it can download and install the correct version.

The lib folder is where you can put any assets for your project (Bitmaps fonts etc.). It should be noted that simply adding items to the lib folder does not make them instantly accessible to …

JasonHippy 739 Practically a Master Poster

It took a bit of playing around, but think I've found a workaround for this....

I noticed in the docs for os.system() (Yes I RTFM!) it mentions that the subprocess.call() should be used instead.
So I had a go with subprocess.call() but I soon ran into very similar problems, it still didn't like the spaces in the path.

After a bit of playing around and using a bit of lateral thinking I decided to try using subprocess.call() to call 'cmd.exe' passing it the path to a program in 'Program Files' as a parameter.

Now, I don't have winamp installed on my pc, so I decided to try and fire up Audacity using the following code:

import subprocess

subprocess.call(r'C:\WINDOWS\system32\cmd.exe /C "C:\Program Files\Audacity\audacity.exe"')

And you know what?? It bloody works!

After that, I decided to try using os.system in exactly the same way (use it to fire up cmd.exe with the path to Audacity as a parameter):

import os

os.system(r'C:\WINDOWS\system32\cmd.exe /C "C:\Program Files\Audacity\audacity.exe"')

Guess what??
That worked too!

Woot woot! :)

You'll get a little cmd window that will pop-up alongside whatever program you fire up, but it will disappear when you close the program down again.

So, all you need to do is copy one of the bits of code posted above and then replace my path to Audacity with the path to your installation of Winamp!

Hope that solves your problem.
Cheers for now,
Jas.

pysup commented: cool.. Thanks +1
JasonHippy 739 Practically a Master Poster

OK, I know it's been a while since I originally posted this and I've marked the thread as solved, but this is a valid bug in wxPython....So here's a quick update!

I finally managed to get onto the wxpython.org site to report the bug today. (All of the wxpython/wxwidgets websites were down when I originally discovered this bug back in June and I haven't tried any of their websites for a while, so I completely forgot about reporting it until today!)

Anyway, I've taken a quick look at the current python source code in their svn repository and the issue is still there, so nobody else has reported/fixed it yet!

My bug report ticket number is #11255 (http://trac.wxwidgets.org/ticket/11255)

Hopefully the bug will be accepted and fixed for a future release of wxPython, but in the meantime if anybody has problems with this bug then by all means use the fix I documented in my original post.

I'll keep an eye on this and keep you all posted!
Cheers for now,
Jas.

Ene Uran commented: thanks for the bug fix! +9
JasonHippy 739 Practically a Master Poster

So what's the difference between:

void foo(int(&A) [])

void foo(int A[])

If the contents of array A need to be modified by the function foo, which of the two is the correct usage?

Thanks.

As far as I understand it, they are both valid and correct.
When passing an array via a reference:

void foo(int (&A)[10])

The only prerequesite is you need to know the dimensions of the array upfront.

But if you pass the array by value:

void foo(int A[]);

Because it's an array you're passing in, Its basically the same as passing a pointer. An array object contains the memory address of (and therefore a pointer to) the first position in the array.
This way you don't need to know the size of the array upfront. (That's not to say that the size of the array isn't important...Don't go indexing out of bounds or anything. You just don't need to specify the size of the array in the function prototype!)

So which you choose really depends what you're trying to do I guess!

Whereas if you were trying to pass a large class object to a function you could
pass in the following ways:
e.g.

void foo(CLargeClass myLargeClass); // pass by value
void foo(CLargeClass *myLargeClass); // pass by pointer
void foo(CLargeClass &myLargeClass); // pass by reference

Passing by value in this case would incur a performance hit because normally; passing by value creates a copy of the object …

JasonHippy 739 Practically a Master Poster

OK, here's a very simple class and some code to test it, based on what you posted previously!

# here's a simple class
class MyClass:
    # class constructor/initialisation
    # if no string is passed, defaults to an empty string
    def __init__(self, aString=""):
        self.myString = aString

    # addText function
    def addText(self, appendedText):
        self.myString += appendedText

    # getString function - returns the current string
    def getString(self):
        return self.myString

# Now lets test the class...
print "Testing the class [passing a literal string to the  constructor]"
# Create an instance of the class, passing some text
myObject = MyClass("Blah blah blah...")
print myObject.getString() # Lets see what we've got

# now lets add some text by passing a literal string to addText...
myObject.addText("More text...")
print myObject.getString() # Now what do we have?

# now lets create a string object and pass it to addText...
anotherString = "Yet more text!"
myObject.addText(anotherString)
print myObject.getString() #  Now what've we got?

print "\nTesting the class [passing no parameters!]"
myOtherObject = MyClass()
print myOtherObject.getString() # This should print a blank line

# now lets pass addText the string object we created earlier!
myOtherObject.addText(anotherString)
print myOtherObject.getString() # now what have we got?

The addText and getString functions speak for themselves..They're pretty straightforward.

The __init__ function is the important bit here, this is what gets called when you instantiate the class. You perform any initialisation for your object here.

The other thing of note is 'self', which is kinda like the 'this' pointer in C/C++/Actionscript (and Java?.. …

vegaseat commented: now that is class! +15
JasonHippy 739 Practically a Master Poster

I was driving past a local special-needs school the other day and I noticed a sign facing the road that says 'SLOW CHILDREN'....And I thought, "Well, that can't do much for their self-esteem can it?" - Jimmy Carr

JasonHippy 739 Practically a Master Poster

Hi folks
I have just completed my first programme with help from yourselves.
I cant understand why the code , if x ==1 or 2, wouldn't work in my programme below

# Convert C to F or F to C and return with result

select = True
while select:
    x = int(raw_input ('To convert Celsius to Farenheit, enter 1\nTo convert Farenheit to Celsius, enter 2\n'))   
    if x == 1 or x == 2:
        select = False
    else:
        print 'Only options are 1 or 2'            

#Convert C to F
if x == 1:
    def Tc_to_Tf ():        
        Tc = input ("What is the Celsius Temperature ?   " )
        Tf = 9.0/5.0 * Tc + 32
        return Tf
    Tf = Tc_to_Tf ()
    #.2f instructs Python that placeholder holds float number with 2decimal places. 
    print 'The temperature is %.2f Degrees Fahrenheit' %(Tf, )
        
#Convert F to C
if x == 2:
    def Tf_to_Tc ():
        Tf = input ("What is the Fahrenheit Temperature ?   " )
        Tc = (5.0/9.0)*(Tf - 32)
        return Tc
    Tc = Tf_to_Tc ()
    print 'The temperature is %.2f Degrees Celsius' %(Tc, )

Many thanks in anticipation. I included the whole programme as I would value any comments on my methods.
Graham

I can't see a problem with the code you've posted!

However if you were using this before:

if x==1 or 2:

Then as gerard has said, the if statement would always evaluate to True...

for example if the user entered '4' as their first choice, …

sneekula commented: great explanation +8
JasonHippy 739 Practically a Master Poster

Hey, we've almost got enough people in this thread to start up an internet based all-geek band here on Daniweb!

Me 'n Crazzy Cat can share drum / percussion duties,
Serkan Sendur and Mosaic Funeral on Guitar,
Grn Xtrm on Bass,
and Rashakil Fol and PaulThom on Piano/keyboard.

Mosaic can also do his best Trent Reznor impression with his miscellaneous electronic noise making equipment.

Now all we need is a vocalist and some ideas on musical direction! Heh heh!

Live gigs and rehearsals are probably out of the question (unless things go seriously viral...Yea' right!), but we might be able to cobble a few MP3 tracks together!

Anybody up for it?

JasonHippy 739 Practically a Master Poster

Considering the problem you have set, your algorithm is completely wrong. And as already mentioned by niek_e, you're using the for loop incorrectly too!

Follow niek_e's advice and take a good look at using for loops.
His post shows you how to correctly use them..
And as he's already said, you should change void main to int main or risk Salems wrath ;) heh heh!

Going back to your actual algorithm, what you need to be doing inside main() is something like:
1. initialise your variables, include a boolean flag to check whether the user was correct (initialise it to false).
2. set up your for loop to iterate three times
Inside the loop you need to do this:
- Ask user to enter a value between 1 and 10
- If the entered value matches the password (3?), set your flag to true and break out of the loop
- else if the value is less than one or greater than 10, display an error message.
- else inform the user that they guessed incorrectly..

(finally after the for loop)
3. check the value of your flag.
- if true, the user guessed correctly during the for loop.
- else user guessed incorrectly 3 times and failed!

Hope that's of some help!
Cheers for now,
Jas.

tux4life commented: Nice post :) +22
JasonHippy 739 Practically a Master Poster

In main() you aren't instantiating your matrix class correctly.
Also your add and multiply functions are currently member functions so you'd have to access them via an instance of your Matrix class.

To correctly instantiate your class you need to do something like:

Matrix* mat1 = new Matrix(rows, cols, initValue); // pointer to a new matrix

or perhaps:

Matrix mat1(rows, cols, initValue);

Likewise, you'd have to do something similar to instantiate mat2.

Then there's this bit of code in main, which is what is causing the errors you mentioned:

for(int i=0; i < rows; i++)
		for(int j=0; j < cols; j++)
			Add(mat1, mat2);
	
	for(int i=0; i < rows; i++)
		for(int j=0; j < cols; j++)
			Multiply(mat1, mat2);

As mentioned, the problem here is that you are trying to access a function which is a member of a class, but you don't have a proper instance of the Matrix class...

I'm not going to solve the whole problem here for you, but I can point you in the right direction...
What you really need to be doing is something like this in main:

Matrix* resultOfAddition = mat1->Add(mat2);
Matrix* resultOfMultiplication = mat1->Multiply(mat2);

or:

Matrix* resultOfAddition = mat1.Add(mat2);
Matrix* resultOfMultiplication = mat1.Multiply(mat2);

(depending on how you instantiated your class!)


You then need to change your Add and Multiply functions, so they take a constant reference or a pointer to a Matrix object as a parameter also make them return a …

Salem commented: Much more detailed than my terse effort +36
JasonHippy 739 Practically a Master Poster

Hey there,
Attached is a quick example to show you what I mean.
I've attached example.zip which contains a simple 200x50 .swf with an example of that text effect from the tutorial you posted. (example.swf)

The .swf has been exported with a white background, so it should be very similar to what you've currently got.

I've also included a very rough (and very orange) html file (example.html) which I knocked up in a few short minutes to show you what I was talking about in my previous post...There's no nice css or formatting in there or anything I just threw this together really quickly, so apologies if it is ugly to look at!

All it does is embed three instances of example.swf on the page.

The first instance has no bgcolor parameter in the embed tags, so it appears white. The second has had it's bgcolor parameter set to red, and the third is set to orange (so it blends in nicely with the rest of the page!)

Cheers for now,
Jas.

sam023 commented: ur post is really helpful +1
JasonHippy 739 Practically a Master Poster

Here are a few of my favourites:

Life, loathe it or ignore it, you can't like it. - Marvin the paranoid android (Hitch Hikers Guide To the Galaxy).

I'm not afraid to die, I just don't want to be there when it happens. - Woody Allen

Either he's dead or my watch has stopped. - Groucho Marx

I don't mind dying, the trouble is you feel so bloody stiff the next day. - George Axlerod

It isn’t necessary to imagine the world ending in fire or ice – there are two other possibilities: one is paperwork, and the other is nostalgia. - Frank Zappa

To succeed in the world it is not enough to be stupid, you must also be well-mannered. - Voltaire

Only in Britain could it be thought a defect to be 'too clever by half.' The probability is that too many people are too stupid by three-quarters. - John Major

I sort of felt sorry for the damn flies. They never hurt anybody. Even though they were supposed to carry disease, I never heard anybody say he caught anything from a fly. My cousin gave two guys the clap, and nobody ever whacked her with a newspaper. - Lenny Bruce

Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. - Albert Einstein

I wouldn't recommend sex, drugs or insanity for everyone, but they've always worked for me. - Hunter …

vmanes commented: Great collection of quotes! +10
JasonHippy 739 Practically a Master Poster

I have this piece of code

// some function
int px;
void SomeFunction( void *dummy )
{
	...

	RECT rect;
	GetWindowRect(hWnd, &rect);
	px = ((rect.right - rect.left) / 2) - 60;

	...

	// Terminate thread
	_endthread();
}

And my problem is px doesn't get assigned.. it stays 0.. although in the debugger I can see all the values inside rect..
please help me

What about if you change px from int to long? Does that give you any differemt results?
The thing to take note of here is that px is currently declared as an int. Whereas rect.right and rect.left are both LONG/long variables.

Therefore if the result of your calculation is less than 1.0 (e.g. something like 0.43455664), then because px is an int, the calculated value will be truncated to 0.
Whereas if you alter px to be long, you'll get the actual calculated value (in my example 0.4345564).

I could be wrong, but that looks like the most obvious explanation to me!

oh, hang on.....Looking at that code, another thing strikes me as odd....
px is declared outside of the function, but used inside it..
That's probably your problem right there!
The px used in the function and the px outside of the function might not be the same variable, they might have different scope.
If you could post some more code, we might be able to determine whether or not this is the case!

Cheers for …

Salem commented: Two px's in scope could easily explain it +36
JasonHippy 739 Practically a Master Poster

One other thing has sprung to mind....

If your program is actually running for a while before it bombs out, it's almost certainly a bug in your code.

If it works on your machine and not any others, is it possible that you have hard coded something into your program which is specific to your machine?....Like perhaps a file-path or something??

Taking the filepath as an example:
Say your program needs to use a file like...
C:\somefolder\somefile.txt

Your machine has a folder on the root of c: called somefolder and contains the appropriate file, but your other windows machines do not.

OK so, you run your program on your XP machine, it finds the file and does whatever it needs to do...ok, fine!
Now you run it on another XP machine....One that does not have the appropriate folder/file...
Perhaps as well as hard coding the path, perhaps when opening the file, you've not put a check in your code to ensure that the file opened ok before attempting to do something with it....
Your program then tries to access the non existent/non opened file and the program crashes..

OK, This is merely a possible scenario. Conjecture if you will, but it's an example of something that could cause problems!

Take another look at your code and see if there is anything which is specific to your machine hard coded in there and then try to make it more …

JasonHippy 739 Practically a Master Poster

OK,
After this line:

label = Tkinter.Label(pg4_group.interior(), image=photo)

try adding the following:

label.photo = photo

This will create an instance of your image in the label, preventing it from being garbage collected (Which is what I suspect is going on!).


Next, after your call to label.place, add the following:

label.pack()

Your final file should look something like this:

from tkFileDialog import *
import Image, ImageTk,Pmw, Tkinter

class Demo:
    def __init__(self, parent):
        notebook = Pmw.NoteBook(parent)
        notebook.pack(fill = 'both', expand = 1, padx = 10, pady = 10)
        page_4 = notebook.add('About')
        pg4_group = Pmw.Group(page_4, tag_text = 'Picture')
        pg4_group.pack(fill = 'both', expand = 1, padx = 10, pady = 10)
        image = Image.open("pic.JPG")
        photo = ImageTk.PhotoImage(image)
        label = Tkinter.Label(pg4_group.interior(),image=photo)
        label.photo = photo #prevent photo from being garbage collected
        label.place(x=0,y=0,width=image.size[0],height=image.size[1])
        label.pack() # display the image
        
if __name__ == '__main__':
    root = Tkinter.Tk()
    Pmw.initialise(root)
    widget = Demo(root)
    root.mainloop()

Now your image should appear and your problems should be solved!

Cheers for now,
Jas.

P.S. See the following link for more details on the Tkinter.Label widget:
http://effbot.org/tkinterbook/label.htm

bumsfeld commented: nice help! +7
JasonHippy 739 Practically a Master Poster

Piriform do a great free file recovery tool called recuva, which I highly recommend. Take a look at www.recuva.com.

I've used it several times to recover files when friends or relatives have accidentally deleted important files on their PC's. I carry a copy everywhere on one of my USB sticks (along with portable versions of Piriforms other free apps CCleaner and Defraggler plus others like the full Sysinternals suite of system diagnostic tools, Cain and abel etc. etc...)!

As the other posters have already stated, once you've deleted a file, the space it used to occupy is basically open to being overwritten and could be overwritten by the system at any time.

But usually, as long as you're quick with your recovery tool (and as long as you're lucky), you should be able to recover most, if not all of your files!

After installing Recuva on your PC, you can create a portable version of the app to go onto a USB stick. To do this, open up your program files directory (or wherever you installed Recuva) and copy the entire Recuva folder to a USB stick. Open the Recuva folder on the USB stick, right click and select 'new->text document' to create a new text file and rename it portable.dat. This will cause Recuva to create and use an ini file in the folder on the USB stick to store user preferences instead of making regsitry entries.

Now you have a copy …