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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mid() Function 1

Status
Not open for further replies.

demoniac

Programmer
Jun 14, 2001
63
US
Hello. I'm trying to create a form in Outlook at my company (exchange server 5.5, outlook 2000). But I can't seem to use the Mid function for some reason.

I'm not familiar with VBScript so I don't know if I have to do something special to be able to use it, but when I try it just says invalid function or arguement.

Anybody know how to stop this?
 
You cannot use Mid in VBScript as a way of substituting part of a string with different text, like you can in VBA.

Also Mid$ is not supported as VBScript does not have strong Data typing.

A.C.
 
Acron,

I don't understand what you mean by the Mid (or Mid$) function "substituting part of a string with different text"

The Mid Function Returns a Variant (String) containing a specified number of characters from a string.

To substituting part of a string with different text you use the Replace Function.

You are correct in that VBScript doesn't Support Mid$ (since all variables in VB Script are Variant in nature)

The Mid Function is the same in VBA and VBScript.



Codefish

 
There is a Mid() function which does as you say, but there is also a Mid Statement (only in VB & VBA, but not VBScript) which can be used to assign a new value to part (or all) of a string. Try the following in VB or VBA :

Sub TestMid()
Dim Test As String
Test = "Abcdef"
Mid(Test, 4) = "xyz"
MsgBox Test ' It should display "Abcxyz"
End Sub

A.C.
 
acron,

Quite correct - learn something new everyday!

Thus for In VBScript,

To get the same Functionality that the Mid Satement gives, demoniac will have to use a combination of Left and Right Functions. E.g.

Left(Test, 3) & "xyz" & Right(Test, Len(Test) - Len(sReplace) - 3)

Regards,

Codefish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top