Displaying a text file immediately after creating it.

I have a section of code that needs to output to a text file using CStdioFile 
and then immediately display it using notepad.

I have tried the following, but it doesn't find the file.  However, if I go 
to window explorer, the file is there.  Any Ideas?


  CStdioFile af;
  if 
(af.Open(theApp.WORKDIR+"steerprt.txt",CFile::modeCreate|CFile::modeWrite))
    {
      af.WriteString(tstr);
      af.Flush();
      af.Close();
    }
  HWND mainhwnd = GetSafeHwnd();
  ret1 = (int) 
ShellExecute(mainhwnd,"open",theApp.WORKDIR+"steerptr.txt","",theApp.WORKDIR,SW_SHOWNORMAL);


ShellExecute returns 2 (File not found)
0
phil78 (1)
7/9/2008 8:52:00 PM
vc.mfc 33608 articles. 0 followers. Follow

6 Replies
887 Views

Similar Articles

[PageSpeed] 56

Because one filename is steerprt.txt and the other is steerptr.txt.

AliR.


"Phil" <phil78@sbcglobal.net> wrote in message 
news:7CFE46AE-2347-4C93-AC28-18341ED84BDB@microsoft.com...
>I have a section of code that needs to output to a text file using 
>CStdioFile
> and then immediately display it using notepad.
>
> I have tried the following, but it doesn't find the file.  However, if I 
> go
> to window explorer, the file is there.  Any Ideas?
>
>
>  CStdioFile af;
>  if
> (af.Open(theApp.WORKDIR+"steerprt.txt",CFile::modeCreate|CFile::modeWrite))
>    {
>      af.WriteString(tstr);
>      af.Flush();
>      af.Close();
>    }
>  HWND mainhwnd = GetSafeHwnd();
>  ret1 = (int)
> ShellExecute(mainhwnd,"open",theApp.WORKDIR+"steerptr.txt","",theApp.WORKDIR,SW_SHOWNORMAL);
>
>
> ShellExecute returns 2 (File not found) 


0
AliR3470 (3235)
7/9/2008 9:12:12 PM
"AliR (VC++ MVP)" <AliR@online.nospam> wrote in message 
news:FP9dk.1729$zv7.1050@flpi143.ffdc.sbc.com...
> Because one filename is steerprt.txt and the other is steerptr.txt.

:-). I couldnt figure it out. I had assumed that OP cut-pasted.

--
Ajay


0
ajaykalra (6842)
7/9/2008 9:36:44 PM
That's amazing.  The two names were so close that it was difficult to see 
the difference and it was likely just a typo.  Nice catch.

The error message from ShellExecute was pretty accurate though :o)

Tom

"AliR (VC++ MVP)" <AliR@online.nospam> wrote in message 
news:FP9dk.1729$zv7.1050@flpi143.ffdc.sbc.com...
> Because one filename is steerprt.txt and the other is steerptr.txt.
>
> AliR.
>
>
> "Phil" <phil78@sbcglobal.net> wrote in message 
> news:7CFE46AE-2347-4C93-AC28-18341ED84BDB@microsoft.com...
>>I have a section of code that needs to output to a text file using 
>>CStdioFile
>> and then immediately display it using notepad.
>>
>> I have tried the following, but it doesn't find the file.  However, if I 
>> go
>> to window explorer, the file is there.  Any Ideas?
>>
>>
>>  CStdioFile af;
>>  if
>> (af.Open(theApp.WORKDIR+"steerprt.txt",CFile::modeCreate|CFile::modeWrite))
>>    {
>>      af.WriteString(tstr);
>>      af.Flush();
>>      af.Close();
>>    }
>>  HWND mainhwnd = GetSafeHwnd();
>>  ret1 = (int)
>> ShellExecute(mainhwnd,"open",theApp.WORKDIR+"steerptr.txt","",theApp.WORKDIR,SW_SHOWNORMAL);
>>
>>
>> ShellExecute returns 2 (File not found)
>
> 


0
tserface (3860)
7/9/2008 9:54:33 PM
"Tom Serface" <tserface@msn.com> wrote in message 
news:e6mDg5g4IHA.4856@TK2MSFTNGP02.phx.gbl...
> That's amazing.  The two names were so close that it was difficult to see 
> the difference and it was likely just a typo.  Nice catch.
>
> The error message from ShellExecute was pretty accurate though :o)

Kicker would have been if there was an actual file with that with different 
content. Or even same content.

--
Ajay

