Solved

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

Posted on 2013-06-14
4
402 Views
Last Modified: 2013-06-14
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
Comment
Question by:PNRT
  • 2
4 Comments
 
LVL 11

Expert Comment

by:Paul S
ID: 39248774
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
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 39248965
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
 
LVL 1

Author Comment

by:PNRT
ID: 39248968
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
 
LVL 1

Author Comment

by:PNRT
ID: 39248978
Absolutley right Kaufmed, was there when I specified the path
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now