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

Error declaring variable as string 1

Status
Not open for further replies.

teckiejon

Technical User
Feb 25, 2004
47
GB
I am trying to declare some variables at the start of a script but the code keeps erroring. For example the first line of code reads:

Dim StrData As String

Yet the script errors after AS (line1 char15) saying 'Expected End Of Statement'
Can anyone advise?
 
Hello techiejon,

vbs is late-binding. It takes on variables as variants. So if you want to declare it, just use dim StrData, no "As String" part.

regards - tsuji
 
Thankyou very much for your speedy response it has saved a lot of head scratching at my end
Further down the script I have other similarly written lines such as

Dim oRecipient As CDOEXM.IMailRecipient

Will this also apply for them too?

Many thanks for your help
 
techiejon,

Yes, it applies. It would translate into something like this if together with new keyword.
[tt] Dim oRecipient As new CDOEXM.IMailRecipient[/tt]
would be ported to late-binding
[tt] Dim oRecipient
'then some where later before using it
set oRecipient=createobject("CDOEXM.IMailRecipient")[/tt]

This is normal mode. It may not necessarily createobject(). It might be assigned from something resultant object etc...

With "Option Explicit", dim is strictly necessary (except for dynamic array), else it is optional.

- tsuji
 
Thats brilliant thankyou very much for your time
 
Thanks, techiejon!

Just want to correct the last sentence where I changed my mind in the phrasing without move the segment to proper place. It should be read of course like this.

>With "Option Explicit", dim is strictly necessary, else it is optional [blue](except for dynamic array)[/blue].

- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top