>
> Tom
>
> "AliR (VC++ MVP)" <AliR@online.nospam> wrote in message 
> news:FP9dk.1729$zv7.1050@flpi143.ffdc.sbc.com...
>> Because one filename is steerprt.txt and the other is steerptr.txt.
>>
>> AliR.
>>
>>
>> "Phil" <phil78@sbcglobal.net> wrote in message 
>> news:7CFE46AE-2347-4C93-AC28-18341ED84BDB@microsoft.com...
>>>I have a section of code that needs to output to a text file using 
>>>CStdioFile
>>> and then immediately display it using notepad.
>>>
>>> I have tried the following, but it doesn't find the file.  However, if I 
>>> go
>>> to window explorer, the file is there.  Any Ideas?
>>>
>>>
>>>  CStdioFile af;
>>>  if
>>> (af.Open(theApp.WORKDIR+"steerprt.txt",CFile::modeCreate|CFile::modeWrite))
>>>    {
>>>      af.WriteString(tstr);
>>>      af.Flush();
>>>      af.Close();
>>>    }
>>>  HWND mainhwnd = GetSafeHwnd();
>>>  ret1 = (int)
>>> ShellExecute(mainhwnd,"open",theApp.WORKDIR+"steerptr.txt","",theApp.WORKDIR,SW_SHOWNORMAL);
>>>
>>>
>>> ShellExecute returns 2 (File not found)
>>
>>
>
> 

0
ajaykalra (6842)
7/9/2008 11:42:02 PM
See below...
On Wed, 9 Jul 2008 13:52:00 -0700, Phil <phil78@sbcglobal.net> wrote:

>I have a section of code that needs to output to a text file using CStdioFile 
>and then immediately display it using notepad.
>
>I have tried the following, but it doesn't find the file.  However, if I go 
>to window explorer, the file is there.  Any Ideas?
>
>
>  CStdioFile af;
****
    CString pathname = WORKDIR + _T("steerptr.txt");

Note that I didn't see the mis-spelling either, but it wouldn't have affected me because I
would not have tried to use the same string twice.  I would either have done a #define of
the name or I would have stored it in a variable as above, so there would be no
possibility of the error you got.
****
>  if 
>(af.Open(theApp.WORKDIR+"steerprt.txt",CFile::modeCreate|CFile::modeWrite))
****
How many things are already wrong with this? 

It uses theApp for some variable.  This is wrong.  You should not be tossing values into
your CWinApp-derived class as if they are global variables.  If this code is in the
CWinApp class, it does not need to use theApp; if it is not in the CWinApp class, it does
not need to know about it.

The creation of the path in two places looks suspicious, and this was before I saw the
other comments pointing out the typo.  

Do not use "xxx" for literal strings; use _T("xxx") so you are Unicode-aware

Use spaces around binary operators and after commas so the code is readable.

if(af.Open(pathname, CFile::modeCreate | CFile::modeWrite))

Why is it that so many programmers do not believe in readability, but think that the
fewest number of characters typed is the quality measure for code?  If you believe this,
don't code in C, code in APL.
****
>    {
>      af.WriteString(tstr);
>      af.Flush();
****
There is no need to do a flush; this will happen automatically with the close
****
>      af.Close();
>    }
>  HWND mainhwnd = GetSafeHwnd();
****
Why do you need a variable here?
****
>  ret1 = (int) 
>ShellExecute(mainhwnd,"open",theApp.WORKDIR+"steerptr.txt","",theApp.WORKDIR,SW_SHOWNORMAL);
****
ShellExecute(GetSafeHwnd(), _T("open"), pathname, _T(""), WORKDIR, SW_SHOWNORMAL);
****
>
>
>ShellExecute returns 2 (File not found)
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15972)
7/10/2008 1:41:32 AM
Yes, I agree.  That is one of the best reason to use a const or #define for 
these kinds strings.  At least if the file is named wrong it's named the 
same in both places where it is used.  CString works as well of course, but 
if it never needed to change after the initialization making it a const 
would help protect that.

Tom

