Saturday, March 31, 2012

subroutines or functions wont work.

any time i try coding a function or a subrouting the page won't run. iget error msg: BC30289: Statement cannot appear within a method body. End of method assumed.

here's my code. PLEASE HELP!, what am i typing wrong??
<%@dotnet.itags.org. Page Language="VB" %>
<script runat="server"
' Insert page code here
'

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<%
Dim arrPrimeNos, arrNames
Sub subPrintArray(arrToPrint, iStartValue, iStopValue)
Dim iCounter
For iCounter = iStartValue to iStopValue
Response.Write(arrToPrint(iCounter))
Response.Write("<BR>")
Next
End Sub
arrPrimeNos=Array(2,3,5)
arrName=Array("John","Mary","Bolek")

'call subroutine
subPrintArray arrNames, 2, 3
%
</form>
</body>
</html>1. You'd better put the server side code in <script> tag if you use inline coding. Using <% %> is not a .net way.

2. You can only call a method (function, subrouting or event handler) from a method (function, subrouting or event handler), so your code need to change like this:


<%@. Page Language="VB" %>
<script runat="server"
Sub page_load

Dim arrPrimeNos() As Integer = {2, 3, 5}
Dim arrNames() As String = {"John", "Mary", "Bolek"}

'call subroutine
subPrintArray arrNames, 2, 3
End Sub

Sub subPrintArray(arrToPrint, iStartValue, iStopValue)
Dim iCounter
For iCounter = iStartValue to iStopValue
Response.Write(arrToPrint(iCounter))
Response.Write("<BR>")
Next
End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
</form>
</body>
</html>


thank you very much

0 comments:

Post a Comment