Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > VB.NET > VB.NET General Discussion

VB.NET General Discussion VB.NET general discussion area

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-12-2008, 8:19 AM
SDR SDR is offline
VB.NET Forum Newbie
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Oct 2008
Posts: 9
Reputation: 0
SDR is on a distinguished programming path ahead
Default CommandLineArgs help needed

I have searched here and google but I am still confused as to how to make this work. I have an application that will be run automaticly from a server by ActiveBatch. This app will run a report for 1 of 3 date ranges depending on the parameter passed into it from ActiveBatch. My problem is I don't understand how to use CommandLineArgs to accomplish this. Could someone please explain to me how CommandLineArgs works? The code I have so far is below...

Dim runType As String
Dim numComArgs As String
numComArgs = My.Application.CommandLineArgs.Count

'---Log the program is beginning and the initial parameters
ArgLogFile = New Log("\\kronos\ProdReptACD\Logs\ArgLogFile.log")
ArgLogFile.Write("Command Arguments: " & My.Application.CommandLineArgs.Count.ToString())
For index As Integer = 0 To (My.Application.CommandLineArgs.Count - 1)
LogFile.Write(vbTab & index.ToString & "-" & My.Application.CommandLineArgs(index).ToString())
Next

'---Set the Run Type to the value of the first parameter passed in.
'---If no parameter was passed, then default to weekly
If numComArgs = 0 Then
runType = "Weekly"
Else
runType = My.Application.CommandLineArgs(numComArgs - 1).ToString()
End If

If UCase(runType) = "WEEKLY" Then
dtStart = DateAdd("d", -6 - Weekday(Now()), Now())
dtEnd = DateAdd("d", -Weekday(Now()), Now())
ElseIf UCase(runType) = "CALENDAR" Then
dtStart = "01/01/" & Year(Now()) - 1
dtEnd = "12/31/" & Year(Now()) - 1
ElseIf UCase(runType) = "FISCAL" Then
If Month(Now()) > 6 Then
dtStart = "07/01/" & Year(Now()) - 1
dtEnd = "06/30/" & Year(Now())
Else
dtStart = "07/01/" & Year(Now()) - 2
dtEnd = "06/30/" & Year(Now()) - 1
End If
End If
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 11-12-2008, 11:51 AM
Robert_Zenz's Avatar
VB.NET Forum Idol
.NET Framework: .NET 2.0
 
Join Date: Jun 2008
Location: Vienna, Austria
Age: 22
Posts: 503
Reputation: 290
Robert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NET
Default

Hello.

I can't find an Error in your code...except that it's not very .NET like and you should really turn on Option Strict.

Code:
        Dim runType As String = "Weekly"

        '---Log the program is beginning and the initial parameters
        ArgLogFile = New Log("\\kronos\ProdReptACD\Logs\ArgLogFile.log")
        ArgLogFile.Write("Command Arguments: " & My.Application.CommandLineArgs.Count.ToString())
        For Each arg As String In My.Application.CommandLineArgs
            ArgLogFile.Write(vbTab & My.Application.CommandLineArgs.IndexOf(arg).ToString("N0") & "-" & arg)
        Next

        '---Set the Run Type to the value of the first parameter passed in.
        '---If no parameter was passed, then default to weekly
        If My.Application.CommandLineArgs.Count > 0 Then runType = My.Application.CommandLineArgs(My.Application.CommandLineArgs.Count - 1).ToString()

        If runType.ToUpper() = "WEEKLY" Then
            dtStart = DateAdd("d", -6 - Date.Now().DayOfWeek, Date.Now())
            dtEnd = DateAdd("d", -Date.Now().DayOfWeek, Date.Now())
        ElseIf UCase(runType) = "CALENDAR" Then
            dtStart = "01/01/" & (Date.Now().Year - 1).ToString()
            dtEnd = "12/31/" & (Date.Now().Year - 1).ToString()
        ElseIf UCase(runType) = "FISCAL" Then
            If Month(Now()) > 6 Then
                dtStart = "07/01/" & (Date.Now().Year - 1).ToString()
                dtEnd = "06/30/" & (Date.Now().Year).ToString()
            Else
                dtStart = "07/01/" & (Date.Now().Year - 2).ToString()
                dtEnd = "06/30/" & (Date.Now().Year - 1).ToString()
            End If
        End If
Commandline Arguments are simple:
Code:
Your.exe Argument1 Argument2 "This is Argument3" This is not Working
Code:
Argument Array:
0: Argument1
1: Argument2
2: This is Argument3
3: This
4: is
5: not
6: Working
Bobby
__________________
Don't give TypeCasting Errors a chance, turn ON Option Strict!
Greatest Obfuscator ever: EazFuscator (Freeware)
Greatest Reflection Tool ever: .NET Reflector (Freeware) with Add-Ins
Greatest Introspection Tool ever: Gendarme (GPL)
Greatest MySQL FrontEnd ever: MySQL-Front (Shareware), HeidiSQL (GPL)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-13-2008, 9:35 AM
SDR SDR is offline
VB.NET Forum Newbie
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Oct 2008
Posts: 9
Reputation: 0
SDR is on a distinguished programming path ahead
Default

Thanks for the help, Robert. It works with the small changes you made. I am starting to understand how the CommandLineArgs works.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 5:57 PM.

Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.