Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Combining Ubound with loop? >> If Ubound = 10, then do loop?

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,61099
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Combining Ubound with loop? >> If Ubound = 10, then do loop?
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Combining Ubound with loop? >> If Ubound = 10, th... - 6/5/2008 7:52:44 PM   
  TKS


Posts: 187
Score: 0
Joined: 5/16/2008
Status: offline
Here's the Ubound code snippet:


      

Here's the loop:


      
 
 
Post #: 1
 
 RE: Combining Ubound with loop? >> If Ubound = 10... - 6/5/2008 8:19:30 PM   
  TKS


Posts: 187
Score: 0
Joined: 5/16/2008
Status: offline
Here's the explanation of this problem I sent off to TNO:
_______________________________
Hey TNO,

I've reached coders block, and need help. Here's what I've got so far:

This code snippet keeps adding 1 onto a, making the type of File Progression I'm looking for:
    Option Explicit     Const ForReading = 1, ForWriting = 2, ForAppending = 3     Dim FSO: Set FSO = CreateObject("Scripting.FileSystemObject")     Dim a: a = 1
    Dim post: post = post.value         Do Until Not FSO.FileExists("IF" & a & ".html")     a = a + 1     Loop         Dim Obj: Set Obj = FSO.CreateTextFile("IF" & a & ".html", ForAppending, True)     Obj.WriteLine("<!--asdf-->")
    Obj.WriteLine (post)     Obj.Close

While this code snippet counts how many times "<!--asdf-->" is inserted into IFa.html:

    Const ForReading = 1,ForWriting = 2, ForAppending = 8     Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")     Dim objFile: Set objFile = objFSO.OpenTextFile("IFa.html", ForReading)     Dim strText: strText = objFile.ReadAll     objFile.Close     msgBox UBound(Split(strText, "<!--asdf-->"))

What I'm trying to do, is combine the First and Second code snippets like this:

If Ubound(Split(strText, "<!--asdf-->")) = 10 Then
Create the next File in Progression (a+1)
Else
Append to the current File in Progression (Obj.WriteLine "<!--asdf-->" & (post))
__________________
So the idea is to Create the next Text File in Progression, when the Ubound of the current Text File is: Ubound(Split(strText, "<!--asdf-->")) = 10
___________________
Hope this makes sense,

-TKS

(in reply to TKS)
 
 
Post #: 2
 
 RE: Combining Ubound with loop? >> If Ubound = 10... - 6/6/2008 12:23:47 AM   
  dm_4ever


Posts: 2664
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
So basically you're trying to limit the number of "asdf" occurances per file?

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to TKS)
 
 
Post #: 3
 
 RE: Combining Ubound with loop? >> If Ubound = 10... - 6/6/2008 2:41:48 AM   
  TKS


Posts: 187
Score: 0
Joined: 5/16/2008
Status: offline
quote:

ORIGINAL: dm_4ever

So basically you're trying to limit the number of "asdf" occurances per file?


Hey dm_4ever,

Yes, basically
Thanks for taking an interest.

-TKS

(in reply to dm_4ever)
 
 
Post #: 4
 
 RE: Combining Ubound with loop? >> If Ubound = 10... - 6/6/2008 4:08:18 AM   
  dm_4ever


Posts: 2664
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Do a search for Mod since something similar what discussed a while back.


      

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to TKS)
 
 
Post #: 5
 
 RE: Combining Ubound with loop? >> If Ubound = 10... - 6/6/2008 5:44:18 AM   
  TKS


Posts: 187
Score: 0
Joined: 5/16/2008
Status: offline
quote:

ORIGINAL: dm_4ever

Do a search for Mod since something similar what discussed a while back.


      


I'll give it a look, thanks, but in the mean time I'm still trying to figure out if Ubound and loop can be combined.

-TKS

(in reply to dm_4ever)
 
 
Post #: 6
 
 RE: Combining Ubound with loop? >> If Ubound = 10... - 6/7/2008 1:33:58 AM   
  TKS


Posts: 187
Score: 0
Joined: 5/16/2008
Status: offline
quote:

ORIGINAL: dm_4ever

Do a search for Mod since something similar what discussed a while back.


      


Hey dm_4ever,

I did a bit of a search, but its not sinking in. Could you help me out a bit?

-TKS

(in reply to dm_4ever)
 
 
Post #: 7
 
 RE: Combining Ubound with loop? >> If Ubound = 10... - 6/7/2008 1:48:57 AM   
  TNO


Posts: 1284
Score: 12
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
Try to think the problem through using pseudocode if you have to. If you get used to thinking in the language you work in, you could solve problems much easier. Don't worry about IF something can be done, think about the steps for doing it or the result you want. All programming languages are Turing Complete and can solve pretty much any problem there is (assuming enough time & space is available).

Without knowing too much about your program, I still honestly think an XML file would be alot easier for you to mess with than flat file progression. (the code will be alot smaller and faster too)

< Message edited by TNO -- 6/7/2008 1:51:50 AM >


_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to TKS)
 
 
Post #: 8
 
 RE: Combining Ubound with loop? >> If Ubound = 10... - 6/8/2008 10:37:38 AM   
  TKS


Posts: 187
Score: 0
Joined: 5/16/2008
Status: offline
quote:

ORIGINAL: TNO

Try to think the problem through using pseudocode if you have to. If you get used to thinking in the language you work in, you could solve problems much easier. Don't worry about IF something can be done, think about the steps for doing it or the result you want. All programming languages are Turing Complete and can solve pretty much any problem there is (assuming enough time & space is available).

Without knowing too much about your program, I still honestly think an XML file would be alot easier for you to mess with than flat file progression. (the code will be alot smaller and faster too)


Hey TNO,

Yes, it really is a matter of time & space, but I'll figure it out eventually.

As for you not really knowing my program, I'm not happy with my current code format, so I'm just going through a bit of code refining. I'll send you a copy soon.

(in reply to TNO)
 
 
Post #: 9
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Combining Ubound with loop? >> If Ubound = 10, then do loop? Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts