Declaring Public Variables New Hashtable
Dec 8, 2009
recently started converting our project from 1.1 to 2.0
It was fine with the following:
Public ghtAllAppMsgs As New Hashtable(300)
Now it is complaining to change to the following is this the right way:
Public ghtAllAppMsgs As New System.Collections.Hashtable(300)
This is under global.vb class file: here are the imports i already had in this file:
Imports Microsoft.Web.UI.WebControls
Imports Microsoft.Web.UI.WebControls.MultiPage
Imports System.Web
[Code]......
View 1 Replies
ADVERTISEMENT
Sep 23, 2011
I've created a 30 point wizard. Every step gathers between 1 and 3 variables. I've created a module and publicly declared the variables there. At the end of the wizard, one master form opens, gets all the variables, and displays them on one form. At this point calculations are run too which populates more variables. This works fine for one instance of the process.
the user may want to be running two instances of the wizard at once. Obviously, if the previous wizard is part complete and they start a new one, the variables are going to get crossed or replaced by the new wizard.Is there a way for the variables to be declared publicly but used in multiple instances?
View 8 Replies
Jan 7, 2010
Does the memory used in declaring variables are reclaimed by the OS when these variables go out of scope?Does the memory used be released by setting thier value to nothing? if not, then how can I force the garbage collector to run or excecute at a certain/desired time..How about in Windows Forms..How can we make sure that the memory used in initializing and showing forms be released if those forms were closed?
View 13 Replies
Jul 26, 2010
I actually came from VB6 and starting to learn VB.NET. I saw this line of code which I cannot understand how it works nor how it goes.
Private MAX_VALUE As Integer = (1 << 14)
View 2 Replies
Oct 6, 2011
I have just been experimenting with nesting classes within a User class I had already created.
E.g.
Friend Class User
[Number of Properties...]
Friend Class Address
[code]....
I get the same error message!!! "Declaration expected". Also I notice the variable's name is not coming up in intellisense. I have not come across this before as declaring an using variables and objects has been straight forward up until now.
View 2 Replies
Sep 29, 2011
The user clicks a button, a new form is generated where the user enters his/her password? How can I keep an in-memory copy of the username?
For instance in web forms, I can just use Session ("User"). How can I replicate this with winforms?
View 3 Replies
Oct 25, 2010
OK, I'm working on a project and i need to access the property of a usercontrol which I have set.Here is the code in the UserControl
Private Color As Color = ColorTranslator.FromHtml("#000000")
Public Property InkColor() As Color
Get
[code].....
View 4 Replies
Mar 5, 2010
What's the proper way to declare variables in a class? I've been doing something like:
'in a class
public shared teststring As String = "first"
'on a code behind
[Code]....
with shared variables loading a second window or reloading the page (without clicking the button) renders the hello world string. so how do I declare variables in a class but make it per instance?
View 5 Replies
Oct 15, 2009
When I am writing a sub or function that does some calculations etc. I often need a loop or a integer variable to count.
An example:
''' <summary>
''' Compare elements with the new data and perform all necessary actions.
''' </summary>
[Code]....
As you can see, variables like timespan, nullCount and seconds are declared within this sub.
My question is, is it better to declare these in the class? I can imagine that would boost performance.
View 8 Replies
Jun 25, 2011
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim chatters As List(Of Chatter) = New List(Of Chatter) chatters.Add(New Chatter(New Guid("CD863C27-2CEE-45fd-A2E0-A69E62B816B9"), "Me")) chatters.Add(New Chatter(Guid.NewGuid, "Juan")) chatters.Add(New Chatter(Guid.NewGuid, "Joe")) Application.Add("Chatters", chatters)
[code]....
I am unable to understand last 3 lines that are bold and underlined. Please what is hppening here. Chatter and Chat are two classes defined in App_Code folder. Is there any sight that contains all possible ways to declare and initilaze variables and data structure:
Dim chatters As List(Of Chatter) = New List(Of Chatter)
View 1 Replies
Jul 19, 2009
i have have a few questions about the syntax of the lan.:
1) What is the 'Get' statement and when do you use it?
2) Whats the difference between public, private, protected etc... when declaring functions and subs.
3) When would you use the overrides property?
View 4 Replies
May 11, 2009
I need to write a simpe calc. program to add, mutiply, subtract and divide. I want to have two textboxes that I enter numbers in and when I click a button, +,-,/ or * a third text box will display the result.Rather than declaring my variables inside each instance of a click event I would like to declare them globally so I just need to perfom the calculation on them and display result. However declaring them globally doesn't work for me. I;ve tried the variables inside the btnAdd click event which works, but as I said I'd prefer to declare them onece globally.
Public Class Form1
Dim number1 As Double = CDbl(txtNum1.Text)
Dim number2 As Double = CDbl(txtNum2.Text)[code]...
View 1 Replies
Mar 23, 2012
I am writing a program and i need to declare matrices but there will be a different number to declare everytime the program is run so I was wondering if anyone knew how to declare them inside a for loop
eg.
For i = 1 to NumberOfMatrices
Dim matrix i (5,5) As Double
Next
View 4 Replies
Feb 11, 2009
I am new to the forum and new to the visual studio set up and have been working at a practical at home and have ran into some difficulty. The notes say that I am to declare several module variables below the section entitledI have the rest of the form complete but have been unable to locate where I am to place this code
View 1 Replies
Nov 5, 2010
I am at a loss to figure out why this code results in 2 errors when I try to Parse it inthe SSMS.
@Collection varchar = Books,
@Title varchar = 0,
@Authors varchar = 0,
[Code].....
I think that I re wrote this query ten times todaday and continue to get errors and don't know what my problem is
There are underlines in red under the 0 in the BookLoanStatus and under all of the parameters in the SQL.
View 2 Replies
May 26, 2010
I am new to Visual Studio.NET but very familiar with the old ASP (using DreamWeaver).I am unfamiliar with this system of having seperate files for VB code and HTML, in my Visual Studio project I have a Default.aspx file and a Default.aspx.vb file. Now I want to declare a variable that will be accesible to all my functions on the Default.aspx.vb file. I.e. if a user clicks on one button and it launches a Protected Sub called Button1_Click, I want that button to be able to read or write to that variable and then if a user clicks on another button, I want it to likewise be able to read and write to that variable.So where should these variables be dimmed?
At the top of the aspx.vb file? Before or after the line that says "Partial Class _Default"?Or at the top of the aspx file? (Within <% %> brackets?)
View 3 Replies
Jan 6, 2011
Is it possible for a class of exposing a type for function returns, without allowing users of that class to create variables of that type? A couple usage scenarios:A Fluent interface on a large class; a statement like "foo=bar.WithX(5).WithY(9).WithZ(19);" would be inefficient if it had to create three new instances of the class, but could be much more efficient if the WithX could create one instance, and the other statements could simply use it.A class may wish to support a statement like "foo[19].x = 9;" even when foo itself isn't an array, and does not hold the data in class instances that can be exposed to the public; one way to do that is to have foo[19] return a struct which holds a reference to 'foo' and the value '19', and has a member property 'x' which could call "foo.SetXValue(19, 9);" Such a struct could have a conversion operator to convert itself to the "apparent" type of foo[19].In both of these scenarios, storing the value returned by a method or property into a variable and then using it more than once would cause strange behavior. It would be desirable if the designer of the class exposing such methods or properties could ensure that callers wouldn't be able to use them more than once. Is there any practical way to accomplish that?In formulating a question, it's difficult sometimes to draw the line between complicated usage cases, and simpler usage cases which aren't quite so important. Here's another usage case, and one closer to the one I'd be most interested in (though I'm also interested in Fluent chaining; being able to have something behave like a C++ reference to a value type would be nice, but probably too much work to bother with).I have a type which is somewhat like the Windows registry, in that it is a hierarchical collection of items, each of which may have a string value, an integer value, and/or a nested collection of items. I wish to be able to support the following types of usage:[code]As for the Fluent interface, my thought would be to have the WithXXX properties return a new instance of a derived class which shadows (not overrides!) the WithXXX properties with versions that simply modify the current instance. The return object from WithXXX would be known to be of the derived class, and would thus use the shadowed WithXXX methods, but once it was assigned to a variable, it would be regarded as an instance of the base class, so the next WithXXX would create a new instance.
C++ a stronger concept of value types than C# or vb.net, including the very useful concept of references to value types; it ensures that references to value types cannot be persisted outside the scope of the type in question. Unsafe code in C# can use pointers to value types, but they don't have the protections offered by C++ references.
View 3 Replies
Feb 7, 2012
I'm wondering about the performance differences between imports and inherits in a .net app.I currently program by creating multiple classes that logically define my objects. e.g. a class for customers, users and product.When i want to use these classes in a page i have to import them eg. "Imports Custmomers" and then later in my code i have to create a variable and datatype it before i can use the sub routines and functions from class.I understand from a coding perspective this keeps it all neat and tidy.So my question Would it be not better to combine all my classes into a base class, inherit that base class, rather than import it, when i want to use it and so cut down on the extra declarations and associated code that come from importing a class; and if i did this would it aid performance?
View 1 Replies
Jun 12, 2011
I want to know what implies to declare a function or a sub using public or directly Sub / Function i.e.:
Public Function Whatever()
' Process
End Function
versus.
Function Whatever()
' Process
End Function
View 4 Replies
Aug 5, 2009
How would I go about dynamically declaring a constant? (It's value is dynamic, not the variable name)
View 5 Replies
Jan 17, 2011
I have a variable declared at Public on a form. But when I try to access it in a module I get an error that its not declared.
[code]...
View 15 Replies
Aug 25, 2010
I have a string on my main form called String1. When I open another form, I need access to this value. In the form I open, I have always done something like:Dim NewString as String = Main.String1
This has worked in the past. Well, I ended up renaming my forms (from Form1 to Main) in the property window and it now when I type the above code, it does not list Main as a form. Nothing that I renamed seems to exist now.
View 2 Replies
Mar 10, 2012
This seems basic but here's my problem. I am trying to build my connect string as a public variable that will connect to either an express version of SQL Server or a non-express version. The app.config defines it as being express or not and is modified to the user's choosing when it is deployed using the a firstRun routine.
The problem is that even though I'm modifying the value of the variable SQLexpress when the app is initiated which in turn should modify the value of the variable g_strConnectionString it doesn't. The value of g_strConnectionString will always take on the initial value of SQLexpress. I know I can define 2 separate variables for the connection string but I'd prefer not to have to change all of the references throughout each of the various programs in this system as they all have the same issue.
So in the following load event I've traced it and when it sets globals.SQLexpress = "", I then look at the value of g_strConnectionString and it still contains "SQLEXPRESS". It seems I need to somehow force vb to refresh this variable after it's been changed.
[Code]...
View 5 Replies
Mar 11, 2010
I am a little new to .NET Developing, and have learned a great deal recently, but I'm stuck with something. I come from an ASP Background, I'm trying to subtract 2 variables, but they don't seem to 'see' one another.
[Code]...
View 6 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
Feb 15, 2012
I am using this example I found to learn how to load class files and access variables through them. This is in a file called Class1.vb in the App_Code folder (this is not an app project):
Imports Microsoft.VisualBasic
Public Class my_class
Public Shared Sub my_sub()
[Code]....
How could I access the vartest variable without using a session, since if this is accessed by multiple functions at the same time the variable can be overwritten I assume. Is it possible to go the other way, where a variable is sent to a class file?
View 4 Replies
Feb 15, 2009
I have created a public shared subroutine in a class file in asp.net 2 (vb.net) web site app_folder.The subroutine retrives some values from a sql database via an sql query and assigns the datareader field values to several variables The problem is I can't seem to assign the variables from the subroutine to the variables and textbox controls in the asp.net page I am calling the subroutine from. The textbox text value just appear blank.By the way, if I response.write the variables in the subroutine they appear populated by the sql data reader.
View 9 Replies
Apr 10, 2009
I am currently working on a project of "interpreting" C# into VB. The project involves adding images to a database, retrieving images from the database and presenting them in thumbnails. Right now I have the following Public Class with the Variable that needs to be assigned:
VB:
Imports System.Data
Imports System.Drawing
Imports System.IO
[code]....
View 6 Replies
Apr 29, 2012
When and why do you declare variables in the Public Class Form1 section?
View 1 Replies
Jan 2, 2012
I'm writing a new app and copying/pasting some lines from another one. In the new app, I get error when I use variables defined as public.
[Code]....
View 1 Replies