Thank you to everyone who posted, after reading your posts, reading some text books on GUI development, re-reading your comments confirms I 'get it' now. :)

I've used C++ before, and I'm inexperienced with GUI designing, so I think I have to think in a much more OO way from now one. The partial classes seem interesting, as do delegates which I've seen some about.

Thanks for the help.

Hi,

I am new to C# and Forms/GUIs.

Basically I am trying to pass a value in a textBox to my programs program.cs file where I can apply my programs logic, but I'm stuck with how to do this.

To get started all I am making is a form which takes two variables, and I want to add those variables together and display the sum in a third text box.

I am stuck though with getting the value entered by the user into my program.cs file where I can use it/add the two values together.

My skeleton app is as follows:

[B]The GUI:[/B]
[URL="

Ah, I've sorted it, seems import statements must be between the package and class declarations.

Hope this helps someone.

Hi there,

I'm completely new to Java.

I am trying to use [I]import[/I] in a project, but despite using what I think is the right code, my application fails to build.

When I build my app, it builds and runs fine, but I want to use [I]JFileChooser[/I], so add this line of code to my program, it is the very first line of code in my app:

[CODE]import javax.swing.JFileChooser;[/CODE]

Now when I try to build it fails. If I comment it out it does build.

Do I have to download JFileChooser and link it into my project or something similar?

I've never imported a package before, searching Google shows lots of use of the import keyword, but I don't see anything about how the IDE/Compiler locates the package in the first place, if that makes sense.

Thanks very much for any help :)

Thanks for your help, so you think I should implement my tree_evaluation() function to iterate through the sets, and return the values held to the set_union(), set_intersection() functions?

Thanks for giving me direction with this. I'm new to trees in general. :)

Hi,

I have an expression tree in which the nodes are operators (union, intersection etc represented by a string "/u") or the nodes are std::sets.

How could I access the std::set's values in order to carry out the tree evaluation using the operator functions(set_union(), set_intersection() etc) ? The expressions are pre and postfix.

Thanks for any help, it's most appreciated.

Hi there,

I am passing command line arguments to a program.

I know traditionally people declare argc and argv like this:

[code=c++]
int main(int argc, char *argv[]
[/code]

but I need to pass bigger numbers into my program (type long long).

Is it OK to use the following:

[code=c++]
int main(long long argc, char *argv[]
[/code]

Or am I making a mistake with this?

Sorry for the newbie question, just couldn't find any examples of this being done, hence my doubt.

Thanks for any advice on this!

Carrots :)

Hi,

I have in my database the location of some images I want to display, all formatted as:

[quote]
../images/products/1.jpg
../images/products/1.jpg
[/quote]

I'm trying to diplay them in a webpage but get the following error:

[QUOTE]
x
Warning: substr() expects parameter 1 to be string, array given in C:\xampp\htdocs\mysite\index.php

x
Warning: substr() expects parameter 1 to be string, array given in C:\xampp\htdocs\mysite\index.php
[/QUOTE]

The 'x's display fine, matching the number of row in the database, but the images do not.

Here is my code:

[code=php]
<?php
$query = "SELECT product_Picture from products LIMIT 0, 10";
$result = mysql_query($query) or die(mysql_error());
$x=0;
while($row = mysql_fetch_array($result))
{
echo 'x';//these work
$row[x] = substr($row, 3);//removes the leading .. from the stored URLs
echo "<img src='".$row."' /><br />";
}
?>
[/code]

Can anyone help me correct this problem?

Your help is most appreciated!

Thanks!

Hi,

I was wondering if anyone can see why the substr_replace() function isn't replacing the 'XXXXX' with the random integer I am creating in the script below:

[code=php]
<?php
$password = rand(12345,98765);
$stringtoparse = 'Your new password is XXXXX';
substr_replace($stringtoparse,$password,18);
echo $stringtoparse;
?>
[/code]

When I run this, I still have the following being output:

[quote]
Your new password is XXXXX
[/quote]

Can anyone see why the function wouldn't be working as I expect and replace the XXXXX with the random number being generated?

Many thanks for any help!

:)

Hi there,

Looking for some advice regarding the following hierarchy structure:

[url]http://i40.tinypic.com/9a1us0.jpg[/url]

I'm storing base class pointers in a std::list in my program:

[CODE=c++]list<Vehicle*>mylist[/CODE]

Is it possible for me to use Pure Virtual functions in the base class?

For example:

[code=c++]virtual int getMPG() = 0;[/code]

Seems fine, as all derived types have an _mpg data member.

But, if I use:

[code=c++]virtual int getNoOfDoors() = 0;[/code]

I am having problems as Boat objects don't have a _noOfDoors data member. Only those derived from Car do.

