VS 2010 Using Variable In Different Classes?
Oct 21, 2010
Public Class Form1 Dim CharList As ArrayList Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click CharList.Add(TextBox1.Text.ToUpper)End Sub Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
[Code]...
View 2 Replies
ADVERTISEMENT
Jul 13, 2011
I have put together the following code to illustrate the problems I've been struggling with:
Public Class OuterClass
Private _OuterProp1 As Boolean = False
Public Property OuterProp1 As Boolean
[code]....
I need to be able to refer to outer class properties and variables in an inner class, and I need to have a variable in one inner class set in a different class. I've tried Public, Private, Protected, Friend and all kinds of combinations of them, and I can't figure it out.
View 4 Replies
Jun 13, 2012
How can I structure my classes so that the user interfaces though a single class while the supporting classes are hidden from their view? I think its best understood in an example:
Public Class MyInterface
Public Economic as EconomicClass
Public Sub New()
MyBase.New()
[code].....
So you might ask why am I even separating them? It's strictly for others who will be working with this interface. I need to funnel them though a logical structure:
interface.Economic.MyMethod
interface.Currency.MyMethod
etc
This way everything is already handled for them in the background and they only need to run the method they need. I don't know if I can have it both ways in VB.NET.
View 23 Replies
Oct 24, 2009
Here is some example code of what I mean:
vb
Public Class Form1
Private Sub Button1_Click(ByVal sender as Object, e as systemEventArgs) Handles Button1.Click
[Code]....
View 5 Replies
May 27, 2010
Is it possible to make Color variable parameters in custom classes Optional?Everytime I try, it gives me a "Constant expression required" error.[code]
View 2 Replies
Jan 1, 2011
I've gone brain dead and can't remember how (where) to declare a variable to be shared by 2 forms (classes) in the same project.
View 2 Replies
Mar 18, 2012
Can i write 2 classes for one Script Task editor in SSIS(2008). I tried to access the global variable like below. I created 2 classes and it doesn't show any compile error, but i couldn't access the global variable in class2 which was assigned as 2 in class, ScriptMain.
[Code]...
View 1 Replies
Jan 10, 2011
Say that i have the following code that parse about 20k records from the DB.
Code #1
vb.net While reader.Read()
list.Add(If(Integer.TryParse(reader(0).ToString, 0), Integer.Parse(reader(0).ToString), 0))
End While
And then another code which does the very same thing but it seems to be a little cleaner.
Code #2
vb.net While reader.Read()
Dim storeowner As Integer = 0
Integer.TryParse(reader(0).ToString, storeowner)
list.Add(storeowner)
End While
This is what i am confused about; does the compiler creates a new variable automatically when i use the if statement without strictly declared variable? What approach is better in sense of performance?
View 2 Replies
Jun 2, 2011
Say I have something like this
Dim Level1 as Integer = 83
Dim Goal as String
Goal = InputBox(" What level is your goal?")
[code].....
View 7 Replies
Dec 11, 2011
For the time being I have been using a Structure to store "people" (their name, gender, age, etc...), because I really love to refer to something like Mike.name or Caroline.age, so I could simply put Caroline.age += 1 anywhere in the code and here you go, Caroline is one year older. No more simpler.But because of how inflexible (compared to Classes) Structures appear to be, when I needed to iterate through all the instances I was forced to use a list or dictionary so I could use a FOR EACH ... NEXT block. That was resolved by you people in the previous post, but I'm having the problem that I couldn't use the elements of the list to change the original instance of the Structure proper... I mean, if I code something like this...
For Each thisperson As Person In peoplelist
If thisperson.name = person_selected Then
'person_selected is the SelectedItem.ToString of a listbox[code]....
Well, I thought that thisperson.teamleader and Mike.teamleader were going to be equivalent (when the IF statement was true, that is) but that doesn't appear to be the case. So right now I'm really hating Structures...But when I look into Classes... well, they have more flexibility, yes. You could construct a FOR EACH block without any other trick like the "on-top" list, and that it's very useful indeed, but (a big "but" IMHO) I lose that NICE feature that makes possible to write the name of one of them instances like Mike.age or Caroline. kills
I mean, if I wanted to add a year to Mike, well... there is no "Mike" in the first place. A "Mike" string could be a property for the class, but I cannot (or know) magically refer to him with the ease of a Structure, so when I want something so simple as Mike.age +=1 ...well, with a Class I'm simply clueless to how locate him and change ANOTHER property of him.I suppose I am doing something very wrong, because I cannot believe VBasic could force on you those two extreme philosophies...:
Classes = +flexibility -usability ???
Structures = -flexibility +usability ???
What I want to do is SO simple that I cannot believe I need to choose between the two.
View 25 Replies
Jun 28, 2011
I need some help with how to organize classes in VB.NET. I have a class called parent with methods for adding, deleting etc. But I also need a method that returns a list of all the parents, a list with parent objects. Where do I put this method? Do I put it in the parent class or do I need to make another class called parents?
View 1 Replies
Oct 16, 2011
I've seen people discourage other from using nested classes, because the make things more complicated and are evil and whatnot.But I want to know what possible justification there would be for using a nested class and if there are any possible benefits for using them(or structures for that matter).
View 10 Replies
Jan 23, 2012
I have two classes, one nested in the other. [code]Neither "Name" or "ID" are unique between operations and records.I wish to construct a dictionary using LINQ = Dictionary(Of String, Of List(Of Integer), whereby the keys are uniqe examples of Names in my collection and the values are the collective set of distinct IDs that are associated with those names.
View 2 Replies
Nov 16, 2011
For a class project (online course, no instructor handy to get a quick reply from -_-) we are to write a short program using classes and OOP to roll a pair of 6-sided dice 1000 times and count the number of times the total of the two dice is 7. Easy enough, and I've read over a few examples that people have written, but they don't seem to use OOP. I'm not asking you guys to do my homework for me, but I am terribly lost when it comes to using OOP. So far I understand that I should be using a Random() class object to determine the roll itself, and then maybe load each roll into an array and use a loop to check if each element is 7 or not, and then increment a counter? How do I set the range of Random() so my dice rolls are representative of a 6 sided die? It's all a bit overwhelming and I'm not sure what I should do next.
[Code]...
View 28 Replies
Feb 24, 2011
What are the best ways you guys recommend to search the MSDN Code Library. I know there have been several instances in searching for ways to do something, doing a long workaround, and finding out later that there was a built in class that handled the problem that I was working on much simpler.
So what are some of the ways you guys use to find tools, classes, etc. when coding. Or are you just that awesome already.This is kindve just a general tips and tricks question. Sorry if Im in the wrong forum mods.
View 2 Replies
Oct 26, 2011
Is it possible to have multiple classes in a namespace and be able to reference the functions within the clases if the Major class is instaniatated from another class?? for instacnce:
Namespace Database
Public Class Data
Public Class Prepare
[code]....
View 1 Replies
Mar 30, 2011
I have a MDI application and a very complicated class there which populates its properties from a dataset derived from an external database. Each form, including child forms have to be able to access that class and use its properties thorughout the whole session.I don't know where to 'preserve' these property values within the application. I kmow many books etc. suggest not to use public variables but I really can't find a way to solve this other than to use a public variable (which is a list(of my custom class) in this case.
I have a separate class called PublicItems.vb and declared there my public variable as
Public Shared secuniverse As List(Of myCustomClass)Is there something wrong with the syntax because if I try to use the variable secuniverse in my main application class, I get the following exception:'sectoruniverse' is not declared. It may be inaccessible due to its protection level.
View 7 Replies
Dec 5, 2010
I've been trying to do this for a while now.What I intend to do is that when I load a webpage in a class, i raise event to my form that the data is recieved.
[Code]...
View 8 Replies
Jul 26, 2010
Is it possible to have visual studio 2010 automatically add namespaces to classes within folders just like c#?
View 1 Replies
Mar 20, 2012
I was just wondering how you can make classes import into your main Form.vb
Let's say I make a class with the following.
Public Class OtherStuff
Public Sub HideMe()
Form1.Hide()
[Code]....
How could I make the Form1.vb include the things that are in OtherStuff.vb.
All of the solutions that I have tried come up with the same error. Reference to a non-shared member requires an object reference.
View 2 Replies
Jul 10, 2009
I m trying to raise Click event of Textbox explictly but I m getting "Derived classes cannot raise base classes" error.[code]....
View 1 Replies
Mar 29, 2012
I am having this strange thing happen where I have a Module that contains multiple classes in my project. In the Solution Explorer, the module shows up as a Windows Form and if I double click on it to open it, it tries to open the Form Designer. What could be causing VS to think that it is a Windows Form instead of a module?
[Code]...
View 3 Replies
May 18, 2012
If a string variable contains the name of an integer variable how do I then use the contents of the integer variable.i.e.I have a string variable called 'Rowname' which will contain the name of an integer variable.The integer variables will have been previously defined with values such as RowA = 0, RowB = 5, RowC = 10..I now want to add together the contents of the variable defined in 'RowName' with a the contents of an integer variable ColumnNumber.
View 7 Replies
Sep 24, 2010
so far i got
code
For Each item As Reflection.FieldInfo In GetType(NameSpace.ClassWithNestedClasses).GetFields
rtfAppend(item.Name & ":" & Tab & item.GetValue(Me))
Next
For Each item As Reflection.PropertyInfo In GetType(NameSpace.ClassWithNestedClasses).GetProperties()
[code]...
which gets me the simple string vars and properties of my top class, but how can i apply this to loop through all sub classes and get there vars and props?
View 1 Replies
Oct 13, 2011
Searching the internet finds no less than 700 different ways and opinions to accomplish what I'm trying to do, and I would just like to know the simplest, most bullet-proof way possible.
[Code]...
I simply want to extract the string "bar," which is inside <hostName></hostName>I can do this easily enough with simple string functions, but I'd like to do it with one of the .NET XML classes/methods.
View 2 Replies
Jan 17, 2012
i want to create a program that pressing a button will increment an integer variable and a textbox will show the result. Te code i wrote is below:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
dim i as integer
i = i+1
textbox1.text = i
End Sub
now, the same code works for the vb6 form but on vb 2010 the textbox just show 1 and does not increment any further.
View 3 Replies
Mar 25, 2010
I am getting the error:"Range variable 'sender' hides a variable in an enclosing block or a range variable previously defined in the query expression."for this
Imports System.Data.SqlClient
Imports System.Linq
Public Class Form1
[code]....
I can select any other item from the table without the error. "sender" has the same properties as "receiver" in the SQL table.
View 2 Replies
May 29, 2011
So I have an arraylist with some strings in it in one private sub. But I would like to use this same arraylist in a different private sub also. How could I accomplish this?
I tried changing the subs to public but still got the "is not declared" error. And I tried switching the arraylist's dim with public only to get another error.
View 7 Replies
Apr 16, 2012
I'm a newbie writing my first app. I need help with the following: I need to retrieve the logged in user which = GID, I then need to append it to a URL which will start our Help Desk chat client. I can retrieve the GID easy enough but can't figure out how to append it and pass it with the URL. I found a post which instructed to declare the url as a string also and concatenate it. The UserName would follow the ":" at the end of the Url.
[Code]...
We use javascript to do this from the HelpDesk site, but I need to adapt it to work from my app.
View 1 Replies
Nov 4, 2011
I'm using VB 2010 Express and have a label named "lblTitle" in my form.The next code doesn't work and I know it , but how can I do something like this?
Dim bla As String
bla = "lblTitle"
bla.Text = "Hello world"
[code].....
View 5 Replies