Resetting Arrays menu

Shout-Out

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Cush's Avatar Elite User
    Reputation
    504
    Join Date
    May 2006
    Posts
    528
    Thanks G/R
    3/19
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Resetting Arrays

    Hey.

    Basically since we just started VB not long ago, our teacher decided putting us into teams and told us to create a two-player Noughts and Crosses, with two programmers and two designers.

    Although we have been given a week to do it, me and my friend are the best in the class currently and finished it today, but I have a feeling it would be possible for us to get rid of some of the mess in the code.

    Originally we had 9 different variables for which player had pressed a button (Storing an O or X) and 9 boolean variables for deciding if a button had been pressed already or not, but after reading a few TicTacToe examples I realised using an array for each would be tidier.

    My problem is that when 'New Game' is pressed, I need 29 lines of code to reset everything, when 18 of those could be condensed into 2 if I was able to reset all of the values in an array (I tried 'Erase', but it caused errors when trying to store variables afterwards) Is there any way to do that?

    *EDIT*

    Nevermind, just realised you Erase it, then ReDim.
    Last edited by Cush; 02-05-2009 at 01:55 PM.

    Resetting Arrays
  2. #2
    Apoc's Avatar Angry Penguin
    Reputation
    1388
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/13
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Cush View Post
    Hey.

    Basically since we just started VB not long ago, our teacher decided putting us into teams and told us to create a two-player Noughts and Crosses, with two programmers and two designers.

    Although we have been given a week to do it, me and my friend are the best in the class currently and finished it today, but I have a feeling it would be possible for us to get rid of some of the mess in the code.

    Originally we had 9 different variables for which player had pressed a button (Storing an O or X) and 9 boolean variables for deciding if a button had been pressed already or not, but after reading a few TicTacToe examples I realised using an array for each would be tidier.

    My problem is that when 'New Game' is pressed, I need 29 lines of code to reset everything, when 18 of those could be condensed into 2 if I was able to reset all of the values in an array (I tried 'Erase', but it caused errors when trying to store variables afterwards) Is there any way to do that?

    *EDIT*

    Nevermind, just realised you Erase it, then ReDim.
    Or you could simply create a New array.
    Code:
    Private Shared Sub foo()
        Dim myArray As Boolean() = New Boolean(8) {}
        
        myArray = New Boolean(8) {}
    End Sub
    Just make sure you call GC.Collect() for extra points

    GC.Collect forces the Garbage collector to run and make sure it frees up the memory waiting to be released.
    Last edited by Apoc; 02-05-2009 at 05:24 PM.

  3. #3
    Cush's Avatar Elite User
    Reputation
    504
    Join Date
    May 2006
    Posts
    528
    Thanks G/R
    3/19
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I dont get your code for creating an array xD, I used;
    Code:
    Dim strContent(3, 3) As String
    Dim btnPressed(3, 3) As Boolean
    Then when it came to the button to reset all of the variables;
    Code:
    Erase StrContent
    Erase btnPressed
    ReDim StrContent
    ReDim btnPressed
    Also what exactly does the garbage collector do? You said it frees up the memory, but I would need to be able to explain it a bit more than that when asked :P Why does the memory it frees need freeing?

    Thanks.

  4. #4
    Apoc's Avatar Angry Penguin
    Reputation
    1388
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/13
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Basically, the GC is what .NET and the CLR uses in the background to clean up used resources. (Deletes internal pointers, removes variables in memory that are out of scope, etc.)

    Whenever the GC runs, it does a sweep for generation 1/2/3 types that should be cleaned. (Generation 3 is hardly ever cleaned unless the application is very close to it's memory limit) Just google for what the .NET GC is, and it'll have a better explanation. GC.Collect() forces the GC to run right now, instead of when it's next scheduled to run.

    And yes, my VB.NET code is probably wrong. I don't code in VB.NET due to silly things such as Erase and ReDim. It's bad practice to do things that way (real programmers will agree, and doing it that way is incredibly confusing for others reading your code as they may not know what btnPressed and StrContent are [type wise])

    In C# the code would be this:

    Code:
                bool[][] myArray = new bool[3][];
    
                myArray = new bool[3][];
                GC.Collect();
    Should be easier to understand.

  5. #5
    suicidity's Avatar Contributor
    Reputation
    207
    Join Date
    Oct 2006
    Posts
    1,439
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I agree gree, some of the "Functions" in VB.Net I do not even use and I stay away from with a 100ft pole.


  6. #6
    Cush's Avatar Elite User
    Reputation
    504
    Join Date
    May 2006
    Posts
    528
    Thanks G/R
    3/19
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, I have always had the mentality that code should be as compact as possible, using a function to do something rather than doing it the long way around.

  7. #7
    ReidE96's Avatar Archer Authenticator enabled
    Reputation
    470
    Join Date
    Dec 2006
    Posts
    1,625
    Thanks G/R
    1/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cush, I belong to the same school. Make it work, then make it shorter!

  8. #8
    Cephalopod's Avatar Member
    Reputation
    5
    Join Date
    Sep 2008
    Posts
    85
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I disagree with such an idea :P

    For example, last night I was coding some of my keyboard hook/key broadcasting and I realised I could compress 4 functions into one, the one would be about the size of one and a half functions HOWEVER it would end up taking about 5-6 times longer to process the function. Leaving the 4 functions seperately was a wiser option.

    I code for:
    1) Function.
    2) Optimisation.
    3) Readability.

    In that order.

  9. #9
    Apoc's Avatar Angry Penguin
    Reputation
    1388
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/13
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Midol, I agree with you entirely. However, I code for optimization over all else if possible. Though I'll never throw away readability for anything.

    Cush, it all depends on your object model. If you have something you use a few times throughout your code, it's a good idea to split it off into it's own method. If you only use it once (maybe twice, depending), you're better off just keeping it in the same method.

    Just remember, every time you call a method, you're adding another CPU cycle. They do add up after a while. (Though, in your case, it's probably not even noticeable.) When you have large scale applications, you want to make sure you're not using any unnecessary jumps, or calls in code, as it can utterly kill an applications performance.

    For example, I was debugging an application I wrote a while back, and couldn't figure out why it was so sluggish. It turns out that I was using a small function to do a regex search through some text, and a small bit of comparison. I moved that code back into the functions that would normally have called it, and all was well.

    Also, you're working in VB, so readability is out the window by default.

  10. #10
    Cush's Avatar Elite User
    Reputation
    504
    Join Date
    May 2006
    Posts
    528
    Thanks G/R
    3/19
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well i'd love to move onto something more...Advanced? But our course is VB =P

    I started C++ a while back, but I got to a certain point while following tutorials and I really couldnt understand it, and im not very patient so I gave up at it while I was still on the basics of the basics (Probably less than I am now in equivalet to VB) Im hoping learning a language in a class with proper help will give me a better understanding of programming in general and aid me in learning C++ further down the line (I would like to write server mods for TF2 and other games running the source engine)

  11. #11
    Cephalopod's Avatar Member
    Reputation
    5
    Join Date
    Sep 2008
    Posts
    85
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Cush View Post
    Well i'd love to move onto something more...Advanced? But our course is VB =P

    I started C++ a while back, but I got to a certain point while following tutorials and I really couldnt understand it, and im not very patient so I gave up at it while I was still on the basics of the basics (Probably less than I am now in equivalet to VB) Im hoping learning a language in a class with proper help will give me a better understanding of programming in general and aid me in learning C++ further down the line (I would like to write server mods for TF2 and other games running the source engine)
    If you know the basics of VB.net then just move to C#.net - the syntax is similar enough that what you learn in C# can easily be ported over to VB.net. I feel your pain though, my HS was still on VB6 in 2004/5... If I knew it'd be so useless, I wouldn't have taken the subject.

    I find online tutorials useless when learning the base of the language. I've got a few books, and use tutorials for very specific things (like the keyboard hook) but progress would be insanely slow if I relied only on tutorials.

    Honestly, books + experts exchange + a few tutorials = win. I can not stress how awesome experts exchange is. Even if they don't fix your problem you still learn a heap. Recently I had trouble with the garbage collector destroying a delegate and experts exchange has been a god send. I don't know if the solution given will work, but just reading his post and viewing the changes helped my understand the garbage collection process a bit better.

    Apoc, I sort of agree with you now that I read your post. In reality though, if your project is functional and optimised then chances are it is readable as well.

  12. #12
    ReidE96's Avatar Archer Authenticator enabled
    Reputation
    470
    Join Date
    Dec 2006
    Posts
    1,625
    Thanks G/R
    1/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Then get into c# ASAP, Cush. I had 3 years of VB6 (bleugh) and now I can't code in anything that's not VB. Makes me sad

  13. #13
    Cush's Avatar Elite User
    Reputation
    504
    Join Date
    May 2006
    Posts
    528
    Thanks G/R
    3/19
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem is I need to be able to do C++ for creating mods for source games (Server side ones such as the Warcraft mod for CSS that allows levels and skills to be used)

    I have been planning to get some books for coding, but theres so many and everyone has different opinions on whats good and whats not, and I dont know language to go for >_<

    I feel like im slowing down with VB.net, too, its similar to what happened when I was trying to learn C++....I grasp the basics but anything further than that, I really dont understand whats going on (Which is why a book or someone to teach it is helpful rather than tutorials that just say 'ok, write this in there and run it' without actually explaining what things do.
    Last edited by Cush; 02-10-2009 at 08:11 PM.

  14. #14
    JoeBiden's Avatar Contributor
    Reputation
    153
    Join Date
    Aug 2007
    Posts
    498
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Plus the books dont even try to teach you these days (most of them)

    100 pages intruduction 200 pages "content list" and another 100 copyright, then we get to read a few pages "about the autor(S)" ...

    then when you get to programming it wants you to copy/paste his code into notepad and rename it to .cs....

  15. #15
    Apoc's Avatar Angry Penguin
    Reputation
    1388
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/13
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're going for C#, I highly suggest this book. (C# 2008 and the .NET 3.5 Platform (4th edition))

    For C++, just go to Learn C++ -. It's the BEST resource I've found for beginner -> advanced C++.

    @Midol, while I don't personally feel that people should need to pay for coding support. (Experts Exchange is good. Just not worth paying for. [PS: I was a C# guru for a while on EE]) You're better off going to public forums such as Bytes for help. It's free, and you'll receive just as much support as you would at EE, but for absolutely free.

Page 1 of 2 12 LastLast

Similar Threads

  1. Farm and reset Mara forever
    By xkillerb in forum World of Warcraft Exploits
    Replies: 1
    Last Post: 08-10-2007, 07:47 PM
  2. Reseting Daily Quests
    By Wesk. in forum World of Warcraft Exploits
    Replies: 13
    Last Post: 06-07-2007, 08:12 AM
  3. reset instances in 2.0
    By sportstud10124 in forum World of Warcraft Exploits
    Replies: 16
    Last Post: 12-16-2006, 08:24 AM
  4. Reset an Instance While Still Inside
    By Matt in forum World of Warcraft Exploits
    Replies: 15
    Last Post: 07-27-2006, 09:04 AM
  5. Instance Resetting
    By Matt in forum World of Warcraft Guides
    Replies: 3
    Last Post: 07-21-2006, 09:18 AM
All times are GMT -5. The time now is 05:06 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search