So I am wondering, is it not possible for me to use Pure Virtual functions in the base class?

I am accessing all the objects in my program through base class pointers you see.

How does one normally handle this hierarchy?

Thanks very much for any advice!

:)

I have solved it.

The base class needed it's member function to be declared as virtual.

This seems to have been the only problem.

Ancient Dragon commented: Glad you found the problem yourself :) More rewarding that way. +26

Thanks for the advice.

I have followed what you suggested:

[code=c++]

ifndef GRANDPARENT_H
define GRANDPARENT_H

using namespace std;

include <string>

/****
Abstract base class
****/
class GrandParent
{
public:
//constructor
GrandParent(string name) {_name = name;}

//Getter
string getName() const { return _name; }

private:

protected:

string _name;

};

/****
Concrete parent class
****/
class ConcreteParent : public GrandParent
{
public:
//constructor
ConcreteParent(string name, string address) : GrandParent(name) { _address = address;}

//Getter
string getAddress() { return _address; }

private:

protected:

string _address;

};

/****
Abstract parent class
****/
class AbstractParent : public GrandParent
{
public:
//constructor
AbstractParent(string name, string telephone) : GrandParent(name) { _telephone = telephone;}

//Getter
string getTelephone() { return _telephone; }

////Pure virtual function for concrete Child class
virtual string getDOB() = 0;

private:

protected:

string _telephone;

};

/****
Concrete child class
****/
class Child : public AbstractParent
{
public:
//constructor
Child(string name, string telephone, string dob) : AbstractParent(name, telephone) { _dob = dob;}

//Getter
string getDOB() { return _dob; }

private:

protected:

string _dob;

};

endif

[/code]

Do you think there could be another reason as to why the slicing is occurring?

Using this code has made no difference and the inherited data members are still being sliced off.

Hi there,

I have a problem in that my derived concrete classes are loosing the data members which are part of my derived classes.

I have wrote a simple program to show the problem.

[B]GrandParent.h :[/B]
[code=c++]

ifndef GRANDPARENT_H
define GRANDPARENT_H

using namespace std;

include <string>

/****
Abstract base class
****/
class GrandParent
{
public:
//constructor
GrandParent(string name);

//Getter
string getName() const { return _name; }

private:

protected:

string _name;

};

//constructor
GrandParent::GrandParent(string name)
{
_name = name;
}

/****
Concrete parent class
****/
class ConcreteParent : public GrandParent
{
public:
//constructor
ConcreteParent(string name, string address);

//Getter
string getAddress() { return _address; }

private:

protected:

string _address;

};

//constructor
ConcreteParent::ConcreteParent(string name, string address) : GrandParent(name)
{
_address = address;
}

/****
Abstract parent class
****/
class AbstractParent : public GrandParent
{
public:
//constructor
AbstractParent(string name, string telephone);

//Getter
string getTelephone() { return _telephone; }

////Pure virtual function for concrete Child class
virtual string getDOB() = 0;

private:

protected:

string _telephone;

};

//constructor
AbstractParent::AbstractParent(string name, string telephone) : GrandParent(name)
{
_telephone = telephone;
}

/****
Concrete child class
****/
class Child : public AbstractParent
{
public:
//constructor
Child(string name, string telephone, string dob);

//Getter
string getDOB() { return _dob; }

private:

protected:

string _dob;

};

//constructor
Child::Child(string name, string telephone, string dob) : AbstractParent(name, telephone)
{
_dob = dob;
}

endif

[/code]

[B]main.cpp :[/B]
[code=c++]

include <iostream>
include <string>
include <list>
include "GrandParent.h"

using namespace std;

int main()
{
list<GrandParent*>theList;

GrandParent *ptrA = new ConcreteParent("a","b");
theList.push_back( ptrA );

GrandParent *ptrB = ...

Hi thanks for replying.

I'm trying to instantiate Parent (the concrete version) and Child and store pointers to those objects in the std::list.

I know the names are slightly offputting, in my real program they are:

[CODE]
Vehicle : [B]Red car[/B]
Blue car : [B]Blue Car 3speed[/B]
: [B]Blue Car 4speed[/B]
: [B]Blue Car5speed[/B]
[/CODE]

Bold indicates a concrete class

Thanks alot.

I attached a .jpeg to my post, and entered:

[attach]image.jpg[/attach]

But it's just showing that code.

Is that wrong?

Thanks for the help :)

Hi,

I was trying to display an image in a thread, but despite using [img][/img] tags, it just parses the link.

Is there a way of posting an image in the post/thread?

Thanks a lot!

Hi,

I'm having trouble understanding how I should use pure virtual functions in my inheritance tree.

I've drawn a class diagram which shows what I'm trying to achieve:

[img]http://i42.tinypic.com/2qjdttd.jpg[/img]

