Visual C# Developer Center > Visual C# Forums > Visual C# Language > C# equiv of a VB module for global values?
Ask a questionAsk a question
 

AnswerC# equiv of a VB module for global values?

  • Friday, October 30, 2009 2:45 PMChristopher Pisz Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I am pretty new to VB and C#, I've ignroed them for years and stayed in my C++ world. Now my new job is throwing .NET at me at 100 mph. So, I am digging through code and find that you can create projects in either language and they can work together, but you cannot write both in the same project. So, I am going to need to translate some VB to C#. Anywho, the question is: What is the preferred method of creating some globally accessable values? Also, access of values from the config files?

Answers

  • Saturday, November 07, 2009 2:46 AMChristopher Pisz Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    It looks like the answer is to use a sealed/static class. Things move over pretty easy from a global module that way.
    There is also app config which can hold alot of settings and such and be parsed using System.Config.ConfigurationManager

All Replies

  • Friday, October 30, 2009 3:06 PMRudedog2ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    You can create multi-project, multi-language solutions in Visual Studio.
    That means you can VB and C# projects within the same solution.
    I see no reason to translate working VB code into C#, unless it is a matter of preference to have it all in one language or another.
    What version of VS are you using?  Express Editions have limitations that can be worked around.

    Globally accessed variables can be created in C# by declaring as static.  Not the Object Oriented approach at all.

    Use the Properties.Resources and Properties.Settings folders in Solution Explorer.




    Mark the best replies as answers. "Fooling computers since 1971."
  • Friday, October 30, 2009 3:29 PMChristopher Pisz Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Using team edition. Well the reason for the translation is that someone wrote a service in VB and I wrote a service in c#, now we need to combine them. There isn't much, just a 15 line onstart, but I have to do all the settings, globals they used, and some encryption of connectrion strings and such.
  • Friday, October 30, 2009 3:34 PMRudedog2ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hmmm.  Duplicate code? 

    Why not simply create a separate assembly that both services reference? 
    Take your pick.  Do it in VB or C#?

    There are dozens of free code translators out there.
    But I find that Reflector from Red Gate does a decent job on single classes.

    I useful tool that every developer should have.

    Rudy   =8^D

    Mark the best replies as answers. "Fooling computers since 1971."
  • Friday, October 30, 2009 3:54 PMChristopher Pisz Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Not really duplicate. They both do different things, but we want them to run under one service. So yea, I am trying to create a solution with the seperate assemblies. I am splitting off all the actual implementations, interfaces, and such and trying to get a proper organization of things. However, there will only be one service. I guess I got to learn a bit of VB. I'll peruse the MSDN language docs for a bit.
  • Saturday, November 07, 2009 2:46 AMChristopher Pisz Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    It looks like the answer is to use a sealed/static class. Things move over pretty easy from a global module that way.
    There is also app config which can hold alot of settings and such and be parsed using System.Config.ConfigurationManager
  • Monday, November 09, 2009 2:14 PMRudedog2ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    You can create multi-project, multi-language solutions in Visual Studio.
    That means you can VB and C# projects within the same solution.
    I see no reason to translate working VB code into C#, unless it is a matter of preference to have it all in one language or another.
    What version of VS are you using?  Express Editions have limitations that can be worked around.

    Globally accessed variables can be created in C# by declaring as static.  Not the Object Oriented approach at all.

    Use the Properties.Resources and Properties.Settings folders in Solution Explorer.




    Mark the best replies as answers. "Fooling computers since 1971."

    That path leads to code that can quickly become unwieldy.

    One small change here or there ripples across multiple methods and classes just ot make it compile again.
    The difficult part is that changes you might need to make do not always cause compiler errors.  Broken code.
    Now you are forced to remember, verify, check every location in your code that might be affected by the original change.



    Mark the best replies as answers. "Fooling computers since 1971."