Results 1 to 7 of 7

Thread: Thinking foward... Execute code once in loop?

  1. #1

    Thread Starter
    Fanatic Member Ruku's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    655

    Thinking foward... Execute code once in loop?

    I found the Static declaration very useful since you can declare a variable once and let it run threw a loop or sub

    ex:

    VB Code:
    1. Form_MouseClick
    2.    Static Click as Integer = 1
    3. End Sub

    which is pretty usefull

    anyways, I was wondering if something could do like:

    VB Code:
    1. Do
    2. a += 1
    3. b += 2 + a
    4. (Some kind of structure header here)
    5. c=b
    6. (Footer structure here)
    7. Loop

    Anyways, to get the result of the c variable only once, meh, I was just curious if some new structure could have 'been created...

    Well, .net, let's think foward!

    (btw don't answer me like use flags and do if statements... There are probably billions of ways to do this, I was just wondering if some new stuff was boiling to be used )


    Using VB.NET 2005/.NET 2.0, NetBeans IDE 5, Fujitsu Cobol85,
    Website: http://DreamForgery.com

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Thinking foward... Execute code once in loop?

    You post makes no sense at all.
    I don't live here any more.

  3. #3
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: Thinking foward... Execute code once in loop?

    Quote Originally Posted by wossname
    You post makes no sense at all.
    that's rude.

  4. #4
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Thinking foward... Execute code once in loop?

    Quote Originally Posted by mar_zim
    that's rude.
    Just a concise observation. No rudeness intended.

    I humbly apologise for any anguish, distress or trauma that my earlier comments may have illicited in those of a delicate sensibility.

    I don't live here any more.

  5. #5
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718

    Re: Thinking foward... Execute code once in loop?

    Can you explain this a little better what you're asking/doing? I also didn't quite understand it.
    I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)

  6. #6

    Thread Starter
    Fanatic Member Ruku's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    655

    Red face Re: Thinking foward... Execute code once in loop?

    uh, ok, sorry for not being crystal clear...

    After using the variable declaration method with Static, that can declare a variable used through let's say a form, the variable is only declared once and it becomes available through the whole form. (lookup "Static" for more info)

    Anyways,

    I was wondering,

    Is there a new way to execute a bunch of code, only once even if it's in a loop?

    my previous code:
    VB Code:
    1. Do
    2. a += 1
    3. b += 2 + a
    4. (The Function)
    5.    c = b
    6. (Footer of function)
    7. Loop Until a = 50

    Meaning the c variable will be grabbed ONCE in the loop, regardless of the values changing in the 2nd, 3rd, etc loop.

    I think hope it's all clear now...

    I know I could use a flag method with an IF to do that, but I'm just exploring new functions...

    Using VB.NET 2005/.NET 2.0, NetBeans IDE 5, Fujitsu Cobol85,
    Website: http://DreamForgery.com

  7. #7
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Re: Thinking foward... Execute code once in loop?

    Then Nope, it would have to be before or after the loop to only execute once.
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width