By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,929 Members | 1,830 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,929 IT Pros & Developers. It's quick & easy.

sub and for next loop

P: n/a
Hello,

I have a SUB which has input variables. If I run it once its okay, but I
need to include it in a for....next loop.

Can this be done ?

for i=0 to 100
call mySub(arr(0,i))
next

sub mySub(var)
.....code
end sub

Thanks,
Andrew.
Jul 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Yes, this is fine. What is not working for you and with what code?

Ray at work

"AndrewM" <sa***@island-style.net> wrote in message
news:Op**************@TK2MSFTNGP11.phx.gbl...
Hello,

I have a SUB which has input variables. If I run it once its okay, but I
need to include it in a for....next loop.

Can this be done ?

for i=0 to 100
call mySub(arr(0,i))
next

sub mySub(var)
....code
end sub

Thanks,
Andrew.

Jul 19 '05 #2

P: n/a
have you tried?
You should be able to call functions and subs from within a loop

--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"AndrewM" <sa***@island-style.net> wrote in message
news:Op**************@TK2MSFTNGP11.phx.gbl...
Hello,

I have a SUB which has input variables. If I run it once its okay, but I
need to include it in a for....next loop.

Can this be done ?

for i=0 to 100
call mySub(arr(0,i))
next

sub mySub(var)
....code
end sub

Thanks,
Andrew.

Jul 19 '05 #3

P: n/a
Hello,

I'm getting a line error as follows

Error Type:
Microsoft VBScript runtime (0x800A0034)
Bad file name or number
/xc/staticScript/untitled0.asp, line 38
I have marked line 38 with -------------->>>>>>

If I replace
"call
createStaticPage(avarGeneral(0,i),avarGeneral(1,i) ,avarGeneral(2,i),avarGene
ral(3,i))"
with
"call
createStaticPage(avarGeneral(0,0),avarGeneral(1,0) ,avarGeneral(2,0),avarGene
ral(3,0))"
in order to maintain the loop but only call one set of input values all
works okay.

Thanks
Andrew.

