Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 19th, 2006, 7:59 AM   #11
ChiHappens
Programmer
 
ChiHappens's Avatar
 
Join Date: Sep 2005
Location: Brevard, NC
Posts: 35
Rep Power: 0 ChiHappens is an unknown quantity at this point
Send a message via MSN to ChiHappens
HEre is a node class i just made:

public class ListNodeClass
{
private int ItemValue;
private string ItemText;
public ListNodeClass()
{
}
public ListNodeClass(int Value, string Text)
{
ItemValue = Value;
ItemText = Text;
}
public int Value
{
get
{
return ItemValue;
}
set
{
ItemValue = value;
}
}
public string Text
{
get
{
return ItemText;
}
set
{
ItemText = value;
}
}

}

and here is how you can use it:
System.Collections.ArrayList Nodes = new ArrayList();
for(int n=1;n<11;n++)
{
ListNodeClass NewNode = new ListNodeClass((n*10),"Item " + n.ToString());
Nodes.Add(NewNode);
}
lblItem->Text = ((ListNodeClass)Nodes[0]).Value.ToString();
txtItem->Text = ((ListNodeClass)Nodes[0]).Text;

Hope this helps,
Chi
__________________
http://www.starshipcombatsimulator.com
They mostly come at night...mostly.
ChiHappens is offline   Reply With Quote
Old Apr 19th, 2006, 8:00 AM   #12
InfoGeek
Professional Programmer
 
InfoGeek's Avatar
 
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4 InfoGeek is on a distinguished road
You forgot the code tags, buddy!
__________________
PFO - My daily dose of technology.
InfoGeek is offline   Reply With Quote
Old Apr 19th, 2006, 8:14 AM   #13
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Purdy, ain' it?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Apr 19th, 2006, 8:56 AM   #14
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Quote:
Originally Posted by DaWei
Purdy, ain' it?
What's purdy mean? I can't find it in the dictionary.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Apr 19th, 2006, 9:01 AM   #15
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
Southerner's way of saying pretty.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Apr 19th, 2006, 9:04 AM   #16
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,223
Rep Power: 5 grumpy is on a distinguished road
Either that, or purdy was what Tweety called Sylvester.
grumpy is offline   Reply With Quote
Old Apr 19th, 2006, 10:28 AM   #17
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
ChiHappens, that's C#, not C++ .NET. There's a difference, I'm afraid.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Apr 21st, 2006, 12:58 AM   #18
Twilight
Programmer
 
Join Date: Apr 2006
Location: Calgary, Alberta
Posts: 67
Rep Power: 3 Twilight is on a distinguished road
Ok, well, I still don't have an answer to my rather simple problem. I had VC++ make me a form object, with the corresponding Form1.h file.

I then went into the main .cpp file, and tried trying to access an object on the form, namely lblTotal, a label object. I reached the current mess I have now by randomly changing things:

int main(array<System::String ^> ^args)
{
	// Enabling Windows XP visual effects before any controls are created
	Application::EnableVisualStyles();
	Application::SetCompatibleTextRenderingDefault(false); 

	// Create the main window and run it
	Application::Run(gcnew Form1());
	(Form1::lblTotal)::Label::Text::set("some text");
        // Form1::lblTotal->Text = and such also won't work.
	return 0;
}

And then I get the following errors:

.\Till Program.cpp(19) : error C2143: syntax error : missing ';' before 'System::Windows::Forms::Label::Text::set'
.\Till Program.cpp(19) : error C2597: illegal reference to non-static member 'TillProgram::Form1::lblTotal'
.\Till Program.cpp(19) : error C2352: 'System::Windows::Forms::Label::Text::set' : illegal call of non-static member function

Somebody mind telling me just how I get at form objects?
Twilight is offline   Reply With Quote
Old Apr 21st, 2006, 1:26 AM   #19
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
The Run method of application doesn't return until the application has finished anyway, so you can't execute code after the Run method and expect that the form is still around.
If you wanted to access the form fields from somewhere else (e.g. another form), then you could pass the form value to that other form. Something like:

	// Create the main window and run it
        Form1 ^newForm1 = gcnew Form1();
        newForm1->lblTotal->Text = "hello";
        Application::Run(newForm1);

Note that you would have to change the lblTotal field to "public" in Form1
The Dark is offline   Reply With Quote
Old Apr 21st, 2006, 1:33 AM   #20
Twilight
Programmer
 
Join Date: Apr 2006
Location: Calgary, Alberta
Posts: 67
Rep Power: 3 Twilight is on a distinguished road
Ah, so ok, so I just have to do all that stuff from within Form1.h. Which leads me to my next question:

Now from within Form1.h, on a certain button click, I want to read the text inside of txtItem, a standard textbox. I tried this:

txtItem->Text = "0";
string current;
current = txtItem->Text;

but got these rather long errors:
c:\documents and settings\sam\my documents\visual studio 2005\projects\till program\till program\Form1.h(469) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'System::String ^' (or there is no acceptable conversion)
        C:\Program Files\Microsoft Visual Studio 8\VC\include\xstring(875): could be 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(const std::basic_string<_Elem,_Traits,_Ax> &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>,
            _Ax=std::allocator<char>
        ]
        C:\Program Files\Microsoft Visual Studio 8\VC\include\xstring(880): or 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(const _Elem *)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>,
            _Ax=std::allocator<char>
        ]
        C:\Program Files\Microsoft Visual Studio 8\VC\include\xstring(885): or 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(_Elem)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>,
            _Ax=std::allocator<char>
        ]
        while trying to match the argument list '(std::string, System::String ^)'

Care to tell me how I should be doing it?

Last edited by Twilight; Apr 21st, 2006 at 1:45 AM.
Twilight is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:43 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC