|
I've been struggling with this for a while. I'm hoping someone can help.
Let's say I have a standard set of commands, namely, to write all changes to a text file. Now I want to repeatedly implement this block of code in my program without having to copy and paste the entire block of code. How can this be done?
This is an example of the code
StreamWriter^ rewrite = gcnew StreamWriter(file_path);
for (int i=0; i < listView1->Items->Count; i++)
{
rewrite->Write(listView1->Items[i]->Text);
String^ price = listView1->Items[i]->SubItems[1]->Text->Remove(0,2);
rewrite->Write(" ["+price+"]");
rewrite->WriteLine(" #"+listView1->Items[i]->SubItems[2]->Text+"##");
}
rewrite->Close();
Is it possible to store it in a dll file and call it from the code? Is it possible to store this code in another form or resource in the current project and call it as a function? How would I go about doing that?
If at all possible, take me through it slow, I'd really like to understand this concept.
Thank You for your time
Nokoff
|
|
|
|
|
Errr...
Why don't you use a function ? I don't really see what you want to do by using that in a dll.
|
|
|
|
|
I was hoping to find out how to declare the function in another c++ file or header and reference to it from the main form to make things a bit neater.
|
|
|
|
|
Declare the function prototype (which is just the return value, the function name and its parameter, with a ';' after it) in a header file (.h) and put the definition in a source file (.cpp).
Then include the header file in the .cpp file in which you want to use the function.
Again, this is basic stuff and you should first learn the basics. Again, don't take it bad, that is not my intention to offend you, but just to give you some suggestions.
Hope this helps.
|
|
|
|
|
Everything looks ok but now it doesn't pick up any of the objects used in the main form. In my function definition, it throws errors that there are undeclared identifiers (namely, all of the objects stated). I've added all the includes in all the files. What could be wrong?
-- modified at 15:07 Thursday 13th April, 2006
|
|
|
|
|
Hi there, I need some help pertaining to a text file I'm using. No use explaining now, I'll do it as I go along.
Here is an example of my text file:
Sasko Sam Seedloaf 800gr [6.86] #3##<br />
Elite Gouda Cheese 500gr [32.90] #5##<br />
Wholegrain [5.00] #6##<br />
Wholewheat [6.00] #7##<br />
Coke [7.00] #0##
If i break it down, using the first line as an example, each line contains:
A product: "Sasko Sam Seedloaf 800gr"
A price: "6.86"
A quantity "3".
I am using a groupbox, with all the product names loaded into it so I have the string to search for. I want to modify the quantity value.
So for example, I need to be able to search through the text file, to find "Wholegrain", which in this case is on the 3rd line. And change the quantity value from '6' to '4'. Any ideas on how to do this?
I have so far,
StreamReader^ din = File::OpenText(file_path);
<br />
String^ all_text = din->ReadToEnd();
<br />
int place_holder = all_text->IndexOf(products_in_stock->Text)
Any help would be much appreciated
Thank you
Nokoff
|
|
|
|
|
|
But this code is accepted and executed in VC++ is it not? If not, how would I go about doing something like this in VC++?
|
|
|
|
|
Managed C++ is a microsoft product (targetted for .NET framework), ,so, of course it compiles with VC++, but i'd say more, it compiles only with VC++ !!!
but the fact is that MC++ is a pretty different language, even thoug it is based on the C++ syntax at its beginning, codeproject has 2 different forums, one for C++, VC++, MFC, and all that unmanaged stuff, and another for MC++, C++/CLI...
hope you better understand what i mean now.
|
|
|
|
|
Thanks for the info. Should I just post again in the correct forum or can someone not just move this post?
|
|
|
|
|
you better repost it on the correct place
|
|
|
|
|
every employee in a company reports to 1 person above him. The leader's cost of company is equal to his salary plus the cost of comapny of all his subordinates. write a program to find the cost of company of each employee. A program in a either C/C++/Java. Plz help me
Sat Shri Akal
Harsimran Singh Bhatia
|
|
|
|
|
Is it an assignment for me??
|
|
|
|
|
Thank You for your prompt reply. This is a question which has made me mad. Can U find the solution or atleast give me some hint of it. Please try it out. This is one of the questions of a company's placement paper.
Sat Shri Akal
Harsimran Singh
|
|
|
|
|
learn the forum's guidelines[^] first... we do not do homeworks here
|
|
|
|
|
Home-Works !!!!! Sir, this question is rated as one of the good questions !!! I dont ask U to do this but just ask to think over it and give hints. Sorry for asking !!!! Bye !!
|
|
|
|
|
First hint:
Start by yourslef and when you are stuck, ask specific questions.
Otherwise how do we know where you are stuck ? What is the problem ?
|
|
|
|
|
|
This was a specific question and not the assignment. And I dont think U even tried reading the question. You think its very easy, huh !! This was one of the questions asked by company in the recruitment procedure. And most of the students were not even able to start this question. Its ok sir if U are not interested and just sitting here for passing your time !! But stop discouraging others who want to use their grey matter !!!! I hope I have made myself clear.
I know after this discussuion I may be kicked out of the group. If any one in the visitors to my query feels interested and can help me out, mail me at harsimran.bhatia@gmail.com .
Bye and take care
Sat Shri Aakal
Harsimran Singh Bhatia
|
|
|
|
|
man, don't talk abou me and what i do at codeproject. you don't know anything about me, and YOU[^] are not in position to judge me.
|
|
|
|
|
Hi v2.0,
Whats the matter
|
|
|
|
|
Hi
You can create a Tree for achieving this so that if there is a node underneath you can add the total of all nodes to the parent .
This will be for the person who is the leader.
Similarly for the person under the leader check for the nodes that are lying underneath and then add the total of all those nodes
It will be easier for you to find a solution if you go according to the iterative method rather than moving on with the more conventional solution of iterating with each node in a different manner.
Vision is Always important and so is your ATTITUDE.
Wishes.
Anshuman Dandekar
|
|
|
|
|
hi all,
i want to adjust the progress bar step size according to the reading of the Records from the Database. If i read Three Records then the Progressbar steps accordingly. if i read 1000 records then the progress bar must steps accordingly. please give a snippet of the code for this. urgent.
thanks,
uday.
uday kiran
|
|
|
|
|
Try this:
void setRange(CProgressCtrl* pWnd, int nLower, int nUpper, int nStep)<br />
{<br />
ASSERT(-0x7FFFFFFF <= nLower && nLower <= 0x7FFFFFFF);<br />
ASSERT(-0x7FFFFFFF <= nUpper && nUpper <= 0x7FFFFFFF);<br />
pWnd->SendMessage(PBM_SETRANGE32, (WPARAM)nLower, (LPARAM)nUpper);<br />
pWnd->SetStep(nStep);<br />
}
Hope this help
Abyss
|
|
|
|
|
Abyss wrote: pWnd->SendMessage(PBM_SETRANGE32, (WPARAM)nLower, (LPARAM)nUpper);
Why not call SetRange32() directly?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|