************************************************** **
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../../Connections/XcapeSQL.asp" -->
<%
set metainfo = Server.CreateObject("ADODB.Recordset")
metainfo.ActiveConnection = MM_XcapeSQL_STRING
metainfo.Source = "{call dbo.metaInfo}"
metainfo.CursorType = 0
metainfo.CursorLocation = 2
metainfo.LockType = 3
metainfo.Open()
metainfo_numRows = 0
if not metainfo.BOF OR NOT metainfo.EOF then
avarGeneral = metainfo.GetRows(10)
metainfo.close
set metainfo = nothing
end if
%>
<%
rows = UBound(avarGeneral, 2)
for i=0 to rows
call
createStaticPage(avarGeneral(0,i),avarGeneral(1,i) ,avarGeneral(2,i),avarGene
ral(3,i))
next
%>
<%
sub createStaticPage(propID, propName, resort, area)
strPropName = propName
strPropName = Replace(strPropName, " ", "_")
strResName = resort
strResName = Replace(strResName, " ", "_")
strAreaName = area
strAreaName = Replace(strAreaName, " ", "_")
Dim fs, file, path
Set fs = CreateObject("Scripting.FileSystemObject")
path = Server.MapPath("/xc/")&"\xc"&strResName&""
IF (fs.FolderExists(path)<>true)THEN
fs.CreateFolder(path)
END IF
-------------->>>>>>Set file = fs.CreateTextFile(path & "/" & strPropName
&".asp", true)
file.WriteLine("<"&"%")
file.WriteLine("intPropID = """&propID&"""")
file.WriteLine("%"&">")
file.WriteLine("<!--#include file=""../../Connections/XcapeSQL.asp"" -->")
file.WriteLine("<!--#include
file=""../../include/code/incStaticPageScript.asp""-->")
file.WriteLine("<!--#include file=""../../include/code/Recordsets.asp""-->")
file.WriteLine("<html>")
file.WriteLine("<head>")
file.WriteLine(" <!--#include file=""../../xc/include/head.asp""-->")
file.WriteLine("</html>")
file.Close
'Set file = Nothing
'Set fs = Nothing
'**************************************
'Dim 2fs, folder, files, fileName, 2path
Set fs = CreateObject("Scripting.FileSystemObject")
path = Server.MapPath("/xc/")&"\xc"&strResName&""
path2 = Server.MapPath("/xc/")&"\xc"&strAreaName&""
IF (fs.FolderExists(path2)<>true)THEN
fs.CreateFolder(path2)
END IF
If (fs.FolderExists(path)=true) Then
Set file = fs.CreateTextFile(path2&"/"&strResName&".asp", true)
Set folder = fs.GetFolder(path)
Set files = folder.files
For each fileName in files
strLinkName = Left(fs.GetFileName(fileName),
Len(fs.GetFileName(fileName))-4)
file.WriteLine("<a
href=""../xc"&strResName&"/"&fs.GetFileName(fileName)&""">"&strLinkName&" </a
<br>") Next
End If
file.Close
Set file = Nothing
Set files = nothing
Set folder = nothing
Set fs = nothing
'**************************************
END sub
response.redirect "StaticPage.asp"'?propID="&intPropID&""
%>
************************************************** **************
"Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
message news:uH**************@tk2msftngp13.phx.gbl... Yes, this is fine. What is not working for you and with what code?

Ray at work

"AndrewM" <sa***@island-style.net> wrote in message
news:Op**************@TK2MSFTNGP11.phx.gbl...
Hello,

I have a SUB which has input variables. If I run it once its okay, but I
need to include it in a for....next loop.

Can this be done ?

for i=0 to 100
call mySub(arr(0,i))
next

sub mySub(var)
....code
end sub

Thanks,
Andrew.


Jul 19 '05 #4

P: n/a
Okay, I've found the problem. Some names in the database had the character
"|" in them as a separator. Someone obviously thought this was a cool way of
writing the name.

Thanks,
Andrew.
"AndrewM" <sa***@island-style.net> wrote in message
news:OL**************@TK2MSFTNGP11.phx.gbl...
Hello,

I'm getting a line error as follows

Error Type:
Microsoft VBScript runtime (0x800A0034)
Bad file name or number
/xc/staticScript/untitled0.asp, line 38
I have marked line 38 with -------------->>>>>>

If I replace
"call
createStaticPage(avarGeneral(0,i),avarGeneral(1,i) ,avarGeneral(2,i),avarGene ral(3,i))"
with
"call
createStaticPage(avarGeneral(0,0),avarGeneral(1,0) ,avarGeneral(2,0),avarGene ral(3,0))"
in order to maintain the loop but only call one set of input values all
works okay.

Thanks
Andrew.

************************************************** **
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../../Connections/XcapeSQL.asp" -->
<%
set metainfo = Server.CreateObject("ADODB.Recordset")
metainfo.ActiveConnection = MM_XcapeSQL_STRING
metainfo.Source = "{call dbo.metaInfo}"
metainfo.CursorType = 0
metainfo.CursorLocation = 2
metainfo.LockType = 3
metainfo.Open()
metainfo_numRows = 0
if not metainfo.BOF OR NOT metainfo.EOF then
avarGeneral = metainfo.GetRows(10)
metainfo.close
set metainfo = nothing
end if
%>
<%
rows = UBound(avarGeneral, 2)
for i=0 to rows
call
createStaticPage(avarGeneral(0,i),avarGeneral(1,i) ,avarGeneral(2,i),avarGene ral(3,i))
next
%>
<%
sub createStaticPage(propID, propName, resort, area)
strPropName = propName
strPropName = Replace(strPropName, " ", "_")
strResName = resort
strResName = Replace(strResName, " ", "_")
strAreaName = area
strAreaName = Replace(strAreaName, " ", "_")
Dim fs, file, path
Set fs = CreateObject("Scripting.FileSystemObject")
path = Server.MapPath("/xc/")&"\xc"&strResName&""
IF (fs.FolderExists(path)<>true)THEN
fs.CreateFolder(path)
END IF
-------------->>>>>>Set file = fs.CreateTextFile(path & "/" & strPropName
&".asp", true)
file.WriteLine("<"&"%")
file.WriteLine("intPropID = """&propID&"""")
file.WriteLine("%"&">")
file.WriteLine("<!--#include file=""../../Connections/XcapeSQL.asp"" -->")
file.WriteLine("<!--#include
file=""../../include/code/incStaticPageScript.asp""-->")
file.WriteLine("<!--#include file=""../../include/code/Recordsets.asp""-->") file.WriteLine("<html>")
file.WriteLine("<head>")
file.WriteLine(" <!--#include file=""../../xc/include/head.asp""-->")
file.WriteLine("</html>")
file.Close
'Set file = Nothing
'Set fs = Nothing
'**************************************
'Dim 2fs, folder, files, fileName, 2path
Set fs = CreateObject("Scripting.FileSystemObject")
path = Server.MapPath("/xc/")&"\xc"&strResName&""
path2 = Server.MapPath("/xc/")&"\xc"&strAreaName&""
IF (fs.FolderExists(path2)<>true)THEN
fs.CreateFolder(path2)
END IF
If (fs.FolderExists(path)=true) Then
Set file = fs.CreateTextFile(path2&"/"&strResName&".asp", true)
Set folder = fs.GetFolder(path)
Set files = folder.files
For each fileName in files
strLinkName = Left(fs.GetFileName(fileName),
Len(fs.GetFileName(fileName))-4)
file.WriteLine("<a

href=""../xc"&strResName&"/"&fs.GetFileName(fileName)&""">"&strLinkName&" </a
<br>")

Next
End If
file.Close
Set file = Nothing
Set files = nothing
Set folder = nothing
Set fs = nothing
'**************************************
END sub
response.redirect "StaticPage.asp"'?propID="&intPropID&""
%>
************************************************** **************
"Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
message news:uH**************@tk2msftngp13.phx.gbl...
Yes, this is fine. What is not working for you and with what code?

Ray at work

"AndrewM" <sa***@island-style.net> wrote in message
news:Op**************@TK2MSFTNGP11.phx.gbl...
Hello,

I have a SUB which has input variables. If I run it once its okay, but I need to include it in a for....next loop.

Can this be done ?

for i=0 to 100
call mySub(arr(0,i))
next

sub mySub(var)
....code
end sub

Thanks,
Andrew.



Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.