Here is what I've written:

[B]main.cpp[/B]
[code]

include <iostream>
include <string>
include <list>
include "base.h"

using namespace std;

int main()
{
list<GrandParent*>theList;

GrandParent *ptr = new Parent("a","b");
theList.push_back( ptr );

GrandParent *ptr1 = new Child("a","b","c");
theList.push_back( ptr1 );

system ("pause");
return 0;

}
[/code]

[B]base.h[/B]
[code]

ifndef BASE_H
define BASE_H

using namespace std;

include <string>

/****
Abstract base/grandparent class AIRCRAFT
****/
class GrandParent
{
public:
//constructor
GrandParent(string name);

//Getter
string getName() const { return _name; }

//Pure virtual function for concrete Parent class
virtual string getAddress() = 0;

//Pure virtual function for ParentAbstract class
virtual string getTelephone() = 0;

//Pure virtual function for concrete Child class
virtual string getDOB() = 0;

private:

protected:

string _name;

};

//constructor
GrandParent::GrandParent(string name)
{
_name = name;
}

/****
Concrete parent class
****/
class Parent : public GrandParent
{
public:
//constructor
Parent(string name, string address);

//Getter
string getAddress() { return _address; }

private:

protected:

string _address;

};
//constructor
Parent::Parent(string name, string address) : GrandParent(name)
{
_address = address;
}

/****
Abstract parent class
****/
class ParentAbstract : public GrandParent
{
public:
//constructor
ParentAbstract(string name, string telephone);

//Getter
string getTelephone() { return _telephone; }

private:

protected:

string _telephone;

};

//constructor
ParentAbstract::ParentAbstract(string name, string telephone) : GrandParent(name)
{
_telephone = telephone;
}

/****
Concrete child class
****/
class Child : public ParentAbstract
{
public:
//constructor
Child(string name, ...

Hi there,

I'm trying to return base class pointers from the two classes 'base' and 'child', but I keep on getting a build error of "1 unresolved externals".

I think it may be because I am linking all the files together incorrectly.

When I comment out the problem line in main.cpp it builds fine, but when I try to use it (and return a base class pointer), this is when I cannot build the program.

I have copy and pasted my code exactly here:

[b]child.cpp :[/b]

[code=c++]

include "base.h"
include "child.h"
include <iostream>
include <string>

using namespace std;

//Child class contructor
Child::Child(string basestring, string childstring) : Base(basestring)
{
_basestring = basestring;
_childstring = childstring;
}

//Child class function
//Return's a base class pointer
Child * ReturnPtrToANewChildClassObject()
{
//Build an child class object, and then return a pointer to that object
//Wthin main() the pointer will be be pushed into the std:list

string basestring;
cout << "Base string ? " << endl;
getline (cin, basestring);

string childstring;
cout << "Child string ? " << endl;
getline (cin, childstring);

//Get a pointer to the new object
Child *ptr = new Child(basestring, childstring);

//return the pointer to main()
return (ptr);

}
[/code]

[b]base.cpp :[/b]

[code=c++]

include "base.h"
include "child.h"
include <iostream>
include <string>

using namespace std;

//Base class contructor
Base::Base(string basestring)
{
_basestring = basestring;
}

//Base class function
Base * ReturnPtrToANewBaseClassObject()
{
//Build an object, and then return a pointer to that object
//Wthin main() the pointer will be be pushed into ...

hey I got it to work!

Thanks for your advice dusktreader,

took me a while, but I'm very happy none the less.

Thanks for taking the time buddy.

Appreciated

Carrots.

Hi,

I have been wrestling with this program all day and am looking for some help.

I have never separated a program up before into separate files (main.cpp, base.h and base.cpp).

What I'm trying to do is call a function from main() and have that function return a pointer to a new object.

Once the pointer has been returned, I'm trying to push it into the std::list.

The problem I've been having is this compile error:

[QUOTE]illegal call of non-static member function[/QUOTE]

I have wrote a simple version of my program which reproduces the same problem:

[B]main.cpp :[/B]
[code=c++]

include <iostream>
include <list>
include <string>
include "base.h"

using namespace std;

int main()
{
typedef list<Base *>BaseList;

do{
    char choice;
    cout << "a) Create then add a base class pointer into the list" << endl;
    cin >> choice;
    cin.ignore();

    switch(choice)
    {
    case 'a':
        {
            //Create an object and return a pointer to that object
            //(I will be making many of these objects)
            Base::ReturnPtrToANewBaseClassObject();

            //push the returned pointer onto the std::list
            BaseList.push_back( ptr );

            cout << "Object now pushed onto list" << endl;
            break;
        }
    default:
        {
            cout << "You made an invalid choice" << endl;
            break;
        }
    }
}
while(true);

system("pause");

}
[/code]

[B]base.h :[/B]
[code=c++]

ifndef BASE_H
define BASE_H
include <iostream>
include <string>

using namespace std;

class Base
{
public:
//constructor
Base(string mystring);

//Member Functions:
Base * ReturnPtrToANewBaseClassObject();//Create an object and return a pointer to it

private:

protected:

//Data Members common to all objects (abstract base class):
string _mystring;

}; ...

Hi there,

I am trying to read values from a .txt file using stringstreams and plan to enter the values into a map,

I am reading into a buffer, but it contains spaces and I believe a character which represent the end of line.

Here is my program so far:

[code]

include <map>
include <iostream>
include <fstream>
include <sstream>

using namespace std;

int main()
{
//I eventually plan to enter the values into a map
map<string, string> mapname;

//Ask for the filename to open
char fileName[20];
cout << "Enter the name of the .txt file that you would like to open (eg: file.txt) : " << endl;
cin >> fileName;

//create the fstream
ifstream in(fileName);

//create a stringstream object called buffer
stringstream buffer;

//read the file into the buffer
buffer << in.rdbuf();

//Now I want to split the buffer so it can be entered into a map, like a phone book

//close the connection to the .txt file 
in.close();

system ("pause");
return 0;

}
[/code]

Here is an example of file.txt:

[QUOTE]
A1 John Doe
A2 John Smith
[/QUOTE]

So I'm trying to put 'A2' into the key part of the map, and 'John Doe' into the mapped part of the map.

I'm trying to do it as simply as possible, just using the standard library.

Really appreciate any advice with this.

Thanks a lot :)

Thanks for the responses.

From my understanding, as I long as I am located within the protected directory structure, and I use an SSL connection for remote login, I am good to go.

I will not be adding any code for cookies or sessions. I don't know if .htaccess creates any, but I don't plan to.

Hi,

I have a web site.

On index.php I have a HTML link to admin/admincp.php

By simply adding a htaccess file to the directory 'admin', will the admin directory and it's contents be fully protected?

I only want it to be possible for me to access mysite.com/admin/admincp.php, because I am the administrator and will be adding records to a mysql database through a HTML form in it.

It works!

Thanks kireol ! :)

Program working now!

Hi,

I'm making a simple forum.

When a user register's, I trying to create their join date.

[code]
CREATE TABLE Users
(
userName varchar(15) NOT NULL,
registrationDate datetime default NULL
)
[/code]

and then have MySQL automatically set that value:

[code]
$sql = "INSERT INTO Users (userName, registrationDate)
VALUES ('".$username."' , '".NOW()."')";
[/code]

The program keeps failing though. when the PHP code is ran it says:

[QUOTE]Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING[/QUOTE]

Am I doing this right?

I think it may be my syntax, but I could be wrong.

Appreciate all help with this. :)

