VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Easy passing parameters to program

by German Bletel (2 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

Often you have to pass some parameters(Password,UserName,...) into
the application.This code gives you elegant and easy way to pass
as many parameters as you want.

Inputs
Add to exe line: Project1.exe /u 'UserName' /p 'Password' /d 'domain' Where UserName,Password,domain are strings Common formula: project1.exe {/[letter] string}
Assumes
Create new project.Add code to Form1.Make Project1.exe.Now you can pass into the application 3 parameters:Username ,Password,Domain (Whith little change you can pass as many parameters as you wont).

Rate Easy passing parameters to program

Const PARAMHEADER = "/"
Public Function getTokens(CommandLine As String) As Collection
  Dim reminder As String
  Dim col As New Collection
  Dim pos As Integer
  Dim param As String
  Dim paramValue As String
  Dim paramName As String
  
  reminder = CommandLine
  pos = InStr(reminder, " ")
  Do While pos > 0
    param = Trim(Left(reminder, pos - 1))
    If (Left(param, 1) = PARAMHEADER) Then
      Call AddParamCol(col, paramValue, paramName)
      paramValue = ""
      paramName = Mid(param, 2)
    Else
      paramValue = param
    End If
    reminder = Trim(Mid(reminder, pos + 1))
    pos = InStr(reminder, " ")
  Loop
  paramValue = Trim(reminder)
  Call AddParamCol(col, paramValue, paramName)
  
  Set getTokens = col
End Function
Private Sub AddParamCol(c As Collection, s As String, k As String)
  If k = "" Then Exit Sub
  On Error Resume Next
  Call c.Add(s, LCase(k))
End Sub
'--------------------------------------
Private Sub Form1_Load()
  Dim Args As Collection
   
  Set Args = getTokens(Command)
  On Error Resume Next
    User = Args("u")
    Password = Args("p")
    Domain = Args("d")
  'Add your variables and actions
End Sub

Download this snippet    Add to My Saved Code

Easy passing parameters to program Comments

No comments have been posted about Easy passing parameters to program. Why not be the first to post a comment about Easy passing parameters to program.

Post your comment

Subject:
Message:
0/1000 characters