"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:jjpa745r8j6rot8tr7td3bkqboqavc86pi@4ax.com...
> See below...
> On Wed, 9 Jul 2008 13:52:00 -0700, Phil <phil78@sbcglobal.net> wrote:
>
>>I have a section of code that needs to output to a text file using 
>>CStdioFile
>>and then immediately display it using notepad.
>>
>>I have tried the following, but it doesn't find the file.  However, if I 
>>go
>>to window explorer, the file is there.  Any Ideas?
>>
>>
>>  CStdioFile af;
> ****
>    CString pathname = WORKDIR + _T("steerptr.txt");
>
> Note that I didn't see the mis-spelling either, but it wouldn't have 
> affected me because I
> would not have tried to use the same string twice.  I would either have 
> done a #define of
> the name or I would have stored it in a variable as above, so there would 
> be no
> possibility of the error you got.
> ****
>>  if
>>(af.Open(theApp.WORKDIR+"steerprt.txt",CFile::modeCreate|CFile::modeWrite))
> ****
> How many things are already wrong with this?
>
> It uses theApp for some variable.  This is wrong.  You should not be 
> tossing values into
> your CWinApp-derived class as if they are global variables.  If this code 
> is in the
> CWinApp class, it does not need to use theApp; if it is not in the CWinApp 
> class, it does
> not need to know about it.
>
> The creation of the path in two places looks suspicious, and this was 
> before I saw the
> other comments pointing out the typo.
>
> Do not use "xxx" for literal strings; use _T("xxx") so you are 
> Unicode-aware
>
> Use spaces around binary operators and after commas so the code is 
> readable.
>
> if(af.Open(pathname, CFile::modeCreate | CFile::modeWrite))
>
> Why is it that so many programmers do not believe in readability, but 
> think that the
> fewest number of characters typed is the quality measure for code?  If you 
> believe this,
> don't code in C, code in APL.
> ****
>>    {
>>      af.WriteString(tstr);
>>      af.Flush();
> ****
> There is no need to do a flush; this will happen automatically with the 
> close
> ****
>>      af.Close();
>>    }
>>  HWND mainhwnd = GetSafeHwnd();
> ****
> Why do you need a variable here?
> ****
>>  ret1 = (int)
>>ShellExecute(mainhwnd,"open",theApp.WORKDIR+"steerptr.txt","",theApp.WORKDIR,SW_SHOWNORMAL);
> ****
> ShellExecute(GetSafeHwnd(), _T("open"), pathname, _T(""), WORKDIR, 
> SW_SHOWNORMAL);
> ****
>>
>>
>>ShellExecute returns 2 (File not found)
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm 


0
tserface (3860)
7/10/2008 2:06:12 AM
Reply:

Similar Artilces:

Dual Displays
I want to connect my Sharp Aquos flat screen TV to my computer, and see my desktop on both the TV and computer monitor. Windows Vista Home Premium. HP Pavilion a1610n computer. Galaxy GeForce 8400 GS graphics card, outputs: 1-VGA, 1-DVI, and 1-SVGA. There is no HDMI port on the card. I connected a VGA cable between the motherboard "on-board" VGA port and the TV, figuring that I could use that output to work with the TV. The computer monitor is plugged into the GeForce graphics card. Tried the Desktop "Display Setting". It says, the number 2 monitor is "N...

Vba code cannot select text pasted from .txt file
The data I'm working with is from a .txt file which was created by exporting a .pdf to a text file. I copy all of the text from the .txt file and paste it into a column in Excel. When trying to reference any column, row, or range on the sheet with the pasted text, I get the following error: Run-time error '1004': Application-defined or object-defined error. Sample code: Sheets("Sheet5").Select ' <this works fine Columns("A:A").Select ' <this gets the error I've tried pasting the text with other paste special options. I'v...

Folder could not be displayed
I am running Windows XP and Outlook Express 6 just fine then one day my husband does something to my computer and his email account won't work. My email is working just fine but in his he cannot open his inbox. It says folder could not be displayed, and when you send and receive it gives you this error message: "An unknown error has occured. Account: 'incoming.verizon.net'. Server:'incoming.verizon.net'.Protocol:POP3, port: 110, Secure(SSL): No, error number: 0x800C013B" If anyone could help me with this I would greatly appreciate it. Thank you T...

Display a message box "this entry is a duplicate"
How can I display a message box on a form if the shipment number is a duplicate? I need a message box to pop up when user attempts to tab out of the field. Thank you. Something like: Private Sub txtShipNum_BeforeUpdate(Cancel As Integer) If DCount("*", "MyTable", "ShipNum = '" & Me.txtShipNum & "'") > 0 Then Msgbox Me.txtShipNum & " already exists." Cancel = True End If End Sub This assumes that your text box is named txtShipNum, that the name of the field in table MyTable is ShipNum...

