By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,581 Members | 2,007 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,581 IT Pros & Developers. It's quick & easy.

File will not open after passing command line argument

P: n/a
The only code that is helpful is this:
fp = New IO.StreamReader(filename, New
System.Text.UnicodeEncoding(True, False), False)
If I pass a command line argument to my program that is not from Visual
Studio.NET is debug mode, the above code won't work, even though filename is
not changed whether I pass a command line argument or not. By not work, I
mean it will set fp.EndOfStream to true and fp.Peek() returns -1. The command
line argument is a file name, but not "filename" and is irrelevant. The file
is not concurrently open by any other program. Can someone please help me or
tell me how to work around what is probably is bug in VB.NET?
Aug 6 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hi Forrest,

Does the code work if you run it in Visual Studio by setting the command
line arguments to the same filename in the Debug tab tot the Project
properties ?
Can you show the code that populates the filename variable ?

EG:

Sub Main(args() as String)
filename = args(0)

?

"Forrest Heller" <Forrest He****@discussions.microsoft.comwrote in message
news:E4**********************************@microsof t.com...
The only code that is helpful is this:
fp = New IO.StreamReader(filename, New
System.Text.UnicodeEncoding(True, False), False)
If I pass a command line argument to my program that is not from Visual
Studio.NET is debug mode, the above code won't work, even though filename
is
not changed whether I pass a command line argument or not. By not work, I
mean it will set fp.EndOfStream to true and fp.Peek() returns -1. The
command
line argument is a file name, but not "filename" and is irrelevant. The
file
is not concurrently open by any other program. Can someone please help me
or
tell me how to work around what is probably is bug in VB.NET?
Aug 6 '07 #2

P: n/a
Oh whoops: here is the code that gets the command line arguments:
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim i, cnt As Integer
'get cmd line params--for some reason they come with quotes (")
attached--guess this isn't Unix
Dim prog_args As String =
Microsoft.VisualBasic.Command().Replace("""", "")
Aug 6 '07 #3

P: n/a
Triple post. I feel terrible.
For full disclosure, here is all code executed in Mainform_load until the
get_configuration_list call

'failure to load config list?
Dim load_failure As Boolean = True
'let the DLL know the HWND
set_acoj_window(Me.Handle)
'set the parent of the reminder form to be me
rm.mparent = Me
'get configuration list
configurations = get_configurations(CONFIG_LIST_FILE)

Aug 6 '07 #4

P: n/a
As I said earlier, I'm lost on this code as it appears you are using a
constant, CONFIG_LIST_FILE, not the actual command line argument.

BTW: for the command line argument you can use
Environment.GetCommandLineArgs, . Index 0 is your exe, index 1 is the first
argument. ,eg.:
filename = Environment.GetCommandLineArgs(1)
That will avoid the need to remove any enclosing quotation marks.

"Forrest Heller" <Fo***********@discussions.microsoft.comwrote in message
news:CE**********************************@microsof t.com...
Triple post. I feel terrible.
For full disclosure, here is all code executed in Mainform_load until the
get_configuration_list call

'failure to load config list?
Dim load_failure As Boolean = True
'let the DLL know the HWND
set_acoj_window(Me.Handle)
'set the parent of the reminder form to be me
rm.mparent = Me
'get configuration list
configurations = get_configurations(CONFIG_LIST_FILE)
Aug 6 '07 #5

P: n/a
I changed the file path to an absolute one with Application.GetStartupPath
and that worked! I don't know why, though, because a file without a specified
path is searched for in the current directory, right? As long as it
works...Thanks for your help, Bill.
Aug 6 '07 #6

P: n/a
I'm not sure I was any, but I'm glad you got it working :)

"Forrest Heller" <Fo***********@discussions.microsoft.comwrote in message
news:62**********************************@microsof t.com...
>I changed the file path to an absolute one with Application.GetStartupPath
and that worked! I don't know why, though, because a file without a
specified
path is searched for in the current directory, right? As long as it
works...Thanks for your help, Bill.
Aug 6 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.