parameters in visual basic 2010 - visual-studio-2010

how can use parameters in my vb application?
i want to make it so that when the parameter its "/y" i want some thing like this to hapen
if parameter = "/y" then
msgbox("you used the parameter /y")
else
msgbox("you dint use any parameter")
end if
i want some thing like this to hapen when i use the parameter "/y"
the parameters are used when for ex: im running the .exe on cmd

You can change Sub Main() to
Sub Main(ByVal cmdArgs() As String)
And use the argument array that way. This has been valid in VB.NET for many versions.

The passed in command line arguments will be available to the Main procedure of your application.
These come in as an array of strings.

Related

VBScript passing value by reference (VarPtr) to ActiveX function

I'm trying this:
Dim oApp
Dim iReturnedResult
Set oApp = CreateObject("Some.Application")
Set F_Ord = oApp.Documents.Open("Window 1", VarPtr(iReturnedResult))
The ActiveX control expects the second parameter to be a Long by reference.
This works perfectly well inside Excel VBA.
I can run this step by step, and see the result is returned like it should.
But, when I move this code to a VBS file and run it from the command line (CScript.exe), I get an error 800A000D, meaning it's the wrong type.
I have also tried creating an array instead, and tested with these commands, without any luck:
Set F_Ord = oApp.Documents.Open("Window 1", VarPtr(iReturnedResult(0)))
Set F_Ord = oApp.Documents.Open("Window 1", iReturnedResult(0))
Does anyone know how to pass a long variable by reference to an ActiveX control from VBScript?
The simple answer is VarPtr() is not supported by VBScript.
To my knowledge, there is no equivalent that allows you to pass a pointer to a variables memory address.
Useful Links
Visual Basic for Applications Features Not In VBScript

Scripting Word from vbs

I'm trying to get Word to fill in cells in a table. The script works when run as a macro from within Word, but fails when saved as a .vbs file and double-clicked, or run with wscript. This is a part of it.
set obj = GetObject(,"Word.Application)
With obj
With .Selection
MsgBox .text
If (.Information(wdWithInTable) = True) Then
.Collapse Direction:=wdCollapseStart
tCols = .Tables(1).Columns.Count
tRow = .Information(wdStartOfRangeRowNumber)
tCol = .Information(wdStartOfRangeColumnNumber)
For I = 2 To 5
.Tables(1).Cell(tRow, I).Range.Text = "fred" & Str(I)
Next
` now make new row
For I = 1 To tCols - tCol + 1
.MoveRight unit:=wdCell
Next
End If
End With
End With
I have three problems. First, it won't compile unless I comment out the .Collapse and .MoveRight lines. Second, although the MsgBox .text displays the selected text, I get "out of range" errors if I try to access any .Information property.
I'm sure I'm missing something very simple: I usually write software for Macs, and I'd do this using AppleScript. This is my first attempt at getting anything done under Windows.
VBScript and VBA are different languages.
They are a bit similar, but not very. Moreover, VBScript is not like AppleScript; it doesn't let you easily interface with running programs.
The interfaces you'll get from VBScript can behave subtly differently in VBA and VBScript. However, I think you've got two problems here:
:= is invalid syntax in VBScript; you'll need to find an alternative way of calling the function. Try just using positional arguments.
You've no guarantee that this will open the expected file; there could be another instance of Word that it's interacting with instead.
Since your code is not running within the Word environment it would require a reference to the Word object library in order to use enumeration constants (those things that start with wd).
VBScript, however, cannot work with references, which means the only possibility is to use the long value equivalents of the enumerations. You'll find these in the Word Language References. Simplest to use is probably the Object Browser in Word's VBA Editor. (In Word: Alt+F11 to open the VBA Editor; F2 to start the Object Browser; type in the term in the "Search" box, click on the term, then look in the bottom bar.)
The code in the question uses, for example:
wdWithInTable
wdCollapseStart
wdStartOfRangeRowNumber
wdStartOfRangeColumnNumber
wdCell
The reason you get various kinds of errors depends on where these are used.
Also, VBScript can't used named parameters such as Unit:=. Any parameters must be passed in comma-delimited format, if there's more than one, in the order specified by the method or property. If there are optional parameters you don't want to use these should be left "blank":
MethodName parameter, parameter, , , parameter

Assign a string value as a result of a command

I want to put a string result of a command in WinDbg in a variable for a later use.
For example, in a memory breakpointI want to save the result of - lm1ma eip that returns me the current module, for later comparison in $spat command.
If anyone knows a better way to achieve the goal of determining if the current debugged module is a specific module, inside a conditional breakpoint, it could be also helpful.
Use as /c Name CommandString.
It creates an alias to the results of executing the specified command.
https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/as--as--set-alias-

Command$ value disappears

I have a VB6 app. I am trying to figure out what command line parameters got passed into the application. If I type in ? Command$ into the Immediate window, it prints out the command line params fine. Same, if I place Command$ into the Watch window.
However, if I assign the Command$ function to a string:
Dim s as string
s = Command$
the s variable will be empty.
What am I missing here?
I should mention that the code in question is located not in the main form, but in a DLL 2 levels down (e.g. the form calls DLL1, then DLL1 calls DLL2).
Pretty sure the GetCommandLine() API would be an alternative (it should work for anything thats in-process with the executable) so you could try that instead of Command$.

Cannot execute cut-n-paste VBScripts

I have been going mad trying to figure out why my scripts weren't working, until I started copying and pasting sample source code directly from a few websites only to have it fail there as well. I am getting the following error in my VBScripts:
C:\temp\vbs\script.vbs(19, 53) Microsoft VBScript compilation error: Expected statement'
For a line of code that looks like this:
wdoc.Application.Selection.Find.Execute Replace:=wdReplaceAll
This is interfacing with Microsft Word in Office 2007 to conduct a search and replace. Index 53 point directly to the := part of the assignment. Since this type of syntax doesn't work on my machine and I am using it from several websites, I was wondering if the cscript.exe I use is out of date.
Am I not calling cscript properly?
Named arguments (Param:=Value) are Visual Basic and VBA feature; this syntax isn't supported in VBScript.
In VBScript, you need to preserve the actual order of a routine's arguments. If a specific argument is optional and you want to use its default value, you need to simply omit that argument. So, your code should look like this:
Const wdReplaceAll = 2
wdoc.Application.Selection.Find.Execute , , , , , , , , , , wdReplaceAll

Resources