Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB application: forms or not? 1

Status
Not open for further replies.

tvbruwae

Programmer
Aug 9, 2001
224
EU
Hi

I'm trying to write a simple application to manage the password on an account. I need a program that is able to set the password on a domain account (password is calculated by the program, based on a number of variables). However, it should also be able to show a form that allows to retrieve the calculated password for a given set of variables.

I tried writing the same code both for "console application" and "windows application" using command line parameters to determine the program use. No parameters = show the form, parameters = set the password. However I just can not get this to work (and the .exe is not even running as a service yet). Either the form is shown even when a parameter is given or no form is ever shown..

Can someone please advise how to write this? I'm not used to write in Visual Studio so I may be writing a wrong application type. I just need to know how to obtain an .exe that executes code with a command line parameter and shows a form without parameters.

Thanks for any tips!
 
I would say that a Windows Application would be the best option for a test app like this, If you change the entry point (Application Properties) to "Sub Main", and create a Module in your app with a Sub called "Main". Then put your starting code in that Sub to check for parameters, open the form (Application.Run(New MyForm)) or run the Function to change the password.

If you are already using this kind of code, could you post your entry code?
 
Thanks cjelec for the reply! So now I have one form (FrmAdmin.vb) and one module (AdminPasswordTool.vb) which contains the following code:

Code:
Module AdminPasswordTool

    Sub Main()
        'Check for arguments	
        Dim Parameter As String = LCase(Trim(Command()))
        Dim HaveParameters As Boolean = False
        Dim ValidParameters() As String = {"-s", "/s", "s", "-set", "/set", "set"}

        For Each Param As String In ValidParameters
            If Param = Parameter Then
                HaveParameters = True
                Exit For
            End If
        Next

        If HaveParameters Then
            Call SetPassword(CalculatePassword(Today))
        Else
            Application.Run(New FrmAdmin)
        End If
    End Sub


    Public Function CalculatePassword(ByVal PasswordDate As Date) As String
        .....
        Return Password
    End Function

    Private Sub SetPassword(ByVal Password As String)
        .....
    End Sub

End Module

I also altered the application startup to run Sub Main(). Now Visual Studio complains that "name 'Application' is not declared". Do I need to include additional namespaces to make this work?
 
Are you using vb.net 2005?

If so (I'm still using '03), try putting "My." before, "My.Application(New FrmAdmin)".

If that still doesn't work or you are not using 2005, try:
Code:
Dim Frm As New FrmAdmin
Frm.ShowDialog
 
That didn't work either (using VS2005). However I did get it running by importing "system.windows.forms" in the application properties! Strange that this isn't imported by default..

Everything is working as expected now, thanks for your assistance!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top