|
Well in my table there are suppose to be 5 columns. Which will look like this
Num Name I/C Group Week
Week 1 Week 2 Week 3
|
|
|
|
|
tanchinchee wrote: Well in my table there are suppose to be 5 columns.
So why the two rows?
In any case, as Maximilien has already suggested, you need a way of delimiting each column with something other than a space. Sans that, it's not possible to differentiate between a space between columns and a space within a column.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Opps sorry...plz omit the second row...
|
|
|
|
|
Hi, i have a weird problem i can't seem to find the source of the problem.
I have an edit box with a button to allow browsing for file. When i debug, i found out that under outputdata>_Fb>_Str, _Str value is 0x00000000 {???}. This causes the file unable to open. Is the problem lies in any of the functions? Can anyone help me to explain what may cause this problem? Below are the codes and any replies or advice is highly appreciated:
void MyDlg::OnBrowse()
{
OPENFILENAME openfile;
openfile.lStructSize=sizeof(OPENFILENAME) ;
openfile.hwndOwner=AfxGetApp()->m_pMainWnd->m_hWnd;
openfile.lpstrFilter="Text Files (.txt)\0*.txt\0All Files (*.*)\0*.*\0";
UpdateData();
openfile.lpstrInitialDir=m_binfile;
openfile.lpstrTitle="Specify file";
openfile.lpstrCustomFilter=NULL;
CString ext=m_binfile.Right(3);
ext.MakeUpper();
openfile.nFilterIndex=1;
CString binfile=m_binfile;
binfile=binfile.Mid(binfile.ReverseFind('\\')+1);
char file[MAX_PATH];
file[0]=0;
strcpy(file,binfile);
openfile.lpstrFile=file;
openfile.nMaxFile=MAX_PATH;
openfile.lpstrFileTitle=NULL;
openfile.Flags=OFN_HIDEREADONLY;
openfile.nFileOffset=0;
openfile.nFileExtension=0;
openfile.lpstrDefExt=ext;
openfile.lCustData=0;
if (GetOpenFileName(&openfile))
{
m_binfile=file;
UpdateData(FALSE);
OnLoad();
}
}
void CICTesterDlg::OnLoad()
{
UpdateData();
CString file;
file="abc.txt";
std::ifstream outputdata;
outputdata.open(file), ios::in);
if ( !outputdata.is_open() )
{
MessageBox(_T("Unable to open file!"),_T("WARNING"),MB_ICONEXCLAMATION);
return;
}
outputdata.close();
}
|
|
|
|
|
cyn8 wrote: When i debug, i found out that under outputdata>_Fb>_Str, _Str value is 0x00000000 {???}. This causes the file unable to open.
I don't see any code like this. What am I missing?
This is the file open code I see:
CString file;
file="abc.txt";
std::ifstream outputdata;
outputdata.open(file), ios::in);
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
_Str can be seen in the debug window. It is under the outputdata variable. Besides that, is OnBrowse function lacking of any command. The file can't open whenever the OnBrowse function is used.
|
|
|
|
|
After a successful GetOpenFileName call, what is in your "file" (openfile.lpstrFile) array?
You copy it to another variable like this:
m_binfile=file;
but your code sample trie to open a different file.
???
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
actually i modify the code pasted here as the original code is too long. The file i open in OnBrowse is different from the one in Onload. However, i think the OnBrowse function somehow affect the opening of the file in OnLoad. This is because, if i didn't clicked on OnBrowse before i clicked on Onload, the file can be open without error. But i don't understand why this is happening...please help...it's urgent..Thank you
|
|
|
|
|
cyn8 wrote: ...please help...it's urgent..
If the file open is failing then the pathname you are passing is invalid.
That's something you'll have to check in the debugger.
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I've check the path name and it is correct.Is the method use in OnBrowse affect anything in opening other files? Because when OnBrowse button has been click and the 'Open' button is clicked, other method(by selecting the file specified in a combobox) which has no problem before the browse button is clicked, is unable to open the file.
|
|
|
|
|
Other than changing the current directory, I don't know how the openfilename dialog can effect
opening a file.
Are you supplying a full pathname or just a filename to open?
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Just the file name to open. I put the file at same folder as the .exe file. So it should be able to open.
|
|
|
|
|
But what argument is being passed to the ifstream constructor? Don't assume...know.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
cyn8 wrote: I put the file at same folder as the .exe file. So it should be able to open.
Not true. Just to make sure, I just tried it.
That works when loading DLLs with LoadLibrary but not files. You'll need to get the exe's folder
and append it if you want to do that (or set the current working directory to it). See
the "GetModuleFileName" API.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
the file that i want to open is a *txt file. The .exe file that i meant is the file to start the dialog application. Sorry for the misunderstanding.
|
|
|
|
|
Right - I'm following
You still need a valid path though (either explicit or set with SetCurrentDirectory)!
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
May i know why when i directly click on OnLoad, the file can be open without any errors. But, after the OnBrowse button has been click even once, opening the file directly through the OnLoad button will create error? I'm confused...
|
|
|
|
|
Because you've messed something up in memory. Since you suspect the OnBrowse() method is at fault, start paring it down until the problem goes away. You should get it narrowed down to a statement or two.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I've finally found out what's wrong!! i need to put the file at the same folder as i specify the m_binfile in order to open the text file in OnLoad. But, now the question is, how can i specify the location if i were to open the file in a predetermine location?
Anyway, thanks everybody...u all are gifts from heaven
|
|
|
|
|
cyn8 wrote: i need to put the file at the same folder as i specify the m_binfile in order to open the text file in OnLoad.
In other words, you need to use an absolute path instead of a relative path.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Doh!
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Besides the potential memory problems that DavidCrow has mentioned...
I'm trying to narrow it down without being able to debug your code
Try this, replacing "c:\\path\\abc.txt" with a fully qualified pathname (drive letter/path/filename)
that you are absolutely sure exists.
The open should succeed. If it still only succeeds when you don't use the fileopen dialog then
you are trashing memory somewhere and you need to fix that code. If it succeeds always then
you have a pathname problem in OnLoad().
void CICTesterDlg::OnLoad()
{
UpdateData();
CString file;
file="c:\\path\\abc.txt";
std::ifstream outputdata;
outputdata.open(file), ios::in);
if ( !outputdata.is_open() )
{
MessageBox(_T("Unable to open file!"),_T("WARNING"),MB_ICONEXCLAMATION);
return;
}
outputdata.close();
}
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Mark Salsbery wrote: That's something you'll have to check in the debugger.
Debugging is a lost art, Mark.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
cyn8 wrote: actually i modify the code pasted here as the original code is too long.
So how are we supposed to help if the code snippet does not match what you are referring to?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|