Like Tree2Likes
  • 1 Post By tabstop
  • 1 Post By laserlight

Problems with Visual Studio Express 2012

This is a discussion on Problems with Visual Studio Express 2012 within the C# Programming forums, part of the General Programming Boards category; I was writing a C# Forms document in Express 2012 and came up with an unusual bug. I have some ...

  1. #1
    Registered User
    Join Date
    Feb 2014
    Posts
    2

    Problems with Visual Studio Express 2012

    I was writing a C# Forms document in Express 2012 and came up with an unusual bug. I have some random data I'm displaying in dataform grid that I'm retrieving from an array of classes. If I run the program, the data grid (and the actual array of classes) are all copies of whats stored in array[0]. If I use the debugger and step through the entire process, the variables all contain different data and the datagrid displays this data correctly. Any ideas why that would be the case? Here is some code snippets if that helps at all:

    I added 2 classes one called Player, and one called Game. Game contains the following code:
    Code:
    public class Game
        {
            public Player[] player = new Player[16];
    
    
            public Game()
            {
                int i;
    
    
                for (i = 0; i <player.Length; i++)
                {
                    player[i] = new Player();
                }
               
           }
        }
    Now my in the Form Document i added this:
    Code:
     public partial class Form1 : Form
        {
            public Game myGame = new Game();
            public Form1()
            {
                InitializeComponent();
            }
    The final thing is the Player class has a function called Initialize player.. it is just a bunch of code using Random to make up some various stats, which i run from the Form1_Load
    Code:
    for (i = 0; i < myGame.player.Length; i++)
                {
                    myGame.player[i].InitializePlayer();
                }
    AGain if i just run the program myGame.player[0] gets randomized and then 1=15 are just copeis of it. But if i step through it, they are all unique.?!? is this some crazy bug in VSE 2012?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Guess based on no evidence whatever: did you do something like seed the random number generator off the system clock, then mistakenly reseed every time through the loop instead of just once total?
    itsme86 likes this.

  3. #3
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Quote Originally Posted by tabstop View Post
    Guess based on no evidence whatever: did you do something like seed the random number generator off the system clock, then mistakenly reseed every time through the loop instead of just once total?
    I'd bet good money that's the problem. If you're using more than one Random object, you shouldn't be - you should make a static member Random object and use that to initialize everything. I bet each copy of InitializePlayer creates its own Random object, and with less than a millisecond to execute all iterations of the loop, it creates the same sequence over and over.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  4. #4
    Registered User
    Join Date
    Feb 2014
    Posts
    2
    Thanks for the insight. That was exactly the problem. I didn't think about the fact that Random Class was most likely initializing each object based on the time. Using one Static Random object for all instances worked out perfectly. (The fact that stepping through was causing the time to lag enough to make each one different time seed makes perfect sense).

  5. #5
    Registered User
    Join Date
    Mar 2014
    Posts
    6

    MVC?

    On visual studio there is a language calld Mvc, does anyone know how it is difrent from C#?

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,445
    Slimtiz: please start a new thread to discuss a new topic. Since what you post is related to Visual Studio but not to C# (or C or C++), the Tech Board is likely to be a good place to post it.

    Anyway, based on a quick search of the Web, I think this "Mvc" that you see in Visual Studio refers to the Model, View, Controller (MVC) pattern rather than to a programming language.
    Slimtiz likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Mar 2014
    Posts
    6
    Thanks you've been helpful.

  8. #8
    Registered User
    Join Date
    Mar 2014
    Posts
    4
    Model–view–controller (MVC) is a software pattern for implementing user interfaces
    The model is the code. It is an object that represents the data. E.g. classes, database table etc.
    A view provides/is like the gui. A kind of visual presentation for the model.
    A controller accepts the input from the user and commands the models to be executed therefore views are also changed. It provides responses to users from the application.

    Repost from quick search-MVC is a way to give order to your code layout. You keep logic in one area and presentation in another. This allow you to unit test more efficiently, find your code faster to upgrade it or fix errors.

    ASP webforms is more free form so how ever you structure your architecture is up to you. You could go spaghetti in the design making it hard to maintain and upgrade.

    Since MVC separates logic(rules) from presentation (views or ui) if your ui changes but the rules didn't you only have to go to the views to edit the changes. In webform you may have to go to several different areas of the project to make ui changes.Using MVC also makes it easy for someone else to maintain or upgrade your code. The structure is easy to pick up. With webform the person would have you learn your architecture style first and then start editing. That takes way more time than using a structure and well documented paradigm

    http://www.dotnet-tricks.com/Tutoria...p.Net-MVC.html - outlines most differences
    Last edited by Dut_Student; 03-06-2014 at 05:37 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 02-27-2013, 07:46 PM
  2. Visual Studio 2012, 3 months later...
    By Mario F. in forum General Discussions
    Replies: 18
    Last Post: 12-04-2012, 03:21 AM
  3. EXCEL & C++: Integration in Visual Studio 2012
    By Solomon Vimal in forum C++ Programming
    Replies: 4
    Last Post: 11-21-2012, 06:31 AM
  4. Visual Studio Express 2008 problems.
    By Normac in forum C++ Programming
    Replies: 2
    Last Post: 08-08-2007, 10:41 AM
  5. Has anyone tried visual studio express yet?
    By Brian in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-17-2006, 08:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21