Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 414
  • Last Modified:

VB.Net Why doesnt this code work from the command line

Hi Experts.   I'm testing some code in both a forms application and console application.  The code is this in the console or the same placed in the form load in the forms application.
 
Sub Main()
        Try
            My.Computer.FileSystem.WriteAllText("Test.txt", "Text,", True)
            MsgBox("")
            My.Computer.FileSystem.WriteAllText("Test2.txt", "Text,", True)
            End
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

If I go to the Release folder and double click either program it works correctly and the files are created in the Release Folder.

If I run either program from the command line, the messagebox appears but the files are not created.  

Please can someone explain why?

Thanks for the help.
0
PNRT
Asked:
PNRT
  • 2
1 Solution
 
Paul SCommented:
try using an alternate name space for the same actions.

File Class (System.IO)
http://msdn.microsoft.com/en-us/library/system.io.file.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1

it could be a problem with the my.computer name space.
0
 
käµfm³d 👽Commented:
Where are you running the console application from? You haven't specified an absolute path, so the file "Test.txt" is being written to the working directory of the console window.
0
 
PNRTAuthor Commented:
No luck Im afraid, tried different types including just creating the file.  All work when you doubleclick the file but nothing works when run from the command line
0
 
PNRTAuthor Commented:
Absolutley right Kaufmed, was there when I specified the path
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now