|
-
Aug 2nd, 2004, 11:41 AM
#1
Thread Starter
Frenzied Member
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
-
Aug 2nd, 2004, 01:48 PM
#2
Frenzied Member
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
-
Aug 2nd, 2004, 02:08 PM
#3
Thread Starter
Frenzied Member
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
-
Aug 2nd, 2004, 02:17 PM
#4
Frenzied Member
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.
-
Aug 2nd, 2004, 03:27 PM
#5
Thread Starter
Frenzied Member
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
-
Aug 2nd, 2004, 03:58 PM
#6
Frenzied Member
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:
Public g_test As Integer = 9 ' This variable is 'globally' available???
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim DTE As EnvDTE.DTE
DTE = System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE")
'MessageBox.Show(DTE.Solution.Globals.VariableValue("g_test"))
MessageBox.Show(DTE.Solution.Globals.VariableExists("g_test"))
DTE.Solution.Globals.VariableValue("g_test") = 42
MessageBox.Show(DTE.Solution.Globals.VariableValue("g_test"))
End Sub
-
Aug 2nd, 2004, 04:13 PM
#7
Thread Starter
Frenzied Member
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
-
Aug 2nd, 2004, 04:19 PM
#8
Frenzied Member
What are you trying to do anyway? You know this stuff represents your IDE, I don't think you could use in production code.
-
Aug 2nd, 2004, 04:39 PM
#9
Thread Starter
Frenzied Member
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
-
Aug 2nd, 2004, 04:46 PM
#10
Frenzied Member
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.
-
Aug 2nd, 2004, 04:52 PM
#11
Thread Starter
Frenzied Member
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
-
Aug 2nd, 2004, 05:13 PM
#12
Frenzied Member
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:
Public myDogsName As String
Public maxValuesAllowed As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myDogsName = System.Configuration.ConfigurationSettings.AppSettings.Get("myDogsName")
maxValuesAllowed = System.Configuration.ConfigurationSettings.AppSettings.Get("maxValuesAllowed")
MessageBox.Show(myDogsName)
MessageBox.Show(maxValuesAllowed)
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.
-
Aug 2nd, 2004, 05:26 PM
#13
Thread Starter
Frenzied Member
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
-
Aug 2nd, 2004, 05:35 PM
#14
Frenzied Member
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
-
Aug 3rd, 2004, 12:02 PM
#15
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|