|
I've confirmed that Yes / No works. Also True / False .... Seems maybe its case sensitive (?)
Just trying to keep the forces of entropy at bay
|
|
|
|
|
Hi RedZenBird,
Thank you very much for your help, it works great!
Many thanks,
Anh
|
|
|
|
|
Hi RedZenBird,
Thank you very much for your help, it works great!
Many thanks,
Anh
|
|
|
|
|
I've worked with both Access and SQL Server SQL statements and found a little inconsistency in the way that both platform represents a boolean value!
However I've found that FALSE is always represented as 0 (zero), and TRUE as any non-zero value. Access will sometimes store TRUE as -1.
So to query a boolean field I use :
"SELECT * FROM [Sample] WHERE [Logic]=0" // FALSE
"SELECT * FROM [Sample] WHERE [Logic]<>0" // TRUE
|
|
|
|
|
Hi,
I got help to find how it works, thanks for help! Please see the second Post of RedZenBird
Thanks,
|
|
|
|
|
My teacher says there isn't but...
There's got to be a better way to do this...
Organism aOrgArray[iColSize] = {Organism iNumChroms),Organism (iNumChroms),
Organism (iNumChroms),Organism (iNumChroms),Organism (iNumChroms),Organism (iNumChroms),
Organism (iNumChroms),Organism (iNumChroms),Organism (iNumChroms),Organism (iNumChroms),
Organism (iNumChroms),Organism (iNumChroms),Organism (iNumChroms),Organism (iNumChroms),
Organism (iNumChroms),Organism (iNumChroms),Organism (iNumChroms),Organism (iNumChroms),
Organism (iNumChroms),Organism (iNumChroms)};
iColSize = 20 for this prog
The constructor for class Organism takes an integer argument, iNumChroms, that has no default value. A default would be acceptable if it would help me clean up this ugly delcaration! What if it needed to be 1000!?
|
|
|
|
|
You've answered your own question. Provide a default constructor, and a method to set the number of Chromosomes. Then you can set them in a loop, no matter how many there are.
Or create them on the heap. Then you can call new on them in a loop and pass in your variable.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
I suppose you could do something like:
int i;
Organism aOrgArray[iColSize];
for(i = 0; i < iColSize - 1; i++)
aOrgArray[i] = Organism(iNumChroms);
Nick Parker
Not everything that can be counted counts, and not everything that counts can be counted. - Albert Einstein
|
|
|
|
|
Um...
Nick Parker wrote:
int i;
Why create this first, and why create it without initialising it ?
Nick Parker wrote:
Organism aOrgArray[iColSize];
Won't work, unless you mean the col size to be a constant that replaces this variable, which does not really exist
Nick Parker wrote:
for(i = 0; i < iColSize - 1; i++)
Even if the rest would work, this would leave the last item uninitialised.
Nick Parker wrote:
aOrgArray[i] = Organism(iNumChroms);
Won't work, the item already exists, except it doesn't, because no default constructor is available.
All of this would be possible if you created them on the heap, an array of Organism pointers, and aOrgArray[i] = new Organism(iNumChroms);.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Christian Graus wrote:
Nick Parker wrote:
int i;
Why create this first, and why create it without initialising it ?
I'm betting he's a C programmer who's never got used to this new fangled ability to declare variables anywhere you like (though I tend to prefer to declare all of my variables at the top, anyway, as it makes it much easier to see what the function's using)
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
I have to admit that conversely, when I had to start using straight C for Palm work, I had NO idea why my code would not compile when it was scattered with variable declarations.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Sheesh, I need to be careful when answering questions late at night and not fully qualifying what I meant.
Christian Graus wrote:
Why create this first, and why create it without initialising it ?
True, I could have just done for(int i = 0;.....
Christian Graus wrote:
Won't work, unless you mean the col size to be a constant that replaces this variable, which does not really exist
I was assuming this would be a constant.
Christian Graus wrote:
Even if the rest would work, this would leave the last item uninitialised.
Yeah, yeah, I was typing quick and the moon was out and .... you want more of an excuse?
Christian Graus wrote:
Won't work, the item already exists, except it doesn't, because no default constructor is available.
I was also assuming that he would add a default constructor as I believe you mentioned it in the above post.
Nick Parker
Not everything that can be counted counts, and not everything that counts can be counted. - Albert Einstein
|
|
|
|
|
Nick Parker wrote:
I was assuming this would be a constant.
Fair enough. It was not clear to me.
Nick Parker wrote:
I was also assuming that he would add a default constructor as I believe you mentioned it in the above post.
That was not clear to me, either.
Nick Parker wrote:
you want more of an excuse?
Not good enough mister !! Oh wait, it seems the latest reports indicate I am not perfect, either. Damn.......
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Christian Graus wrote:
Not good enough mister !! Oh wait, it seems the latest reports indicate I am not perfect, either. Damn.......
Wow, there is a report for these types of things? Is it automated? Where can I find this at?
Christian Graus wrote:
I am not perfect, either
Shh...we can keep it a secret and continue to fool them.
Nick Parker
Not everything that can be counted counts, and not everything that counts can be counted. - Albert Einstein
|
|
|
|
|
Damn Christain, calm down.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Thanks for your help guys..it seems so obvious now..
|
|
|
|
|
*grin* To be honest, I saw the response under mine, thought 'that can't possibly work', threw it into the compiler to make sure I was right, then worked my way through the compiler errors.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Damn ..I still can't get it to compile.. If you can tell me what the heck I'm doing wrong I'll buy you lunch..Here's part of what's in main..
const int iColSize = 20;
//Seed rand function
srand((unsigned)time(NULL));
int iNumChroms;
cout << "Artificial Life Simulator 1.0\n\n"
<< "Enter the number of pairs of chromosomes in each organism: ";
cin >> iNumChroms;
for(int i = 0; i < iColSize; i++)
Organism aOrgArray[i] = {new Organism (iNumChroms)};
And this is my Organism class definition:
#ifndef ORGANISM_H
#define ORGANISM_H
class Organism {
friend class Chromosomes;
public:
//Constructor: iChromo is number of chromosome pairs
Organism(int iChromo = 1);
~Organism();
//Calc fitness value of single organism called on
void calcFitVal();
//Prints fitness value of single organism called on
void printFitVal() const;
//Mutate a random chromosome
void mutate();
private:
//Fitness value of each organism
int iFitVal;
//Number of pairs of chromosomes in each organism
const int iNumOfChromoPairs;
//Pointer to array of Chromosomes (chromosome pairs)
Chromosomes* pChromoArray;
};
#endif
And if this helps here are the member functions:
// File: Organism.cpp
// Defines member functions of class Organism
#include <iostream>
#include "Organism.h"
#include "Chromosomes.h"
using std::cout;
using std::endl;
Organism::Organism (int iChromo) : iNumOfChromoPairs (iChromo)
{
//Declare array of chromosome for each organism
pChromoArray = new Chromosomes[iNumOfChromoPairs];
}
Organism::~Organism()
{
//Release memory to the O.S.
delete [] pChromoArray;
}
void Organism::calcFitVal()
{
//Set fitness value to 0 on organism called
iFitVal = 0;
//Loop counts number of true chromosomes in each organism
for(int i = 0; i < iNumOfChromoPairs; ++i) {
if(pChromoArray->bChrom0 == true)
++iFitVal;
if(pChromoArray->bChrom1 == true)
++iFitVal;
++pChromoArray;
}
//Move pointer back to the beginning of the array
for (; i != 0; --i)
--pChromoArray;
}
void Organism::printFitVal() const
{
//Print fitness value for each organism
cout << iFitVal << endl;
}
void Organism::mutate()
{
//Pick a random pair of chromosomes in the organism
int iRanPair = rand() % iNumOfChromoPairs;
//Pick a random chromosome in that pair and mutate it
if(rand() % 2 == 0){
if(pChromoArray[iRanPair].bChrom0 == true)
pChromoArray[iRanPair].bChrom0 = false;
else
pChromoArray[iRanPair].bChrom0 = true;
}
else {
if(pChromoArray[iRanPair].bChrom1 == true)
pChromoArray[iRanPair].bChrom1 = false;
else
pChromoArray[iRanPair].bChrom1 = true;
}
}
|
|
|
|
|
student() wrote:
for(int i = 0; i < iColSize; i++)
Organism aOrgArray[i] = {new Organism (iNumChroms)};
You seem to be trying to impliment what Nick gave you rather than what I said. With all due respect to Nick, in this case he is mistaken, this code will not work. I don't see where you have actually created this array, for starters, and to assign values like this you'd need to be using the heap.
Organism * aOrgArray = new Organism [iColSize];
for (int i = 0; ....)
aOrgArray[i] = new Organism(iNumChroms];
don't forget delete [] aORgArray; at the end if you do it this way. The other is to provide a constructor that takes no arguments, and then you can do this:
Organism [20] aOrgArray; // A const int value may work, I am not sure.
for (int i = 0;.....
aOrgArray[i].SetNumberChroms(iNumChroms);
Method B is neater IMO.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Christian..
Method B works perfectly...and I could even use a const although I had to do this:
Organism aOrgArray [20];
instead of
Organism [20] aOrgArray;
but that's no biggie.
Damn...now I owe you lunch...
|
|
|
|
|
student() wrote:
Method B works perfectly...
great !!!
student() wrote:
and I could even use a const
Cool - I wasn't sure, I gave it about a 50/50
student() wrote:
although I had to do this
Yeah, the syntax did not look right when I typed it, but it was 4:30 am and I was burning a DVD, which means I cannot really fire up a compiler because the PC is so slow.
student() wrote:
Damn...now I owe you lunch...
See you at 12:00..... :P
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
I have some questions regarding Arrays of Controls. I have two arrays declared as follows:
<br />
#define MAX_NUMBER 10<br />
<br />
CStatic m_cStaticArray[MAX_NUMBER];<br />
CString m_strStringArray[MAX_NUMBER];<br />
Now what I would like to do is be able to set the m_strStringArray to a value and then use DDX to update the Static control that relates to it. My problem is that the application may not actuall use all 10 of the CStatic controls. Depending on the user it may only use 1, none, some or all of them. The controls are created depending on certain variables that occur during run time. I have defined all the IDs ahead of time in the Resource.h file for the static controls.
Do I have to perform the movement of the data from the CString variable to the CStatic control manually or can I still use DDX in some way to automate this?
As a side question that I just thought of, if I override the OnHScroll method of a CScrollView derived class do I have to then perform all the various functions required to get the view to scroll or can I do just a small amount of data manipulation and still let the CScrollView handle moving the view?
Thanks for any help,
-Eric
|
|
|
|
|
You should be able to do this with the DDX mechanism. You need to add the entries to map them manually:
DDX_Control(pDX, IDC_DROP_GRAPHS, m_DropGraphs);
DDX_Control(pDX, IDC_RESULTS, m_lcResults);
DDX_Control(pDX, IDC_PKA_LIST, m_lcpKaList);
DDX_Control(pDX, IDC_GRAPH, m_YSExtrapolation);
for (int i = 0 ; i < number_of_controls ; i++)
{
DDX_Control(pDX, IDC_OF_FIRST_STATIC + i, m_cStaticArray[i]);
}
Just don't put your code inside the AFX_DATA_MAP tags otherwise class wizard will complain.
Roger Allen
Sonork 100.10016
In case you're worried about what's going to become of the younger generation, it's going to grow up and start worrying about the younger generation. - Roger Allen, but not me!
|
|
|
|
|
Roger Allen wrote:
<br />
DDX_Control(pDX, IDC_DROP_GRAPHS, m_DropGraphs);<br />
DDX_Control(pDX, IDC_RESULTS, m_lcResults);<br />
DDX_Control(pDX, IDC_PKA_LIST, m_lcpKaList);<br />
DDX_Control(pDX, IDC_GRAPH, m_YSExtrapolation);<br />
for (int i = 0 ; i < number_of_controls ; i++)<br />
{<br />
DDX_Control(pDX, IDC_OF_FIRST_STATIC + i, m_cStaticArray[i]);<br />
}<br />
Just don't put your code inside the AFX_DATA_MAP tags otherwise class wizard will complain.
Thanks for the help, but I still get an assertion error on the UpdateData() method in my OnInitialUpdate function.
Here is what my DoDataExchange looks like:
<br />
void CMyView::DoDataExchange(CDataExchange *pDX)<br />
{<br />
for(int i = 0; i < MAX_USERS; i++)<br />
{<br />
DDX_Text(pDX, IDC_STATIC_ONE + i, m_strUsers[i]);<br />
}<br />
}<br />
Any other thoughts?
-Eric
|
|
|
|
|
You should only call DDX_Text on an item is you actually create it. Thinking on it, you may need to move this code into your OnInitDialog() as the DDX stuff gets called for you by the CDialog::OnInitDialog() implementation which will be before you create your controls properly (unless you do it in the WM_CREATE message handler).
Roger Allen
Sonork 100.10016
In case you're worried about what's going to become of the younger generation, it's going to grow up and start worrying about the younger generation. - Roger Allen, but not me!
|
|
|
|
|