How to replace "Wscript.Arguments" for VB6?

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
sexy69
Member
Member
Posts: 124
Joined: 2016-06-22, 17:21 UTC

How to replace "Wscript.Arguments" for VB6?

Post by *sexy69 »

This script is to show the full path of the selected file.

TC button:
Command: B:\test.vbs
Parameter: %L

Code: Select all

Set ABC = CreateObject("Scripting.FileSystemObject")
'*****************************
'Here is the problem.

Set Path = Wscript.Arguments  '<-- How to replace "Wscript.Arguments" for VB6?
'*****************************

Set MyFile = ABC.OpenTextFile(Path.Item(0),1)
   FullName1 = MyFile.ReadLine
MyFile.Close

Msgbox FullName
As the VBS script rewrite for VB6?
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48083
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Wscript.Arguments is correct, but you access them then by Path(i) and not Path.Item(i), see:
https://msdn.microsoft.com/en-us/library/z2b05k8s(v=vs.84).aspx
Author of Total Commander
https://www.ghisler.com
sexy69
Member
Member
Posts: 124
Joined: 2016-06-22, 17:21 UTC

Post by *sexy69 »

I need the code to VB6
User avatar
Stefan2
Power Member
Power Member
Posts: 4158
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 »

sexy69 wrote:I need the code to VB6
Google knows the answer, also specialized 'VB' forum.




 
sexy69
Member
Member
Posts: 124
Joined: 2016-06-22, 17:21 UTC

Post by *sexy69 »

The problem is that nobody knows the answer.
User avatar
Stefan2
Power Member
Power Member
Posts: 4158
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 »

sexy69 wrote:The problem is that nobody knows the answer.
No?
Well, I don't know, but how about Google "visual basic 6 command line arguments"


http://forums.codeguru.com/showthread.php?337778-Passing-in-Command-Line-Arguments-VB6
When you pass something from the Command Line to the VB app (compiled),
the arguments that are passed get stored into Command$.

You can use this variable to get the Command Line Arguments passed by the user

sArgs = Split(Command$, " ")
For iLoop = 0 To UBound(sArgs)
Debug.Print sArgs(iLoop)
Next


I am sure there must be a way, as VB6 was/is used by many coders.


 
sexy69
Member
Member
Posts: 124
Joined: 2016-06-22, 17:21 UTC

Post by *sexy69 »

TC button:
Command: B:\test.vbs
Parameter: %L or Parameter: %P%N %T%M

Code: Select all

Const ForReading = 1, ForWriting = 2, ForAppending = 8

Set dostep = CreateObject("Scripting.FileSystemObject")

                                  'VB6 reacts::
Set Path = Wscript.Arguments  ->  'Run-time error '424': Object required

If Path.Count = 1 Then
'   Parameter: %L
   Set Path2 = dostep.OpenTextFile(Path.Item(0),ForReading)
      FullPathSRC = Path2.ReadLine
   Path2.Close

'   Set MyFile = dostep.OpenTextFile("B:\TEMP\FullPathSRC.txt", ForWriting, True)
'      MyFile.WriteLine FullPathSRC
'   MyFile.Close
   Msgbox FullPathSRC
ElseIf Path.Count = 2 Then
'   Parameter: %P%N %T%M
'   Set MyFile = dostep.OpenTextFile("B:\TEMP\FullPathBoth.txt", ForWriting, True)
'      MyFile.WriteLine Path.Item(0)
'      MyFile.WriteLine Path.Item(1)
'   MyFile.Close
   Msgbox Path.Item(0) & vbnewline & Path.Item(1)
Else
   WScript.Echo "the parameter for the active window: %L, or both windows: %P%N %T%M"
End If

WScript.Quit
How to write a code for VB6?
sexy69
Member
Member
Posts: 124
Joined: 2016-06-22, 17:21 UTC

Post by *sexy69 »

Stefan2 wrote:
sexy69 wrote:The problem is that nobody knows the answer.
Well, I don't know, but how about Google "visual basic 6 command line arguments" 
You're right, you can do it.
Post Reply