That's sweet.

Thanks ever so much for the help. I understand it now. yes it was the first time I'd ever tried to add a resource.

Real appreciated!

Thanks again :)

William Hemsworth commented: You're welcome (: +5

Thanks buddy :)

I got it to work, copy and pasted the .wav file into the Project's directory.

Used this code:
[code]

include <iostream>
include <windows.h>
include <mmsystem.h>
pragma comment(lib,"Winmm.lib")

using namespace std;

int main()
{
for( int a = 0;a<1;a++)
{
PlaySound(L"tone.wav", NULL, SND_FILENAME | SND_SYNC);
Sleep(3000);
}
return 0;
}
[/code]

and now it plays.

Shame though that I can't see the file in the Solution Explorer.

I tried your recommendation and it created a .rc file, but was trying to convert char* into ____,

Yes, i just want to add it as a resource, so it plays.

I can see an option for .bmp files, but nothing for .wav.

Thanks William!

I changed the line, but it still makes the same 'error/not found' sound.

I honestly think it doesn't now where to find the .wav file?

Its a 26 KB .wav file.

I need to add the .wav file to the project some how. It's on my Desktop right now.

Hi,

I am trying to a play a .wav file in a C++ program.

I think my code is OK, but when it plays, it plays the default windows 'error' sound, not my .wav file.

This is the program:

[code]

include <iostream>
include <windows.h>
include <mmsystem.h>
pragma comment(lib,"Winmm.lib")

using namespace std;

int main()
{
for( int a = 0;a<10;a++)
{
PlaySound((LPCWSTR)"tone.wav", 0, SND_LOOP|SND_ASYNC);
Sleep(1000);
}
return 0;
}
[/code]

How can i add the .wav file so it is found?

In the Visual Studio 2005 soulution explorer I right click on Resource Files>Add>Resource, but can't find an option for .wav.

Thanks for any help!