|
Hello everybody, i am trying to parse a simple CSV file (see a little file sample below) using the functions found in the book 'PROFESSIONAL MFC with VC++6' by M. Blaszczak, Wrox. I am working with VC7.
The functions work fine but unfortunately i can get only the first, say, N-1 values parsed instead of all the N wished ones.
for example in the sample below
i get parsed only:
label0 .. label5 as labels row (missing label6)
field0,f1,f2,f3,f4,f5 as first row of values (missing field f6)
0,10,20,30,40,50 as second row of values (missing 60)
and so on...
I mean only six values (with reference to the csv file sample), not all the seven values
any help/tip will be gratly appreciated!
Thanks in advance
<br />
class CMyDoc : public CDocument<br />
{<br />
<br />
public:<br />
int CountChars(CString& ref, TCHAR ch = ',') const;<br />
CString GetField(CString& ref, int nIndex, TCHAR ch = ',') const;<br />
<br />
...<br />
<br />
<br />
};<br />
<br />
...<br />
<br />
int CMyDoc::CountChars(CString& ref, TCHAR ch) const<br />
{<br />
LPCTSTR pstrBuffer = ref.LockBuffer();<br />
int nCount = 0;<br />
<br />
while (*pstrBuffer != _T('\0'))<br />
{<br />
if (*pstrBuffer == ch)<br />
nCount++;<br />
pstrBuffer++;<br />
}<br />
<br />
ref.UnlockBuffer();<br />
return nCount;<br />
}<br />
<br />
<br />
CString CMyDoc::GetField(CString& ref, int nIndex, TCHAR ch) const<br />
<br />
<br />
{<br />
CString strReturn;<br />
LPCTSTR pstrStart = ref.LockBuffer();<br />
LPCTSTR pstrBuffer = pstrStart;<br />
int nCurrent = 0;<br />
int nStart = 0;<br />
int nEnd = 0;<br />
int nOldStart = 0;<br />
<br />
while (nCurrent <= nIndex && *pstrBuffer != _T('\0'))<br />
{<br />
<br />
if (*pstrBuffer == ch)<br />
{<br />
nOldStart = nStart;<br />
nStart = nEnd+1;<br />
<br />
nCurrent++;<br />
}<br />
<br />
<br />
nEnd++;<br />
pstrBuffer++;<br />
}<br />
<br />
ref.UnlockBuffer();<br />
<br />
<br />
if (*pstrBuffer == _T('\0'))<br />
{<br />
TRACE("Warning: Couldn't find it.\n");<br />
return strReturn;<br />
}<br />
<br />
return ref.Mid(nOldStart, nEnd-nOldStart-1);<br />
}<br />
<br />
<br />
<br />
...<br />
<br />
<br />
...<br />
<br />
int nColumns = pDoc->CountChars(pDoc->m_strColumns);<br />
TRACE("N. col= %d, header titles= %s\n", nColumns, pDoc->m_strColumns);<br />
int nIndex;<br />
CString strCurrent;<br />
for (nIndex = 0; nIndex < nColumns; nIndex++)<br />
{<br />
... print values ...<br />
}<br />
SAMPLE FILE.CSV
label0,label1,label2,label3,label4,label5,label6 <-- labels row
field0,f1,f2,f3,f4,f5,f6 <-- first row of values
0,10,20,30,40,50,60 <-- second row of values
...
best regards
|
|
|
|
|
Try my article, CDataFile[^] Just change the std::vector<<double> values="" to="" std::vector<cstring>="" and="" comment="" out="" the="" statistics="" stuff="" you'll="" be="" good="" go.=""
<b="">- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
my message was truncated
Anyway, change the double vector to CString and scrap the statistics stuff and you'll be good to go.
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
thank you very much Nitron!
i have just downloaded your excellent code and i'll give it a try as soon as possible
anyway i would be really interested in finding the reasons why the code above form Wrox book doesn't work as expected
I have tried to debug it and follow all the steps to figure out why the last field isn't parsed but so far i could'f find an answer so i would appreciate very much if anybody could point me towards the solution
thanks again!
best regards
|
|
|
|
|
Hello world...
I use a grabber with 4 cameras connected and I get images from this 4 cameras.
Next, I display all images in the same View...
My question is simple:
Is the Document OR the View which must acquire the images?
I suppose It's the Document... Because the Data is the image and the view only display the data...
When I press the start menu (to start the acquisition) is the Document or the View which must handle this message?
Thanks in advance...
Hello World!!!
from Raphaël
|
|
|
|
|
Raphaël Kindt wrote:
I use a grabber with 4 cameras connected and I get images from this 4 cameras.
Got any spare cameras you don't need? I'm taking donations.
Raphaël Kindt wrote:
When I press the start menu (to start the acquisition) is the Document or the View which must handle this message?
My instinct tells me it's the Document that needs to handle this. But I imagine you also want to update the view as the acquisition is in progress. So as you're loading the images, call UpdateAllViews to let the views know of the new data that has come in.
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
(I actually prefer medium-well.)
|
|
|
|
|
You are right. From an architectural point of view its the Document that should get the images. The purpose of the view should be restricted to display and of course user interface.
Raphaël Kindt wrote:
When I press the start menu (to start the acquisition) is the Document or the View which must handle this message?
This is potentially more interesting a question It really depends on the kind of system you are building. Ideally the document will have a fucntion that will tell it to go and acquire the images.
Now in one situation you can have the menu send its command to the view which will tell the document to load the images.
In another case you could have the menu send a message to the view which will load the document which already has the images loaded because some other process told it to do so, or because the document is told to load images every so often.
Another case, where there is no menu, when the document finds images the view turns on.
Not sure if I actually answered the second question
|
|
|
|
|
Raphaël Kindt wrote:
When I press the start menu (to start the acquisition) is the Document or the View which must handle this message
IMHO it's the MainFrame which should process the command. Knowing which document is currently active, it will be able to call for this object the document's method responsible for loading the data.
HTH,
K.
Angels banished from heaven have no choice but to become demons
Cowboy Bebop
|
|
|
|
|
I think that's a good idea...
Thanks Karl...
Hello World!!!
from Raphaël
|
|
|
|
|
I wonder if there is an easy way to rename a class
including its source file in Visual Studio.
Has .NET Studio any support for this ?
Variable renaming would also be a fine thing.
Simply change the name in the class wizard and all
occurences of the variable are renamed.
This would make refactoring the code much easier when
I change my code in the late stage of a project to
clean up loose ends.
Regards,
Alois Kraus
|
|
|
|
|
Edit->Find and Replace->Replace in Files
Check out the regular expression you pretty much can do anything old grep used to do.
|
|
|
|
|
Nope, you gotta do it the old fashioned way. Find/Replace.
My guess why DevStudio doesn't have this feature is that it may be difficult to do accurately every time. They'd rather avoid the risk of renaming something inappropriately.
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
(I actually prefer medium-well.)
|
|
|
|
|
Hello,
I would like to make something similar to the Start menu of 2000/XP: you can double click on any popup menu to open the item (therefore you can select items that are not leaves in your menu). Anyone has an idea how to do this?
Regards,
mynab
|
|
|
|
|
Hi!
I'm doing this:
if(bRectangleFlag)
{
if (bAddTenHousesFlag = true)
{
CBrush myBrush;
myBrush.CreateSolidBrush(RGB(255,0,0));
HBRUSH hMyBrush = (HBRUSH)myBrush;
pDC->SelectObject(hMyBrush);
pDC->Rectangle(Anchor.x,Anchor.y,DrawTo.x,DrawTo.y);
pDoc->pMetaFileDC->SelectObject(hMyBrush);
pDoc->pMetaFileDC->Rectangle(Anchor.x,Anchor.y,DrawTo.x,DrawTo.y);
}
pDC->SelectStockObject(NULL_BRUSH);
pDC->Rectangle(Anchor.x,Anchor.y,DrawTo.x,DrawTo.y);
pDoc->pMetaFileDC->SelectStockObject(NULL_BRUSH);
pDoc->pMetaFileDC->Rectangle(Anchor.x,Anchor.y,DrawTo.x,DrawTo.y);
}
But the return from SelectObject is killing mu program!
Anyone know why?
Thanks,
quirky
|
|
|
|
|
pDC->SelectObject(&myBrush);
You don't need hMyBrush.
|
|
|
|
|
Many thanks, it now works !
quirky
|
|
|
|
|
Try something like this:
[...]
{
CBrush myBrush;
myBrush.CreateSolidBrush(RGB(255,0,0));
CBrush* pOldBrush pDC->SelectObject(&myBrush);
pDC->...
...
pDC->SelectObject(pOldBrush);
}
[...]. This way, you are sure to select the brush out of the DC (by selecting in whatever has been there before) before the variable that contains it goes out of scope.
Hope this helps
--
"My opinions may have changed, but not the fact that I am right."
Found in the sig of Herbert Kaminski
|
|
|
|
|
Hi Friends
Below is the code wich i used to split the window
It executes well but remains minimised, WHY ??
please identify the mistakes as well as other things to implement if there is
#include <afxwin.h>
#include <afxext.h>
/////////////////////////////////////////////////
// my view class
class myView : public CView
{
DECLARE_DYNCREATE(myView)
public:
myView();
void OnDraw(CDC *dc);
DECLARE_MESSAGE_MAP()
};
myView::myView()
{}
/////////////////////////////////////////////////
// my main class
class myMain:public CFrameWnd
{
public:
myMain();
afx_msg void OnPaint();
CSplitterWnd splitter;
BOOL OnCreateClient(LPCREATESTRUCT,CCreateContext*);
DECLARE_MESSAGE_MAP();
};
myMain::myMain()
{
Create(NULL,"MFC");
}
BOOL myMain::OnCreateClient(LPCREATESTRUCT rs,CCreateContext* context )
{
// Adding the splitter
if (!splitter.CreateStatic(this,1,2,
WS_CHILD|WS_VISIBLE) )
{
TRACE0("Failed to CreateStaticSplitter\n");
return FALSE;
}
// Creating first view(left)
if ( !splitter.CreateView( 0, 0,
RUNTIME_CLASS(myView ),
CSize(50,50), context
) )
{
TRACE0("Failed to create second pane\n");
return FALSE;
}
// Creating second view(right)
if (!splitter.CreateView( 0, 1,
RUNTIME_CLASS(myView ),
CSize(50,50), context
) )
{
TRACE0("Failed to create second pane\n");
return FALSE;
}
return FALSE;
}
//////////////////////////////////////////////////////
// my application calss
class myApp:public CWinApp
{
public:
BOOL InitInstance()
{
m_pMainWnd=new myMain;
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
};
//////////////////////////////////////////////////
// my document class
class myDoc : public CDocument
{
DECLARE_DYNCREATE(myDoc)
public:
myDoc()
{}
};
void myView::OnDraw(CDC *dc)
{
myDoc *p_myDoc = (myDoc*) GetDocument();
}
/////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(myMain,CFrameWnd)
END_MESSAGE_MAP()
BEGIN_MESSAGE_MAP(myView,CView)
END_MESSAGE_MAP()
myApp App;
IMPLEMENT_DYNCREATE(myDoc,CDocument)
IMPLEMENT_DYNCREATE(myView,CView)
|
|
|
|
|
i have created a project in vc6.0 . iwant to distribute my application to other people so that they can use it. it contains some dll i have tried the realse version in vc6 but i constantly gives me errors what do i do is this the right way to do it or not. pls help me out.
thanx in advance
|
|
|
|
|
Either link statically (project-> Settings)
or see what are the dll dependies using the tool dependency walker and supply these files with ur application
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Hi Friends
I created an MFC Application using AppWizard with the option "Split Window"(something like this) in the 4th step's advanced section. It splits the window dynamically.
Can I make this dynamic splitting static ??
by calling 'CreateStatic' instead of 'Create' in CFrameWnd::OnCreateClient
i.e
BOOL CmyMain::OnCreateClient( 'parameters' )
{
// creating splitter
m_wndSplitter.CreateStatic(this,
1 // one row
2 // two columns
)
return TRUE;
}
Will it solve my problem or i need the other stuffs ??
If YES the please identify them also
BTW Do I need to create view for each splitted window ??
you can reply me at aatifaqeel@yahoo.com
Thanx for helping me
|
|
|
|
|
Which API should be the best choice (i.e winsock2 e.t.c) for the development of a firewall (in MFC) for a beginner.
Reply me soon
|
|
|
|
|
I am interested in developing a firewall using VC++(MFC). pLZ TELL ME WHAT LIBRARIES/websites to explore and how to start. I am a beginner so plz guide me properly in detail.
Reply me soon
|
|
|
|
|
http://www.codeproject.com/useritems/DrvFltIp.asp for a start
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Hy people!
My CRichEditCtrl is taking me out of control... I don't know what to do...
It haves an CString variable and a control variable associate. When I type more than 256 chars, it just crash...
If someone have some idea...
thanks all for the attention.
cheers!
Ricky
|
|
|
|
|