C++ var "casting" by name!

Discussion in 'C++' started by xan8ter, Feb 13, 2008.

  1. xan8ter

    xan8ter New Member

    Joined:
    Feb 13, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    C++ Programmer
    Location:
    Canada
    I have a for loop
    and I have 25 var named Case_P1 to Case_P25 in type double
    I wanna do it simple as i can i just want show this var value in 25 TextBox named
    ECase_1 To ECase_25:
    So, i tought it was :
    Code:
    for (int i =1;i<=25;i++)
    {
    
    char *name= ("CaseP" + String(i)).c_str();
    double *NV = reinterpret_cast<double*> (name);
    E_Case_(i)->Text = String(*NV);
    // I want this Case_P(i); Not supposed to be hard?!?!
    //Something like that!
    E_Case_(i) = Case_P(i);
    }
    
    
    So, i can't use vector or tabs, is an already implemented code! i can't change var types.
    thx
    Thx you !

    :):):)
     
    Last edited by a moderator: Feb 14, 2008
  2. sanjaik

    sanjaik New Member

    Joined:
    Sep 23, 2006
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Mumbai
    Code:
    void connectionDlg::OnBtnConnect() 
    {
    	int conResult;
    	int pos;
    	int oldlen; 
    	int newlen;
    	
    	CString ConnectionString,Msg;
    	CString IpAddress ,Directory,Password,UserName;
    
    	char tmpLastDrive[100]	=	{""};
    	char strmsg[100]		=	{""};
    	char tmp;
    	
    	UpdateData(true); //retrieve data 
    
    	for( TCHAR cLetter = _T('A'); cLetter <= _T('Z'); cLetter++ )
    	{
    		CString sDrive = cLetter;
    		sDrive += _T(":");	
    		
    		/** Determine Whether a disk drive is removal or fix */
    		UINT nType = GetDriveType( sDrive + _T("\\") );
    		
    		/**  GetDriveType fuction Retuen values Drive types 		
    			DRIVE_UNKNOWN     0
    			DRIVE_NO_ROOT_DIR 1
    			DRIVE_REMOVABLE   2
    			DRIVE_FIXED       3
    			DRIVE_REMOTE      4
    			DRIVE_CDROM       5
    			DRIVE_RAMDISK     6
    		*/
    	
    		if( DRIVE_REMOVABLE <= nType && nType <= DRIVE_RAMDISK )
    		{
    			strLastMappedDriveOrHardDisk = sDrive;
    		}
    	}
    
    	/**
     	 *	If Connect Dialog is called from withing get path then,
    	 *	maintain the remote drive string for insertions in 
    	 *	ID_CMB_MAPPED_DRIVES combobox
    	 */
    
    	if(!bConnectDlgCalledFromGetPath)
    	{
    		ConnectionString= "net use ";
    		ConnectionString = ConnectionString + " * \\\\";
    		ConnectionString = ConnectionString + m_strIpAddress +"\\" +  m_strDirectory + " ";
    		ConnectionString = ConnectionString + m_strPassword + " ";
    		ConnectionString = ConnectionString + "/user:"+m_strUserName;
    	}
    	else
    	{
    		strcpy(tmpLastDrive,strLastMappedDriveOrHardDisk);
    		tmp = tmpLastDrive[0];
    		tmp ++;
    		
    		ConnectionString= "net use ";
    		ConnectionString = ConnectionString + _T(tmp) + ": \\\\" ;
    		ConnectionString = ConnectionString + m_strIpAddress +"\\" +  m_strDirectory + " ";
    		ConnectionString = ConnectionString + m_strPassword + " ";
    		ConnectionString = ConnectionString + "/user:"+m_strUserName;
    	}
    
    	/**
    	 *	Command To Mapping NetWork Drive 
    	 *	net use g: \\192.9.202.113\d$ versa2001 /user:administrator 
    	 */
    
    	/** Fire Network mapping Command */
    	conResult = system(ConnectionString);
    	if(conResult == 0)
    	{
    		if(bConnectDlgCalledFromGetPath)
    		{
    			strLastMappedDriveOrHardDisk = _T(tmp) ;
    			strLastMappedDriveOrHardDisk = strLastMappedDriveOrHardDisk + _T(":");
    			gMappedDrives[++MappedDriveCounter] = strLastMappedDriveOrHardDisk;
    			bInsertIntoComboBox = true;
    		}
    		
    		Msg = "Connection successful";
    		AfxMessageBox(Msg);
    	
    		sprintf(strmsg,"Drive Number : %d is Mapped Successfully",NoOfMappedDrives);
    		m_strMessage = CString(strmsg);
    
    		CEdit * ce = (CEdit *) GetDlgItem(IDC_TXT_IP_ADDRESS);
    		ce->SetFocus();
    		m_strIpAddress =	"";
    		m_strDirectory =	"";
    		m_strUserName =		"";
    		m_strPassword =		"";
    		UpdateData(false);
    	}
    	else 
    	{
    		/**
    		 *	Sometime if d$ is mapped and user puts d then 
    		 *	The local device name is already in use 
    		 */
    		pos = m_strDirectory.ReverseFind('$');
    		if(pos == -1)
    			m_strDirectory = m_strDirectory + "$";
    		else
    		{
    			oldlen = m_strDirectory.GetLength();
    			newlen = oldlen-1;
    			
    			m_strDirectory.GetBufferSetLength(newlen);
    		}
    			
    		/** done only if dlg is called  from dlggetpath */
    		strcpy(tmpLastDrive,strLastMappedDriveOrHardDisk);
    		tmp = tmpLastDrive[0];
    		tmp ++;
    		
    		ConnectionString= "net use ";
    		ConnectionString = ConnectionString + _T(tmp) + ": \\\\" ;
    		ConnectionString = ConnectionString + m_strIpAddress +"\\" +  m_strDirectory +" ";
    		ConnectionString = ConnectionString + m_strPassword + " ";
    
    		ConnectionString = ConnectionString + "/user:"+m_strUserName;
    		
    		conResult = system(ConnectionString);
    		if(conResult == 0)
    		{
    			if(bConnectDlgCalledFromGetPath)
    			{
    				strLastMappedDriveOrHardDisk = _T(tmp) ;
    				strLastMappedDriveOrHardDisk = strLastMappedDriveOrHardDisk + _T(":");
    				gMappedDrives[++MappedDriveCounter] = strLastMappedDriveOrHardDisk;
    				bInsertIntoComboBox = true;
    			}
    
    			Msg = "Connection Successful";
    			AfxMessageBox(Msg);
    		}
    		else
    		AfxMessageBox("There was an error in Connecting");
    	}
    }
     
    Last edited by a moderator: Feb 20, 2008

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice