PDA

Click to See Complete Forum and Search --> : Questions about VB Script (Client) - Help.


Namo
Jan 28th, 2001, 02:17 AM
Hello , I would like to get info. about VB script client.

1. Can i load Controls in RUN TIME with VB SCRIPT client code? i mean, can i load controls, unload controls, and catch the events of the controls (I am talking about control array..)

2. Can i access all control properties? i mean,can i access the TAG property of listbox\checkbox control? what about visible property? for what properties can i access and for what i cant?

Any other info about the "power" of VBscript client code?

Thanks!
Namo

Skeen
Jan 29th, 2001, 09:58 AM
As far as I'm aware VBScript dosn't have an IDE such as a full language like VB.

I use it in ASP's where the VBScript is embedded into HTML so all graphical content such as list boxes and radio buttons for examle, are generated by the HTML but controlled by the vb script.

heres an example of what I mean. Its a loggon to a database I did a while ago. I've simplified it to the core basics that make it work.
This 1st page is straight html. It has two text boxes for a username and password. When the submit button is clicked, the second page is activated and the values typed in by the user are passed into the second script. The VBScript connects to the database and checks the username and password are valid. If they are, the security level assigned to that user is checked and they era redirected to the relevant page. The second script you will notice does not have any visual content, so the user will appear to go from the loggon screen to thier relavent menu page:

PAGE 1 CODE:

<html>
<head><title>Login Page</title></head>
<body>

<form method="post" action="Get_username.asp">
<table width="100%">
<tr>
<td width="50%" height="29" align="right"> <font size="3" face="Arial, Helvetica, sans-serif"

color="#000000">UserName:
</font></td>
<td width="50%" height="29"><font size="3" face="Arial, Helvetica, sans-serif"><b>
<input type="text" name="T1">
</b></font></td>
</tr>
<tr>
<td width="50%" height="33">
<div align="right"><font size="3" face="Arial, Helvetica, sans-serif" color="#000000">Password:
</font></div>
</td>
<td width="50%" height="33"> <font size="3" face="Arial, Helvetica, sans-serif"><b>
<input type="password" name="T2">
</b> </font> </td>
</tr>
</table>
<table width="100%">
<tr align="center">
<td>
<p>&nbsp;</p>
<p><a href="user_sorry3.html"><font size="3" face="Arial, Helvetica, sans-serif"

color="#990099"><font color="#3333FF">Forgotten
your password?</font></font></a></p>
</td>
</tr>

<tr align="center">
<td> <font size="2">
<input type="submit" name="Submit2" value="Submit">
<input type="reset" name="reset2" value="Reset">
</font><br>
<font face="Arial, Helvetica, sans-serif" size="2" color="#000000"> </font>
</td>
</tr>
</table>
</form>

</body>
</html>


PAGE 2 CODE:
(*Note, this page doesn't return any html, its a hidden script that checks validity of the user.)



<html>
<head><title></title>
</head>
<body>
<%

Dim cnAcqAcc
Dim cmAcqAcc
Dim rsUserPassword
Dim cmSQL
Dim cmmSQL
Dim cmpSQL
Dim StoredPassword
Dim Stored_ID
Dim rsID
Dim rsSL
Dim Security

Set cnAcqAcc = CreateObject ( "ADODB.Connection" )
cnAcqAcc.ConnectionString = "Provider=MSDASQL;DSN=DataBaseName;UID=UserID;PWD=UserPassword;"
cnAcqAcc.open

User = Request.Form("T1")
Pass = Request.Form("T2")

cmSQL= "SELECT Password FROM UserPassword WHERE Username = '" & User & "' AND Password = '" & Pass & "' "

Set rsUserPassword = cnAcqAcc.Execute( cmSQL )
If rsUserPassword.EOF then Response.redirect "user_sorry3.html"
rsUserPassword.MoveFirst
StoredPassword =rsUserPassword( "Password" )

cmmSQL= "SELECT Client_ID FROM UserPassword WHERE Username = '" & User & "' AND Password = '" & Pass & "' "

Set rsID = cnAcqAcc.Execute( cmmSQL )
If rsID.EOF then Response.redirect "user_sorry3.html"
rsID.MoveFirst
Stored_ID = rsID( "Client_ID" )

Response.Cookies("sText") = User


Response.Cookies("cID")= Stored_ID
Response.Cookies("BOG")= Pass
cmpSQL= "SELECT SecurLevel FROM UserPassword WHERE Username = '" & User & "' AND Password = '" & Pass & "' "

Set rsSL = cnAcqAcc.Execute( cmpSQL )
rsSL.MoveFirst
Security = rsSL( "SecurLevel" )

cnAcqAcc.Close
Set rsUserPassword = Nothing
Set rsID = Nothing
Set rsSL = Nothing

If StoredPassword = Pass AND Security = 2 Then
Response.Redirect "..companystats/callinfo/search.asp"


ElseIf StoredPassword = Pass AND Security = 3 Then
Response.Redirect "..companystats/callinfo/ro_ad_search_frame.asp"

ElseIf StoredPassword = Pass AND Security = 5 Then
Response.Redirect "..companystats/callinfo/ad_search_frame.asp"

ElseIf StoredPassword <> Pass Then
Response.Redirect "..companystats/callinfo/user_sorry3.html"

End If


%>
</body>
</html>


From here, depending how you have your database set up, the client user is redirected to one of three pages, an administrator level, a user level, or to a default error page if they are not a valid user on the database.

As you can see, text boxes are generated in the HTML, but the values place into T1 &T2 are posted into the next script (into the Vbscript) for manipulation.

If you haven't used VBScript before, its dead easy. I love it, but to give you an idea of how it works, try this:

open notepad and type the following:


MsgBox Date


...and then save it to your desktop as DateToday.vbs. When you open it todays date will appear in a messagebox like in vb. Active Server Pages (ASP's) are tops though. Quick to learn and very easy. To save an asp its extention is *.asp but you probably already know this.

In terms of the power of VBScript, a lot of VB's functions are apllicable, however a lot aren't. Also, VBScript is quite powerful, and because it is so simple it is possible to write dangerous code so I'm told. A freind of mine wrote a little VBScript app which recorded the username and password of everyone who logged on to his PC at work and wrote them to a text file, but apparantly it was also making entries to the windows registry and it was only 4-5 lines of code.
I've never screwed up with it though and I'm a novice at programming altogether.

To View ASP's, you must be in a server client situation, if you just try and open an asp in your web browser you'll just get the code script and not the page (Like perl in cgi scripts). To save you from uploading code to a server everytime you want to test it, get a copy of Microsoft's Personal Web Server (PWS). Place your scripts into the root directory of the server and then just typ the address http://nameofyourpc, and your login page will appear as it would on the net. I think PWS is on windows98 disc, and on the technet discs for NT4, however, I don't think its available on microsofts site as a download anymore. I don't know why because its a great development tool.

Anyway, hope any of this helps

Cheers 'n' beers,

Skeen.

Namo
Jan 30th, 2001, 01:22 AM
Thanks,
but still, i wanna know if you can load controls (in run time) with vb script (control array).

and i guess you cant use all propeties of the controls in vbscript CLIENT - right?

What is the best way to give "power" to the client? i mean use controls , access thier properites, control events etc... (i talking about MS tools only)
(I want more then just use listbox and combo with 2 prorpties)

What do you think about dhtml? ocx? or other ideas?
any other tips?

Thanks for the answers!!
Namo.