GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 13-Jun-2005, 00:36
nasaiya nasaiya is offline
New Member
 
Join Date: Jun 2005
Posts: 16
nasaiya is on a distinguished road

variables return to previous value after i try to set them


thanks for all the help you guys have givin me already, i am new to windows programming so please bear with my millions of posts...

i have defined a struct that is just a bunch of basic strings and i dynamically created an array of this struct. i am trying to allow the user to delete any one of the array locations (sorry i'm not as good as i should be at talking in c++) , anyway, i am doing this by just bumping up the values of each location starting with the one after the one to be deleted. this is where the problem is: for some reason when i change one of the variables, it immediatly resets itself to its original value. i am doing this all within a member function of the dialog where the info is displayed.

here is the function:
CPP / C++ / C Code:
void CCustDlg::OnDelete() 
{	
	int sel=(-1);
	
	POSITION p = m_list.GetFirstSelectedItemPosition();
	if (p!=NULL)
	{

		while (p)
		{
			sel = m_list.GetNextSelectedItem(p);
		}
	}
	if (sel==(-1))
	{
		MessageBox("YOU MUST SELECT A NAME BEFORE YOU CAN DELETE THE PERSON!!!","ERROR!",MB_OK);
	}
	else
	{
		CString str = "Are you SURE you want to delete: ";
		str += ccusts[sel].pname.c_str();
		CString hh;
		hh.Format("%d",sel);
		int nResp=MessageBox(str,"CONFIRMATION!",MB_YESNO);
		if (nResp==IDYES)
		{
			ccusts[sel].pname=ccusts[(sel+1)].pname;hh.Format("%d",sel);
			MessageBox(ccusts[sel].pname.c_str(),hh,MB_OK);
			ccusts[sel].padd=ccusts[(sel+1)].padd;hh.Format("%d",sel);
			MessageBox(ccusts[sel].pname.c_str(),hh,MB_OK);
			ccusts[sel].padd2=ccusts[(sel+1)].padd2;hh.Format("%d",sel);

//i know this only changes one of the array locations
//but i need to get this to work before i can do the rest

			ccusts[sel].pcity=ccusts[(sel+1)].pcity;
			ccusts[sel].pstate=ccusts[(sel+1)].pstate;
			ccusts[sel].pzip=ccusts[(sel+1)].pzip;
			ccusts[sel].pcountry=ccusts[(sel+1)].pcountry;
			ccusts[sel].pphone=ccusts[(sel+1)].pphone;
			ccusts[sel].pemail=ccusts[(sel+1)].pemail;
			ccusts[sel].bname=ccusts[(sel+1)].bname;
			ccusts[sel].badd=ccusts[(sel+1)].badd;
			ccusts[sel].badd2=ccusts[(sel+1)].badd2;
			ccusts[sel].bcity=ccusts[(sel+1)].bcity;
			ccusts[sel].bstate=ccusts[(sel+1)].bstate;
			ccusts[sel].bzip=ccusts[(sel+1)].bzip;
			ccusts[sel].bcountry=ccusts[(sel+1)].bcountry;
			ccusts[sel].bphone=ccusts[(sel+1)].bphone;
			ccusts[sel].bemail=ccusts[(sel+1)].bemail;
			ccusts[sel].sname=ccusts[(sel+1)].sname;
			ccusts[sel].sadd=ccusts[(sel+1)].sadd;
			ccusts[sel].sadd2=ccusts[(sel+1)].sadd2;
			ccusts[sel].scity=ccusts[(sel+1)].scity;
			ccusts[sel].sstate=ccusts[(sel+1)].sstate;
			ccusts[sel].szip=ccusts[(sel+1)].szip;
			ccusts[sel].scountry=ccusts[(sel+1)].scountry;
			ccusts[sel].sphone=ccusts[(sel+1)].sphone;
		
		  MessageBox("The selected person has been deleted!!!","",MB_OK);	
			Wfile();
				MessageBox(ccusts[sel].pname.c_str(),"",MB_OK);
			
			Rfile();
			MessageBox(ccusts[sel].pname.c_str(),"",MB_OK);
}
}
}

i have all those message boxes to show me what the value is at different points. This seems simple enough to me but i'm new to dynamic memory allocation so i might be missing something that has to do with that, but i really don't know.

the Rfile function simply creates the variables and reads the stuff from the file into the variables and then puts the information into the list control. the Wfile function just writes the info to a file and deletes the variables. (i put these two functions that so that the list control that i'm using to display the information would be updated).

please help if you have any ideas as to what could possibly cause variables to reset themselves to their original values when you try to change them, this makes no sense.
  #2  
Old 13-Jun-2005, 15:29
aie0 aie0 is offline
Member
 
Join Date: Dec 2004
Posts: 246
aie0 is a jewel in the roughaie0 is a jewel in the rough
If I am not wrong, you use a simple c-typed array for your "array".
Well, to avoid a lot of errors in the near future, from personal experience, use CArray - easy to create and maintain.
  #3  
Old 14-Jun-2005, 00:43
nasaiya nasaiya is offline
New Member
 
Join Date: Jun 2005
Posts: 16
nasaiya is on a distinguished road

hmmm


well i'm not exactly sure what that is so i'll just post the declaration , it is just a simple struct:

CPP / C++ / C Code:
struct custinf
{
	

	string	pemail;
	string  pphone;
	string	pcountry;
	string	pzip;
	string	pstate;
	string	pcity;
	string	padd2;
	string	padd;
	string	pname;
	string	bemail;
	string	bphone;
	string	bcountry;
	string	bzip;
	string	bstate;
	string	bcity;
	string	badd2;
	string	badd;
	string	bname;	
	string	sphone;
	string	scountry;
	string	szip;
	string	sstate;
	string	scity;
	string	sadd2;
	string	sadd;
	string	sname;
};

i just don't understand why the variables reset themselves. besides i didn't even get any errors
 
 

Recent GIDBlogMeeting the populace by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Things to Avoid in C/C++ -- gets() , Part 1 WaltP C Programming Language 5 21-Jun-2007 12:13
Problem with one variable bretter C++ Forum 1 16-May-2005 07:20
[Tutorial] Pointers in C (Part I) Stack Overflow C Programming Language 1 08-Apr-2005 18:35
C++ file I/O CronoX C++ Forum 36 09-Mar-2004 17:28

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:14.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.