Results 1 to 3 of 3

Thread: [RESOLVED] [2005] Error exporting text to Notepad

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    Resolved [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
    At home - VB.NET 2005/2008 Express, Visual Web Developer 2005 Express
    At work - VS 2008 Standard (VB)
    .NET 2.0/3.5


    Visual Studio Express Learning Centre | How do I videos | MSDN VB Express Forum | MSDN VB Developer Centre

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: [2005] Error exporting text to Notepad

    This will probably work better for you
    vb Code:
    1. Private Sub btnFirstExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    2.     Handles btnFirstExport.Click
    3.  
    4.         Dim strText As String = "Some Text" & vbCr
    5.  
    6.         'For x As Integer = 0 To Me.lstFirstFile.Items.Count - 1
    7.  
    8.         '    strText = strText & Me.lstFirstFile.Items(x) & vbCr
    9.  
    10.         'Next
    11.  
    12.         Dim tempFile As String = IO.Path.GetTempFileName
    13.         My.Computer.FileSystem.WriteAllText(tempFile, strText, False)
    14.  
    15.         Dim myProcess As Process = New Process()
    16.         myProcess.StartInfo.FileName = "Notepad"
    17.         myProcess.StartInfo.Arguments = tempFile
    18.         myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
    19.         myProcess.Start()
    20.  
    21.         ' wait until the program is ready for input
    22.         myProcess.WaitForInputIdle(1000)
    23.         IO.File.Delete(tempFile)
    24.  
    25.     End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    Re: [2005] Error exporting text to Notepad

    Thanks. This works well, although I'm not quite sure why my original attempt didn't.
    At home - VB.NET 2005/2008 Express, Visual Web Developer 2005 Express
    At work - VS 2008 Standard (VB)
    .NET 2.0/3.5


    Visual Studio Express Learning Centre | How do I videos | MSDN VB Express Forum | MSDN VB Developer Centre

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width