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!

Calling a value in a script 1

Status
Not open for further replies.

staleb

Programmer
Feb 7, 2005
45
NO
Hi

How is the syntax for calling a string-value from a vb-script.

I have:

Sub Document()
dim sPath as string = "\\myserver\test.doc"

Dim script as string
+++

script &= " set Doc = Word.Documents.Open('" & sPAth & "') " & vbCrLf

++++

Me.Page.RegisterStartupScript("Open", script)

End Sub


How do I refference the sPath in my scriptcode?
When I do the way I have described here I get error.
Does anyone know the right syntax
 
I get error
The usual way is to post the error message as, at least for me, the crystal bowls are in vacation.
Anyway, the code you posted is NOT VBScript.
What is your intent ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
The error message is just: Syntax error.
Because the script-line is this when it get rendered:
set Doc = Word.Documents.Open('\\myserver\test.doc')

The code is a vb-script I only didnt paste the whole script. It was to long:

Dim script As String
script = "<script language=""vbscript"">" & vbCrLf
script &= " Dim Word" & vbCrLf
script &= " Dim Doc" & vbCrLf
script &= " Set Word = CreateObject (""Word.Application"") " & vbCrLf
script &= " Set Doc = CreateObject(""Word.Document"") " & vbCrLf
script &= " set Doc = Word.Documents.Open('" & sDokNavn & "') " & vbCrLf
script &= " Doc.SaveAs("" & sDokNavnLokalt & "")" & vbCrLf
script &= "</script>" & vbCrLf

Me.Page.RegisterStartupScript("Open", script)



This code is included in a a sub called Document.
And the script works fine if I adress the path directly, but I want to adress it through a variable since there a many documents
 
I didn't know that VBScript is accepting the &= and the Dim ... AS ... syntax...
Anyway, replace this:
script &= " Set Doc = CreateObject(""Word.Document"") " & vbCrLf
script &= " set Doc = Word.Documents.Open('" & sDokNavn & "') " & vbCrLf
By this:
script &= " Set Doc = Word.Documents.Open(""" & sDokNavn & """) " & vbCrLf

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks

I thought I have tried many different syntax's, but I did think about putting three " in a row.
Thanks!!
 
So did it work? I still don't see how it could work both the As and the &= cause the script host to choke with compile errors.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top