Calculator - Declaring Global Variables?

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


ADVERTISEMENT

Declaring Global Variables In Vb?

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

Memory Used In Declaring Variables Are Reclaimed By The OS When These Variables Go Out Of Scope?

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

Define Some Global Variables Of A Class - Variables Occupy Memory?

Mar 23, 2012

I define some global variables of a class as follows:

Private Class MyClass
Private var1 as Decimal
Private list1 as List(Of string)[code].....

But I found that after this form is closed, all above variables, var1, list1, list2 still exist in memory. I thought they should be collected by gc since the form is already disposed as I confirmed.

Add: I have monitored half an hour after the form is closed. But these variables are not collected by gc. I have an automatic update procedure on the form which uses above variables.Since the above variables still hold values, the automatic update procedure is always called which causes exception. (One quick fix is to check if form.isDisposed in update procedure. But I do not think this is elegeant. Besides, these variables occupy memory.)

View 2 Replies

Use Variables Or Properties, And Global Or Static Variables In A Class?

Jun 9, 2012

I'm new in .NET programming.I have a class Form1 that includes Button1_Click event.Button1_Click creates a multiple Text Boxies at run time)Here is the class:

Public Class Form1
Dim shiftDown As Integer
Dim counter As Integer

[code].....

View 3 Replies

Asp.net - Declaring A Global Request.ServerVariable Variable

Jul 7, 2011

After many many years of using Classic ASP, I am attempting to delve into the world of ASP.Net using VB. I have gotten way to use to being able to declare variables on a page, inlclude that file and use it everywhere. I am struggling to declare a global variable. I just need

[Code]...

View 2 Replies

Declaring Variables On .NET?

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

Declaring Any Variables At All In A .Net Form?

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

Declaring The Public Variables?

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

Declaring Variables And Properties?

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

Declaring Variables In A Class?

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

Declaring Variables Within A Sub/function?

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

Loop And Declaring Variables?

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

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

Declaring Variables Inside A Loop?

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

Forms :: Declaring Module Variables?

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

DB/Reporting :: Declaring Variables In SSMS 2008 R2

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

Declaring VB Variables In VS2008 Aspx Webpage?

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

Any Way For A Class To Prevent Outside Code From Declaring Variables Of Its Type?

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

Asp.net - Does Retyping And Declaring Variables That Could Otherwise Be Inherited Degrade Performance

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

.net - Creating Global Variables In Asp.net Using C#?

Nov 25, 2009

I was working on window appication previously where i used to create global variables using modules in vb.net, but i found that in C# there is no concept of modules. so how can i create global vaiables in C#

View 9 Replies

.net - Global Variables And DLL Files?

Nov 16, 2009

I want that global variables that sit in some DLL will be seen from other DLLs and EXE of that project.

I included in that VB file "Option Explicit On" as the first line .

But still no one can see my variables that were defined in that file . I made that all DLLs of that project depend to that one with the definition

I am using module and all my variables are public .

Option Explicit On
Module LPSoft_Core
#Region "Public"

[Code].....

View 1 Replies

Global Variables And Functions

Mar 24, 2010

how can i create global variables and functions within a visual basic project?

View 6 Replies

How To Declare Global Variables

Aug 16, 2010

How I can declare global variables in vb.net that I can access them in all windows of my application?

View 5 Replies

How To Handle Global Variables

Feb 2, 2009

I'm creating an App that requires a few global variables (user information mostly) and I wanted to know the best why to declare these. I would like to create a "global" class with properties for each variable, but the property values reset with every instance of the class. Plus, what is the must excepted way to declare globals, I've heard placing them in their own module is as Globals is not a good practice.

View 7 Replies

Save All Global Variables?

Aug 20, 2009

I've got a RPG style game I am putting together - mostly to teach myself vb.net. I am using alot of global variables to hold game values.[code]...

My question is -- I am trying to make a "SAVE" and "LOAD" the game's state. Is there a simple way to save the values of all my global variables, without having to type everysingle variable out. Is there anyway to call upon all my global variables at one time, and possible save/load them to a text file ?

View 3 Replies

Using And Accessing Global Variables?

Apr 13, 2011

I want my "textbox.text" variable of my main form to be accessible by my other forms. Can somebody please guide me on making that a global variable?

View 12 Replies

VS 2008 - Global Variables?

Apr 4, 2009

I have this little code here in vb 2008, I created a flag var to see if the user has clicked the button "enter" so the flag would be set to true. If its true then the game would begin...

I have a label that says "Press enter to Play", and if the user presses play the flag is true, the label visible is set to false. I have the keydown event to check if the enter button has been pressed, i checked if it works and it does, but the var of the flag is always false in my other subs...

Thats the thing with vb i dont understand is when you make a public variable, and when you change the value of the var in a sub, it doesnt change globally.

CODE:

View 15 Replies

C# - Application Variables Global To Webgarden?

Jan 12, 2010

I am currently trying to program an online drawing program using the HTML5 canvas.the thing is, I need to have the current canvas saved somewhere globally. Static variables work, but they do not get shared across a Webgarden. This results in two different drawings being created.I will have to somehow create a new application object which is shared. I figured I will need an external application holding them.

1) How do I replace the application object with my own?
So either I will have to make my own program and call to it with remoting or use the ASP.NET session state server for application variables. I favor the Session State Server though.

2) How do I use the session state server for my own variables? How do I access it?

I searched high and low on the internet and only found the ideas mentioned above, but no help executing them.

I mainly code in VB.NET, but I can also understand C# code for examples.

A little info on my application:The client side has two canvas objects on top of each other. The top canvas object us used for drawing stuff, the canvas object below it holds the drawing in the end.When something is drawn, it is sent to the server in it's base64 representation. (getDataUri).The server puts this graphic on top of a stored Bitmap object through a Graphics object.

How the changes are being distributed to the other clients, I am working on that right now. Either I transfer the complete picture or each and every change that is submitted. This should work through Server Push. If this does not work thoroughly I will have to save and timestamp changes. A link to the current implementation, which is not currently fetching changes (but they get transfered to the server... With the problem that some reach one instance some reach the other on either w3wp in the webgarden) from the server is here: http:[url].....

View 1 Replies

Declare Global Value Type Variables With New?

Dec 29, 2009

What happens if I do: Dim x As New Int32? Is a object of int placed on the heap? If it is, maybe your application would be able to access global variables faster if they were reference types.

A global variable as an value type should be somewhere at the bottom of the stack most of the time and it might take more time to get to this then to get a object from the heap. Unless it's the same story with the pointer of this object is also at the bottom of the stack of course.

View 9 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved