?
Solved

Simple VBScript Question   src=

Posted on 2003-02-26
17
Medium Priority
?
314 Views
Last Modified: 2010-04-06
I know my functions work.  I tried to put them in a .vbs
file by themselves and then just do a

<script language="vbscript" src="encrypt.vbs">

and it will not read the functions...  am I missing anything?

this is the source for the functions which works fine in the main file ..


Thank you,

- David



function Encrypt (byval str)
tempstr=""
for i=1 to len(str)
  ch=mid(str,i,1)
  ch=chr(asc(ch)+10)
  tempstr=tempstr+ch
next
Encrypt=tempstr
end function

function Decrypt (byval str)
tempstr=""
for i=1 to len(str)
  ch=mid(str,i,1)
  ch=chr(asc(ch)-10)
  tempstr=tempstr+ch
next
Decrypt=tempstr
end function
0
Comment
Question by:brookd
  • 6
  • 5
  • 3
  • +2
17 Comments
 
LVL 4

Expert Comment

by:whammy
ID: 8029997
If you have them in a .vbs file by themselves, you can't use script tags...

Example:


time.vbs:

MsgBox Now()
MsgBox FormatDateTime(Now(), 0)
MsgBox FormatDateTime(Now(), 1)
MsgBox FormatDateTime(Now(), 2)
MsgBox FormatDateTime(Now(), 3)
MsgBox FormatDateTime(Now(), 4)
0
 
LVL 4

Expert Comment

by:whammy
ID: 8030024
Perhaps you're confusing local vbscript files on a windows system with using them server-side on an ASP platform?

Perhaps this helps?:

function Encrypt (byval str)
tempstr=""
for i=1 to len(str)
 ch=mid(str,i,1)
 ch=chr(asc(ch)+10)
 tempstr=tempstr+ch
next
Encrypt=tempstr
end function

function Decrypt (byval str)
tempstr=""
for i=1 to len(str)
 ch=mid(str,i,1)
 ch=chr(asc(ch)-10)
 tempstr=tempstr+ch
next
Decrypt=tempstr
end function

MsgBox Encrypt("ABCDE")
MsgBox Decrypt("PQRST")
0
 
LVL 4

Expert Comment

by:whammy
ID: 8030031
Oops, I meant this:

whatever.vbs:
=============

function Encrypt (byval str)
tempstr=""
for i=1 to len(str)
 ch=mid(str,i,1)
 ch=chr(asc(ch)+10)
 tempstr=tempstr+ch
next
Encrypt=tempstr
end function

function Decrypt (byval str)
tempstr=""
for i=1 to len(str)
 ch=mid(str,i,1)
 ch=chr(asc(ch)-10)
 tempstr=tempstr+ch
next
Decrypt=tempstr
end function

MsgBox Encrypt("ABCDE")
MsgBox Decrypt("KLMNO")
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:syn_siju
ID: 8031999
Hi
If u are trying for Server side ASP scripting, These guidelines may help u,

What ever be the vbs file, keep in a directory in the server.
In the ASP file where u want to access these functions, include the .vbs file as follows
<!--#include /dir/filename.vbs-->

then u can access these functions as if it is coded in the same asp page as u are witing now
0
 

Author Comment

by:brookd
ID: 8040522
Hi,
  I forgot to mention that I was not using asp ..
  I thought that I could create a vbs file just the same
  as creating a jscript file .js  and that I could
  include my functions with no problem , but maybe
  plain Vbscript doesn't allow a src include like Jscript.

  /? ? ?    Thank you for all of your responses.

-- David

