473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

sub and for next loop

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
4 2082
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Petr Bravenec | last post by:
I have found that when I use the RETURN NEXT command in recursive function, not all records are returned. The only records I can obtain from function are records from the highest level of...
13
by: PeterZ | last post by:
Hi, Back to basics! My understanding is that the only way to exit a For-Next loop prematurely is with the 'break' keyword. How are you supposed to do that if you're inside a Switch...
14
by: Ale K. | last post by:
i know that For...Next as a Exit For.... there is any way from the middle of my for...next code to go to the next item and jump out part of my code , like the same thing that can be done with exit...
23
by: Mitchell Vincent | last post by:
Is there any way to "skip" iterations in a for loop? Example : for x = 1 to 10 if something = 1 next endif
13
by: andreas | last post by:
Hi, I want to do some calculation like ( t1 and t2 are known) for i = t1 to t2 for j = t1 to t2 ..... ..... for p = t1 to t2 for q = t1 to t2
4
by: Neo | last post by:
I found on error resume next doesn't work in for each... e.g. on error resume next for each x in y 'do stuff next if you have an error in for each loop, it falls in infinite loop... it...
0
ADezii
by: ADezii | last post by:
If you want to visit each item in an Array, you have two alternatives: Use a For Each..Next loop, using a Variant to retrieve each value in turn. Use a For...Next loop, looping from the Lower...
0
by: Semajthewise | last post by:
Hi all. I'm starting on my next part of my teach myself vb program. What I am trying to do is on button click open a textfile showing the math as it would be done long hand. I started writing the...
2
ADezii
by: ADezii | last post by:
If you are executing a code segment for a fixed number of iterations, always use a For...Next Loop instead of a Do...Loop, since it is significantly faster. Each pass through a Do...Loop that...
6
by: baldrick | last post by:
Hi, I have some intensive number crunching code that I want to break up into threads so PCs with several processors can do the job quicker. I have a loop that will go from say 1 to 10, and for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.