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 21-Feb-2005, 19:28
shinyhui shinyhui is offline
Awaiting Email Confirmation
 
Join Date: Feb 2005
Posts: 38
shinyhui is on a distinguished road

Limit combo box choice according to database created in folder


i creating database by month, so every month i got a database to store the data.. in my application i would like to have a combo box to select which database i would like to display according to month and year...

how can i code my combo box to only display database that have created in my folder? example: in my folder i have Jan05, Feb05 and Mar05 database so my combo box only have the choice of Jan05, Feb05 and Mar05 for me to selected.
  #2  
Old 21-Feb-2005, 20:20
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough
i guess you are using MFC, so you should use CFileFind class to get the file names in your folder and display it in the combo box. since I currently don't hav a VC++6.0, so can't post the exact program that works, but here is a guide...


CFileFind has the member function to find filed in a folder based on the file name pattern passed to the function, for example:

FindFile(_T("*.txt"))) will find file with '.txt' extensions, so in your case,
FindFile(_T("*.mdb"))) will find files with the mdb extensions for the data base, or if you your data base is of other type, then use accordingly..

here is a code saple which gts all the files in a directory:

CPP / C++ / C Code:
   CFileFind finder;
   BOOL bWorking = finder.FindFile("*.*");
   while (bWorking)
   {
      bWorking = finder.FindNextFile();
      CString MyFileName =   finder.GetFileName() ;
      // then insert the filename to your combo box
   }

the above sample code gets all the file, so do a litle editing so that it gets only the database file, i use '.mdb' here for my database:

CPP / C++ / C Code:
   CFileFind finder;
   BOOL bWorking = finder.FindFile("*.mdb");
   while (bWorking)
   {
      bWorking = finder.FindNextFile();
      CString MyFileName =   finder.GetFileName() ;
      // then insert the filename to your combo box
   }

BTW: if you want to post MFC related question, plase post in the MFC or Visual C++ Forum.
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
  #3  
Old 21-Feb-2005, 20:38
shinyhui shinyhui is offline
Awaiting Email Confirmation
 
Join Date: Feb 2005
Posts: 38
shinyhui is on a distinguished road
Quote:
Originally Posted by Max Payne
i guess you are using MFC, so you should use CFileFind class to get the file names in your folder and display it in the combo box. since I currently don't hav a VC++6.0, so can't post the exact program that works, but here is a guide...


CFileFind has the member function to find filed in a folder based on the file name pattern passed to the function, for example:

FindFile(_T("*.txt"))) will find file with '.txt' extensions, so in your case,
FindFile(_T("*.mdb"))) will find files with the mdb extensions for the data base, or if you your data base is of other type, then use accordingly..

here is a code saple which gts all the files in a directory:

CPP / C++ / C Code:
   CFileFind finder;
   BOOL bWorking = finder.FindFile("*.*");
   while (bWorking)
   {
      bWorking = finder.FindNextFile();
      CString MyFileName =   finder.GetFileName() ;
      // then insert the filename to your combo box
   }

the above sample code gets all the file, so do a litle editing so that it gets only the database file, i use '.mdb' here for my database:

CPP / C++ / C Code:
   CFileFind finder;
   BOOL bWorking = finder.FindFile("*.mdb");
   while (bWorking)
   {
      bWorking = finder.FindNextFile();
      CString MyFileName =   finder.GetFileName() ;
      // then insert the filename to your combo box
   }

BTW: if you want to post MFC related question, plase post in the MFC or Visual C++ Forum.

if MyFileName = abc_Jan05.mdb
but i just want Jan05 show in my combo box how can i limit it?
  #4  
Old 21-Feb-2005, 21:58
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough
Quote:
Originally Posted by shinyhui
if MyFileName = abc_Jan05.mdb
but i just want Jan05 show in my combo box how can i limit it?

that you need to chop the string your self...
is all your files would hav the same filename format, like the above 'abc_Jan05.mdb'??

the a litle CString oprations could do what you want:

CPP / C++ / C Code:
CString strAfter;
CString strFileName = "abc_Jan05.mdb";

int nLeft = strFileName.Find('_');
int nRight = strFileName.Find('.');

strAfter = strFileName.Mid(nLeft,nRight);


strAfter would have 'Jan05'..

hope that helps...
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
 
 

Recent GIDBlogProblems with the Navy (Officers) 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
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 11:28

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

All times are GMT -6. The time now is 03:19.


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