Results 1 to 6 of 6

Thread: Program already running

  1. #1

    Thread Starter
    Banned
    Join Date
    May 2017
    Location
    https://t.me/pump_upp
    Posts
    4

    Program already running

    Hi i'm new to programming on VB.

    i tried to make the folowing script :
    Module Module1

    Sub Main()
    Dim voornaam, achternaam As Integer
    voornaam = FreeFile()
    achternaam = FreeFile()
    FileOpen(voornaam, "E:\console004a.txt", OpenMode.Output)
    FileOpen(achternaam, "E:\console0004b.txt", OpenMode.Output)
    PrintLine(voornaam, "Jan")
    PrintLine(voornaam, "Peter")
    PrintLine(achternaam, "Jansen")
    PrintLine(achternaam, "Pietersen")
    PrintLine(voornaam, "Klaas")
    FileClose(voornaam)
    FileClose(achternaam)

    End Sub

    End Module

    When i run it it says program already running and it doesn't print the name's on the txt file.

    Can somebody say whats wrong with my script?Name:  Schermopname (51).jpg
Views: 141
Size:  19.7 KBName:  Schermopname (51).jpg
Views: 141
Size:  19.7 KB

  2. #2
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Program already running

    The error must be "File already open." not "Program already running."

    The mistake is, voornaam and achternaam gets the same file number because there is no open file, to fix, replace with
    Code:
            voornaam = FreeFile()
            FileOpen(voornaam, "E:\console004a.txt", OpenMode.Output)
    
            achternaam = FreeFile()
            FileOpen(achternaam, "E:\console0004b.txt", OpenMode.Output)
    Anyway, as documented here, don't use FileOpen, instead use My.Computer.FileSystem or IO.File
    The FileOpen function is provided for backward compatibility and may affect performance. For non-legacy applications, the My.Computer.FileSystem object provides better performance.

    Example:
    Code:
        Sub Main()
    
            Dim F1 As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter("E:\1.txt", False)
            Dim F2 As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter("E:\2.txt", False)
    
            F1.WriteLine("Jan")
            F1.WriteLine("Peter")
            F1.WriteLine("Klaas")
            F1.Close()
    
            F2.WriteLine("Jansen")
            F2.WriteLine("Pietersen")
            F2.Close()
    
        End Sub
    Last edited by 4x2y; May 23rd, 2017 at 03:27 PM.



  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: Program already running

    Welcome to VBForums

    Thread moved from the 'Testers and Testing' forum (for help with testing etc) to the 'VB.Net' (VB2002 and later) forum

  4. #4

    Thread Starter
    Banned
    Join Date
    May 2017
    Location
    https://t.me/pump_upp
    Posts
    4

    Re: Program already running

    Quote Originally Posted by 4x2y View Post
    The error must be "File already open." not "Program already running."

    The mistake is, voornaam and achternaam gets the same file number because there is no open file, to fix, replace with
    Code:
            voornaam = FreeFile()
            FileOpen(voornaam, "E:\console004a.txt", OpenMode.Output)
    
            achternaam = FreeFile()
            FileOpen(achternaam, "E:\console0004b.txt", OpenMode.Output)
    Anyway, as documented here, don't use FileOpen, instead use My.Computer.FileSystem or IO.File



    Example:
    Code:
        Sub Main()
    
            Dim F1 As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter("E:\1.txt", False)
            Dim F2 As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter("E:\2.txt", False)
    
            F1.WriteLine("Jan")
            F1.WriteLine("Peter")
            F1.WriteLine("Klaas")
            F1.Close()
    
            F2.WriteLine("Jansen")
            F2.WriteLine("Pietersen")
            F2.Close()
    
        End Sub
    Thanks for the help I did this as script :

    Module Module1

    Sub Main()
    Dim voornaam, achternaam As Integer
    voornaam = FreeFile()
    achternaam = FreeFile()
    Dim F1 As IO.Streamwritter = My.Computer.FileSystem.OpenTextFilewritter("E:\1.txt", False)
    Dim F2 As IO.Streamwritter = My.Computer.FileSystem.OpenTextFileWritter("E:\2.txt", False)

    F1.WriteLine("Jan")
    F1.WriteLine("Peter")
    F1.WriteLine("Klaas")
    F1.close()

    F2.WriteLine("Jansen")
    F2.WriteLine("Pietersen")
    F2.Close()
    End Sub

    End Module

    It still give's me the error Stopped at Exeption: FileOpen
    Thread :
    3192

  5. #5
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,835

    Re: Program already running

    Quote Originally Posted by Knightmonkeyman View Post
    Thanks for the help I did this as script :

    Module Module1

    Sub Main()
    Dim voornaam, achternaam As Integer
    voornaam = FreeFile()
    achternaam = FreeFile()
    Dim F1 As IO.Streamwritter = My.Computer.FileSystem.OpenTextFilewritter("E:\1.txt", False)
    Dim F2 As IO.Streamwritter = My.Computer.FileSystem.OpenTextFileWritter("E:\2.txt", False)

    F1.WriteLine("Jan")
    F1.WriteLine("Peter")
    F1.WriteLine("Klaas")
    F1.close()

    F2.WriteLine("Jansen")
    F2.WriteLine("Pietersen")
    F2.Close()
    End Sub

    End Module

    It still give's me the error Stopped at Exeption: FileOpen
    Thread :
    3192
    I'm not familiar how "Streamwritter" works...how did you even test that?
    Please remember next time...elections matter!

  6. #6
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Program already running

    Don't mix my code with yours, you don't have to use FileOpen any more.



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