Results 1 to 15 of 15

Thread: Error: Type "Solution" is not defined???

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Question Error: Type "Solution" is not defined???

    Esteemed Forum Participants and Lurkers:

    The VB.Net Help examples FREQUENTLY omit essential tidbits of information, and are thus useless (to me, the newbie). I cut the "Solution" and "Globals" code straight out of the "VariableExists" examples, but it doesn't compile because "Solutions" is "not defined". I'm guessing I have to Import some namespace?

    Code:
    Imports System
    Imports System.IO
    Module Ini_Process
        Private objSoln As Solution  '<<< ERROR: Type 'Solution' is not defined
        Public g_test As Integer
        Sub test()
            ' Do some file operations here!!!
            If objSoln.Globals.VariableExists("g_test") Then
                MsgBox("Variable EXISTS")
            End If
        End Sub
    End Module
    How do I get "Solutions" defined???

    Thank you for any comments, suggestions, and assistance.
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    It's in there, but it's is hidden. Notice the requirements section. To get it to work, add a reference to envdte, the you can use
    VB Code:
    1. Imports EnvDTE

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045
    Mike -

    I already tried that -

    "Imports EnvDTE" generates an error:

    "Namespace or type 'EnvDTE' for the Imports "EnvDTE' can not be found."

    Where do we go from here?
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  4. #4
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    You missed the first step. You have to add a reference first. From the pull-down menu, click project/Add Reference, then on the .NET tab, double click envdte then click ok. You will see this newly added reference under "References" in solution explorer.

    That's when they mean when they say that namespace EnvDTE is required.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045
    Frustration Level 9.1 and climbing -

    Does anyone have an example (for a NEWBIE!) of setting the value of an existing variable "Public g_test As Integer" by referencing the variable name in a string?
    Dim varname As String

    I want to read a string/value pair from a file, and load the variable. Here is what I have so far - it all compiles - but I obviously don't understand what "Globals" means or what "Property" has to do with what I am trying to accomplish ... I'm not looking at a property, unless a variable is a property of a class???

    Code:
    Imports System
    Imports System.IO
    Imports EnvDTE
    Module Ini_Process
        Public g_test As Integer = 9  ' This variable is 'globally' available???
        Private objSoln As Solution
        Sub test()
            Dim tst As Boolean
            MsgBox(g_test, 0, "Variable: g_test")  ' variable definitely exists!
            tst = objSoln.Globals.VariableExists("g_test")  '<<<ERROR
        End Sub
    End Module
    The error message is:
    An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication1.exe

    Additional information: Object reference not set to an instance of an object.

    Thank you for your comments, suggestions, and assistance.
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  6. #6
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Not sure if this will help you or not. Strange thing is, first time I ran this code, g_test didn't seem to exist. Then after setting it, it did exist. I don't think the first time around it "sees" the g_test variable. But then it seems to create one.

    Haven't ever message with this stuff before, so I don't know what's going on.
    VB Code:
    1. Public g_test As Integer = 9  ' This variable is 'globally' available???
    2.  
    3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    4.         Dim DTE As EnvDTE.DTE
    5.         DTE = System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE")
    6.         'MessageBox.Show(DTE.Solution.Globals.VariableValue("g_test"))
    7.         MessageBox.Show(DTE.Solution.Globals.VariableExists("g_test"))
    8.         DTE.Solution.Globals.VariableValue("g_test") = 42
    9.         MessageBox.Show(DTE.Solution.Globals.VariableValue("g_test"))
    10.     End Sub

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045
    Mike: Thanks for your gracious help -

    I don't think "Public g_test As Integer" creates a GLOBAL variable - it only creates a variable that can be referenced anywhere.


    And that's consistent with your observation - from the help docs -

    "If you attempt to check the value of a variable with the VariableValue property and the variable does not exist, a new variable of that name is created with a null value. "

    So after the 1st time through, you have created a TRUE Global variable. How do we create TRUE GLOBAL variables in the first place?
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  8. #8
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    What are you trying to do anyway? You know this stuff represents your IDE, I don't think you could use in production code.

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045
    Mike -

    I want to read a "text string"/"value" pair from a text file, and initialize a variable that has the name in the text string with the value read from the file.

    This is just an initialization file for some variables. I don't want them necessarily hard coded in my project - if a variable is included in the initialization file, I want to overwrite it with the value in the file.
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  10. #10
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    So, you mean like some sort of config file? Not sure why you're going through all the DTE stuff. If so, there's many ways to do it. Try searching around for some really good ideas.

    FWIW, I've made a class that contains all the config variables I need, then you can just serialize/deserialize (I used xml). Worked for me, but I know this has been discussed and some really smart guy had a cool way to go about it.

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045
    Mike:

    I did something like this (load variables from an initialization file) about 5 years ago in LabWindows CVI, but I have done very little programming since then, and am a Newbie to VB.Net.

    I've been dthinking about it, and once the application is compiled, the variable names don't exist any more - only memory location references. I think I must have just made a giant case statement with all of the variables to init. Unless anyone else has any brilliant ideas, that's the way I'll proceed.

    Thanks for the help -
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  12. #12
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    You may want to think of just using an App.config to store your config stuff - that's what it's made for. Check out the help. But basically it goes like this:

    Add a configuration file to your project - it's one of the choices when you add a new item.

    Set some stuff in it. for example:
    Code:
    <configuration>
    	<appSettings>
          <add key="myDogsName" value="Buoy" /> 
          <add key="maxValuesAllowed" value="42" /> 
       </appSettings>
    </configuration>
    Then in your code, maybe in Form_Load, you get set your variables:
    VB Code:
    1. Public myDogsName As String
    2.     Public maxValuesAllowed As Integer
    3.  
    4.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    5.         myDogsName = System.Configuration.ConfigurationSettings.AppSettings.Get("myDogsName")
    6.         maxValuesAllowed = System.Configuration.ConfigurationSettings.AppSettings.Get("maxValuesAllowed")
    7.  
    8.         MessageBox.Show(myDogsName)
    9.         MessageBox.Show(maxValuesAllowed)
    10.     End Sub

    You can always check to see if there's a value in the file, and use your default if not. The file can ship with your app, so the end user can change.

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045
    Mike -

    I was just trying to reinvent the wheel. The App.config is EXACTLY what I was trying to do. Thanks for pointing me in the right direction. I told you I am a Newbie! Sorry I didn't make my goal plain in the first post - I'll try to do better in the future!

    Thank you for your gracious patience and assistance. I'm learning!
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  14. #14
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    I was just trying to reinvent the wheel
    LOL - I did the exact same thing for my first couple of projects. Thought I was being smart by making all these reusable classes to facilitate reading a config file. Then I find out it's built in. duh.

    Live and Learn

  15. #15

    Thread Starter
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045
    Mike -

    I finally found an ap note on the MS web with an example of a Config file application, and I even got it to work, for what it's worth:

    http://support.microsoft.com/default...EN-US%3B313405

    The config file format is in a klutzy XML format from a user's perspective. I would also still have to do a case statement to load a list of variables. As far as I can tell, the only thing this method does is that it offloads building a sorted list onto the config file. If I write code build a sorted list from a text file, I've got exactly the same capabilities. So, I'm abandoning the config file and rolling my own.
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

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