?
Solved

Simple VBScript Question   src=

Posted on 2003-02-26
17
Medium Priority
?
311 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

777 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