by Ralph Barton (5 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 11th May 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)
This code allows you to send command lines to your program, either when you first start it, or when it is already running. This is quite a
'all their names as the defaults. Then place the following code in the general
'section, and compile it to an exe. When you enter some commands in the command
'line, if it is this first copy of the program, it will use those, otherwise,
'it will close, and send them to the first copy you opened. Enter commands in
'the format (command name,first value,second value,etc), with the only spaces
'being between the commands, not between the values.
'Here is a list of the commands I have put in the program as an example:
'caption (This just changes the title of the form, e.g caption,Test.)
'colour (This just changes the colour of the form, e.g colour,255,0,255.)
'exit (This just exits the program, e.g exit.)
'msg (This just shows a msgbox, e.g msg,Hello.)
'E.g "C:\Yourprog.exe caption,Adder colour,0,0,255 msg,Ready"
'To change them, just add a case statement, making sure the the command is
'typed in lower case, as thats what the program changes the commands to before
'checking them against the case statments. Then use CmdItm to find the options
'they have used with them, e.g CmdItm(1) will be the first thing they put in
'after the comma.
'None of the commands are case sensitve.
'Also, you can set the timer interval lower, but I found this made some
'clipboard errors, so I made it a bit higher, and it seemed to help a bit.
'You may use the code in anyway you like, and I hope you find it useful.
'Code:
Private Sub Form_Load()
Dim TmpText As String
Timer1.Enabled=False
TmpText = Command$
If App.PrevInstance = True Then
If TmpText <> "" Then Clipboard.SetText ("**ComDat** " & TmpText)
End
Else
If TmpText <> "" Then Call CmdHandler(" " & TmpText)
End If
Timer1.Enabled = True
Timer1.Interval = 200
End Sub
Public Function CmdHandler(CmdText As String)
On Error GoTo CmdError
Dim CmdCnt As Byte
Dim CmdItms As Variant
Dim CmdItm As Variant
Clipboard.Clear
CmdItms = Split(CmdText, " ")
For CmdCnt = 1 To UBound(CmdItms)
CmdItm = LCase$(CmdItms(CmdCnt))
CmdItm = Split(CmdItm, ",")
Select Case CmdItm(0)
Case "caption"
Me.Caption = CmdItm(1)
Case "colour"
Me.BackColor = RGB(CmdItm(1), CmdItm(2), CmdItm(3))
Case "exit"
End
Case "msg"
MsgBox (CmdItm(1))
Case Else
MsgBox "Sorry, the command '" & CmdItm(0) & "' is not a valid command." & vbCr & "Please check your spelling, and that the command exists.", vbCritical + vbOKOnly, "Unknown Command"
End Select
Next CmdCnt
Text1.Text = "Your commands have been processed."
Exit Function
CmdError:
MsgBox "Sorry, there was an error while reading the command line." & vbCr & "Please check your formating, and try again.", vbCritical + vbOKOnly, "Processing Error"
Resume Next
End Function
Private Sub Timer1_Timer()
Dim TmpText As String
TmpText = Clipboard.GetText
Text1.Text = TmpText
If (TmpText Like "*ComDat*") And (Mid$(TmpText, 11, 1) = " ") Then
Timer1.Enabled = False
Call CmdHandler(TmpText)
Timer1.Enabled = True
End If
End Sub
No comments have been posted about This code allows you to send command lines to your program, either when you first start it, or when. Why not be the first to post a comment about This code allows you to send command lines to your program, either when you first start it, or when.