Connect with Expertise | Find Experts, Get Answers, Share Insights

How to call a vb script funtion in form load ??

 
Join Date: Jan 2010
Posts: 3
#1: Jan 27 '10
Hi,

I am a new bi in asp...
I need to call a function in asp with vb script in form load...without button fire.

please give sample code...

Thanks and Regards,



Bijesh

yarbrough40's Avatar
C
 
Join Date: Jun 2009
Posts: 161
#2: Jan 27 '10

re: How to call a vb script funtion in form load ??


do you mean?

Expand|Select|Wrap|Line Numbers
  1. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2.  
  3. MyFunction()
  4.  
  5.     End Sub
  6.  
 
Join Date: Jan 2010
Posts: 3
#3: Jan 28 '10

re: How to call a vb script funtion in form load ??


Hi,

Actually I have currency conversion coding from INR to USD .But it will execute in Button click only...ie we need to give the amount in INR in textbox.and while clicking submit button , it wil convert the amount into USD and will show the output.

Instead of button click event, I need to show the output while the page loaded. I set the input as static(ie textbox value I set to some value).so by taking that input it will execute and show the corresponding amount in USD.


The following is the code....I need to call a function for this conversion...



<%@ language="VBScript" %>

<html>
<head>
<title>Currency Server ASP Example 2</title>
</head>

<body>
<!-- declare application object -->
<%
Const curncsrvReturnRateString = 1
Const curncsrvReturnRateNumber = 2
Dim objApplication, objCurrencies,URL


Set objApplication =Server.CreateObject("CurrencyServer.Application")
Set objCurrencies = objApplication.ActiveCurrencies


%>
&nbsp;






<table border=0>


<td style="visibility:hidden" ><%= objCurrencies.Count %></td></tr></table><br>

<!-- currency conversion form -->
<form onload=csexample2.asp method="POST">


<table>
<tr>
<td> </td>
<td><select name=CurrFrom style="HEIGHT: 22px; WIDTH: 166px;visibility:hidden; ">
<% For i = 1 To objCurrencies.Count
if Request.Form("CurrFrom") = "INR" then %>
<option selected><%="INR"%>
<% else %>
<option><%="INR"%>
<% end if%>
<% Next %>
</select>



</td>
<td> </td>
<td><select name=CurrTo style="HEIGHT: 22px; WIDTH: 166px;visibility:hidden;">
<% For i = 1 To objCurrencies.Count
if Request.Form("CurrTo") = "USD" then %>
<option selected><%= "USD"%>
<% else %>
<option><%= "USD"%>
<% end if%>
<% Next %>

</select></td>
</tr>
<tr>
<td>Amount to convert:</td>
<td>
<input name=FromValue value="100">


</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
<input type="submit" name="Convert" value=Convert>
</td>
<td>
</td>
<td></td>
<td></td>
</tr>
<tr>
</tr>
<tr>


<% dim ToValue %>
<% dim FromValue %>
<% FromValue=Request.Form("FromValue") %>

<!-- validation of input data -->
<% if (FromValue > "") and (IsNumeric(FromValue)) then
ToValue = objApplication.Convert(Request.Form("CurrFrom"), Request.Form("CurrTo"), Request.Form("FromValue"), true, ". ", curncsrvReturnRateString)
end if %>
<!-- empty -->
<% if FromValue = "" then ToValue = "" end if %>
<!-- alpha -->
<% if not IsNumeric(FromValue) then
FromValue = ""
ToValue = ""
end if
%>
<td>Result:</td><td><input name=ToValue Value="<%=ToValue%>"></td>
<td></td>
<td></td>
<!-- free resources -->
<% Set objApplication = Nothing %>


</tr>
</table>
</form>
</body>
</html>
yarbrough40's Avatar
C
 
Join Date: Jun 2009
Posts: 161
#4: Jan 28 '10

re: How to call a vb script funtion in form load ??


just give your function a name like "MyFunction" then I believe you can call it using something like:

onLoad=”MyFunction()”
 
Join Date: Jan 2010
Posts: 3
#5: Jan 29 '10

re: How to call a vb script funtion in form load ??


Hi,

If I need to call this in form load or page load???

Please give a sample code...How to call?

How the function look like??

Thanks and Regards
Bijesh
yarbrough40's Avatar
C
 
Join Date: Jun 2009
Posts: 161
#6: Jan 29 '10

re: How to call a vb script funtion in form load ??


I'm a .net programmer so I apologize if I can't be of further assistance. but it would seem to me that you could build a function (use 'sub') and then type "call" to call it. place the code within the body of the page. the sub procedure will run when the page loads.

Expand|Select|Wrap|Line Numbers
  1.         <script type="text/vbscript">
  2.  
  3. sub MySub()
  4. dim i
  5. i = 0
  6. End Sub
  7.  
  8. call MySub()
  9.  
  10. </script>
  11.  
jhardman's Avatar
E
M
C
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,941
#7: Jan 29 '10

re: How to call a vb script funtion in form load ??


OK, I need to clarify, and I'm not sure I follow your explanation of the problem.
1- Are you trying to run client-side VBScript? Although it is technically possible, I think only Internet Explorer ever supported that, and it was only standard in pre-IE7. Most people use Javascript to execute code on the browser. Nevertheless, if that is what you are trying to do, I can try to help you.
2- Are you trying to call an ASP function after the page is sent to the client? That will not work, the ASP script is completely finished by the time it is sent to the browser. Calling an ASP function after the browser receives the page is like trying to get a factory option installed on your car AFTER you receive it. If you want the function to execute while the form is being BUILT, that is another question.

Jared
Reply

Tags
vbscript load