|
-
Nov 26th, 2007, 08:54 AM
#1
Thread Starter
Addicted Member
[RESOLVED] [2005] Error exporting text to Notepad
I am running the following code, but I'm getting an error that doesn't make much sense to me:
"Specified repeat count is not valid"
The following code works ok, but if I uncomment the For .... Next loop, it falls over on the line System.Windows.Forms.SendKeys.SendWait(strText)
Code:
Private Sub btnFirstExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirstExport.Click
Dim strText As String = "Some Text" & vbCr
'For x As Integer = 0 To Me.lstFirstFile.Items.Count - 1
' strText = strText & Me.lstFirstFile.Items(x) & vbCr
'Next
Dim myProcess As Process = New Process()
myProcess.StartInfo.FileName = "Notepad"
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
myProcess.Start()
' wait until the program is ready for input
myProcess.WaitForInputIdle(1000)
If myProcess.Responding Then
System.Windows.Forms.SendKeys.SendWait(strText)
Else
myProcess.Kill()
End If
End Sub
-
Nov 26th, 2007, 05:03 PM
#2
Re: [2005] Error exporting text to Notepad
This will probably work better for you
vb Code:
Private Sub btnFirstExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnFirstExport.Click
Dim strText As String = "Some Text" & vbCr
'For x As Integer = 0 To Me.lstFirstFile.Items.Count - 1
' strText = strText & Me.lstFirstFile.Items(x) & vbCr
'Next
Dim tempFile As String = IO.Path.GetTempFileName
My.Computer.FileSystem.WriteAllText(tempFile, strText, False)
Dim myProcess As Process = New Process()
myProcess.StartInfo.FileName = "Notepad"
myProcess.StartInfo.Arguments = tempFile
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
myProcess.Start()
' wait until the program is ready for input
myProcess.WaitForInputIdle(1000)
IO.File.Delete(tempFile)
End Sub
-
Nov 27th, 2007, 05:46 AM
#3
Thread Starter
Addicted Member
Re: [2005] Error exporting text to Notepad
Thanks. This works well, although I'm not quite sure why my original attempt didn't.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|