(I would have the point value increased but I only had
< 50 points and the system wouldn't let me. .. ) :)

0
 
LVL 1

Expert Comment

by:spiritwithin
ID: 8045676
Maybe your missing the type attribute:

<script language="vbscript" type="text/vbscript" src="encrypt.vbs"></script>

?
0
 
LVL 1

Expert Comment

by:spiritwithin
ID: 8045685
(I did not try it, so no wonder please, if it does not work.)
0
 
LVL 4

Expert Comment

by:whammy
ID: 8045704
Are you trying to use VBScript client-side?

If so I'm not sure about how to include them, but I would advise against doing so anyway if this is the case (unless this is for an intranet application where you KNOW everyone ABSOLUTELY uses Internet Explorer), since VBScript is only supported by Internet Explorer client-side.

Just a thought...
0
 

Expert Comment

by:craZcoder
ID: 8055398
If you are using VBScript for client side coding, use the following code to include the vbs file.
<script language="vbscript" src="encrypt.vbs">
</script>

And then call the VB function using the following
<script>
strEnc=Encrypt(somestring)
</script>

(provided you have declared strEnc and somestring)

Pls note that this works only in I.E.

HTH,
craZcoder.
0
 

Author Comment

by:brookd
ID: 8065815
craZcode ,
You would think this would work.

<script language="vbscript" src="c:\encrypt.vbs"><script>
<script language="vbscript">
dim s,t
s="Hello World"
msgbox (s)
' document.write (s)
t=encrypt(s)
document.write (t)
</script>

But for some reason it doesn't..
Out of desparation, here is the whole program.. Can you
convert it into two files... and test it with IE ?

<script language="vbscript">
s="Hello World"
msgbox (s)
' document.write (s)
t=encrypt(s)
document.write (t)

function Encrypt (byval str)
tempstr=""
for i=1 to len(str)
 ch=mid(str,i,1)
 ch=chr(asc(ch)+10)
 tempstr=tempstr+ch
next
Encrypt=tempstr
end function

function Decrypt (byval str)
tempstr=""
for i=1 to len(str)
 ch=mid(str,i,1)
 ch=chr(asc(ch)-10)
 tempstr=tempstr+ch
next
Decrypt=tempstr
end function


</script>
0
 
LVL 4

Expert Comment

by:whammy
ID: 8068328
Hmm, have you verified that the path c:\encrypt.vbs is correct? That definitely would not work on a webpage, I have never included a .vbs file like that either... so I am not sure if that works!
0
 
LVL 1

Expert Comment

by:spiritwithin
ID: 8068533
Should'nt files of such locations be defined with something like file:///C:/encrypt.vbs ?

However, put the file in the same folder as the html file is and just set the src to "encrypt.vbs" only.
0
 

Accepted Solution

by:
craZcoder earned 80 total points
ID: 8069478
Hi,
Tested your code, its working fine for me if I put it in two separate files.
Here are the two files.

1. Test.htm
<HTML>
<HEAD>
<TITLE>Test Page</TITLE>
<script language="vbscript" src="encrypt.vbs"></script>
<script language="vbscript">
s="Hello World"
msgbox (s)
' document.write (s)
t=encrypt(s)
document.write (t)
</script>
</HEAD>
<BODY>
<P>Hello There</P>
</BODY>
</HTML>

2. Encrypt.vbs
function Encrypt (byval str)
tempstr=""
for i=1 to len(str)
ch=mid(str,i,1)
ch=chr(asc(ch)+10)
tempstr=tempstr+ch
next
Encrypt=tempstr
end function

function Decrypt (byval str)
tempstr=""
for i=1 to len(str)
ch=mid(str,i,1)
ch=chr(asc(ch)-10)
tempstr=tempstr+ch
next
Decrypt=tempstr
end function

Pls note that I have put Test.htm and encrypt.vbs in the same folder. If you put encrypt.vbs in a subfolder say scripts, the script tag will change to
<script language="vbscript" src="scripts/encrypt.vbs"></script>

I suggest that you test with the files in the same folder and if it works, tinker with the path.

As per whammy, "C:/encrypt.vbs" will not work. You have to use a file path or relative path.

Let me know if it works,
Cheers,
craZcoder.

0
 

Author Comment

by:brookd
ID: 8073253
Both CraZCoder and spiritwithin are correct , strange I thought I tried that,.. but I probably made a typo.. I increased the point value,, and I'm going to award to CraZCoder ... Thank you all !

Here's what I ended up with:

<script language="vbscript" src="file:///c:\encrypt.vbs"></script>
<script language="vbscript">
s="Hello World"
msgbox (s)
' document.write (s)
t=encrypt(s)
document.write (t)
</script>

-- David
0
 

Author Comment

by:brookd
ID: 8073261
It wouldn't let me increase the point value, sorry..
0
 
LVL 4

Expert Comment

by:whammy
ID: 8076038
Keep in mind that the .vbs file can be downloaded, so this isn't secure at all. :=|
0
 

Author Comment

by:brookd
ID: 8076062
yes, this was just for fun,.. if I had access to asp , I would have written it there,.. it seemed easiest to write with vb string functions  . . .

Thank you all ...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question