Maximum File Size #2
What is the maximum recommended file size for an Excel workbook? Hi see: http://www.decisionmodels.com/memlimits.htm -- Regards Frank Kabel Frankfurt, Germany "Lynn" <Lynn@discussions.microsoft.com> schrieb im Newsbeitrag news:EC7732CE-8678-426A-8400-0836D87D80D8@microsoft.com... > What is the maximum recommended file size for an Excel workbook? ...

Converting Revisions to Text
I have two word files. I do a comparison of the two files. I would like to convert the comparison result into a file where the revisions are actual text and formatting. For example, I would like the deletions to become text with strikethrough, not text marked as a deletion displayed with a strikethough. I need this to export to another application. Is there any simple way to do this? ...

how to display values in 3 cells into one cell
Anyone can help me how do I display the 3 separate different values in 3 cells into just one single cell ? thanks so much in advance. Either there was a typo or there's an echo in here. That line should have been: = A1 & " " & B1 & " " & C1 "Bradley Dawson" <bradleydawson@earthlink.net> wrote in message news:l464b.2224$Lk5.2093@newsread3.news.pas.earthlink.net... > In the target cell, type: > > = A1 & B1 & C1 > > where A1, B1, C1 are the cell addresses that you want to concatenate. > > If these have number...

How to select & display distinct values
Hello, I need help with a form please. My form has two controls, the first being a combo box. This box should select the company name from a lookup table. The lookup table has only two companies in it, however, they each are repeated several time. Company 1 has about 10 rows, company 2 has 3 rows. I used the query builder and came up with the statement: "SELECT DISTINCT Lktbl_Role_Master.CompanyName FROM Lktbl_Role_Master;" When I run the statement directly from query view, it executes perfectly and returns exactly two rows (one for each company, in a datasheet view) ho...

grey text box
Need help adding the grey box to a document to click and fill basically. Deanna wrote: > Need help adding the grey box to a document to click and fill > basically. See http://www.computorcompanion.com/LPMArticle.asp?ID=22. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. ...

Display Time in Outlook
The time setting in my Outlook is one hour behind my actual time. I cannot determine how to change the time. Outlook is the only item that is incorrect. Other display times in operating system are correct. Thanks, Jodi ...

PK and FK Displayed
I am a complete Visio newbie, and cannot find the answer I need in books or online help. I am trying to create ER diagrams from scratch, and not connected to real tables, using VEA. I have added tables ('Entities') to the form, connected them with a Relationship connector, and, in the Database Properties window I've assigned the end points to a Primary Key on the left and a Foreign Key on the right. But the model shows the connector as running between the top colums on both sides, whereas I want the keys to be in that upper box and provide the connector's end points. Wh...

Trouble Opening WMV File
Running Win XP SP3. Have Corel's (Intervideo) WIN DVD 8 installed, and have this as my program of choice in the Folders entry in control panel as the program to always open WMV programs. When I point to a WMV program and pick play or open, I get a message "File xxx is not a valid Win32 Program." and an abort. However, if I launch WinDVD 8, and have the program point to the file, it opens and plays it perfectly every time. Do I have an error in my system somewhere? Thanks in advance for any help. -------- Original-Nachricht -------- > Running Win XP SP3....

Formulas are displayed, results are not
Hello, For some reason, when I enter a formula into a cell and press enter, the formula just stays there. Anyone know what I can do to show the results? I tried pressing Cntrl + `, but that didn't work. FYI, when I cut and paste a column from a separate workbook, that column works like normal (i.e., the formulas produce results). Thanks for any suggestions! Hi Mike, Maybe your cell is preformatted as Text. Try formatting to general then erase your = and type it in again. HTH Martin "Mike C" <js2k111@yahoo.com> wrote in message news:f699bcd4-ad82-4a88-9759-5638c147b...

Converting number to text
Is it possible to convert, say 1234 to one thousand two hundred and thirty four Thanks There is no direct functions to convert this. For a VBA solution check out the below links http://www.ozgrid.com/VBA/ValueToWords.htm http://support.microsoft.com/kb/213360 http://www.xldynamic.com/source/xld.xlFAQ0004.html -- Jacob (MVP - Excel) "booshi" wrote: > Is it possible to convert, say 1234 to one thousand two hundred and thirty > four > > > Thanks > > > . > ...

Stop displaying a line
I have a line graph/chart and it gets its values using a formula and the values of another column. However this poses a problem because if there is nothing in the targetted column the formula returns 0 cause the line to drop to the bottom, instead of casuing the line to just end until a value is added to the target column. How can I do this? Change your formula to use NA() if the cell is empty. For example: =IF(A1="",NA(),A1) To hide the resulting #N/A errors on the worksheet, you can use conditional formatting. There are instructions here: http://www.contextures.com/xlC...

Macro to import from a binary file and convert to hex
Excel 97. I have a macro that imports hex and stores the data in a column. Can this be done with a binary file? Import from a binary file and convert to hex and store it in a column? ...

A question about Console window(display or not display)
I've redirected the (stdin stdout stderr) of a console window process I spawned to a pipe. And I want to display the redirected console window, the question is: If I display it(set Create_new_CONSOLE in createprocess and some flags in startupinfo), I cannot use the redirected way of pipe, which means if i do not display, i can use the pipe communicating with the child process. Does it mean that as long as I disply the console window, windows will change stdin stdout to "screen&keyboard" instead of my pipe? That's right. If you redirect stdin or stdout then you preemp...

unattached textboxes disappear when a msgbox is displayed on a tab control
I'm using Access 2003. I have a form with a tab control on it. I was having problems with labels flashing and I followed the suggesting from Allen Browne - http://allenbrowne.com/ser-46.html. The flashing went away but now when a msgbox is displayed the unattached textboxes that I'm using as labels disappear. They come back as soon as the msgbox is removed from the screen. I've searched google looking for an answer but have come up short. Does anyone know why I'm experiencing this behavior and how to make it go away? Thanks, Rick That *is* strange. Have you tr...

Display or not display series
I have a graph with four series but some of the series may be blank, i.e. the series name is <blank series>. Is there a way to not display these series on the graph and/or legend if they are blank, and display them if they are without deleting the series? Thanks! Clay Create a chart from all the data Select the data on which the chart is based. Choose Data>Filter>AutoFilter In the heading cell for the series name column, select (NonBlanks) from the dropdown list The series with blank name cells will be hidden in the chart. Clay wrote: > I have a graph with four serie...

Creating fields like gateways, when met, unlock next step
I am researching how to create "gates" in a database so that when someone initilializes the process filling out a form, they cannot progress beyond a certain point in the process until a specified field is "electronically" signed by the "keyholder" person authorized to approve progression to the next step. The "next step" could be gaining entry into another form or subform. I've not been able to come across anything helpful yet. Any help is much appreciated. Thank you in advance, "Aso" <Aso@discussions.microsoft.com>...

does Excel support multiple display monitors?
Hello All Excel Experts How do I move chart windows to multiple display montors?? (one computer runnng three monitors... Excel Charts will not move off the primary monitor. Your advice is EXTREMELY appreciated thanks. Denni ...

Getting IIS to recognize OFT files?
Our intranet server (IIS) died a few weeks ago so we had to get a new one and migrate everything over. It all seemed to transfer just fine except for one issue...any link to an .oft file sitting on the server returns a 'page not found' error. I realize this is likely a IIS issue moreso than outlook, but thought I'd post in here as well just in case anyone else has heard of this issue. Any thoughts on what might be going on? -Darrel it's a configuration problem on iis - the guys in the iis groups will be able to help but they will need to know if the link a network pa...

Displaying an equation
I have an equation setup that is referencing a few other cells that have equations in them. I want to have a cell that displays this equation with the answers that are calculated from these other cells displayed as values in the new equation. Any help would be greatly appreciated. Thanks Check out http://www.mvps.org/dmcritchie/excel/formula.htm#getformula In article <E4143E2B-360A-4B43-955F-73BF8EC60694@microsoft.com>, "hoising8" <hoising8@discussions.microsoft.com> wrote: > I have an equation setup that is referencing a few other cells that have > eq...

Retrieve Meeting Response Text Associated with an Appointment
How do I retrieve the text of meeting responses associated with an appointment? I have redeveloped a macro which produces a word document listing the meeting response status of invitees to an appointment. I would like, for those who declined, to include the body of the meeting response (ie., where the invitee has chosen to "Edit response before sending." While the Meeting Response Status is a Recipient property, the text of the response is not. Any ideas? I'm including the macro below: Public Sub PrintAttendees() ' Gather data from an opened appointment ...

Serialisation
A general query Im serialising a person object with the following member variables Class Person Private _forenames As String Private _surname As String Private _dob As Date Private _marital_status As MaritalStatus 'Public Get and Set Properties here for each of the above ' I'll not detail them all to save space but Ill show attributes <XmlElementAttribute(Elementname:="forename")> _ <XmlElementAttribute(Elementname:="surname")> _ <XmlElementAttribute(Elementname:="dob"...