Does Constants Take Up Memory

Jan 4, 2010

i was concerned if constants take up storage. if a class had 10 integer constants at class level, will that adds up to 40bytes of storage or is that actually not true because they are constants?

what i'm trying to do: find the best place to put the constants that i need to access at class scope, and whether its best to make them shared or not. [constants are private]

View 31 Replies


ADVERTISEMENT

Proper Way To Implement Global Constants Plus Memory Considerations

May 3, 2012

I am new to Visual Studio and Visual Basic, but I am a revived dBase, FoxPro, Visual FoxPro, ColdFusion programmer..I'm as good once as I ever was.So I am looking for how to implement some constants for the three main reasons anyone would want to use global constants:Readability, Maintenance,Memory Usage.For example in a list of error return codes, I may assign "File Not Found" an error code of 1010.To create a constant that exists only within a procedure, declare it within that procedure.To create a constant available to all procedures within a class, but not to any code outside that module, declare it in the declarations section of the class.To create a constant that is available to all members of an assembly, but not to outside clients of the assembly, declare it using the..Friend keyword in the declarations section of the class.To create a constant available throughout the application, declare it using the Public keyword in the declarations section [of] the class. global it is visible to all procedures and modules that comprise the application. Global variables and constants, as with Module level variables, must be declared outside of any procedures in the Declarations section and must use the Public keyword.The language above stating "Global variables and constants, as with Module level variables..." insinuates to me that Global Constants and Module Level constants are different, thus having different scopes.

And I have yet to see ANYWHERE that tells me to put stuff in the Declarations Section of a class or program or application, tell me just WHERE the declarations section actually IS! They always give the code of how to declare (I can do this...) but they don't say where the code GOES.I know I am overlooking the simplest of things, but just trying to be very sure of what I am doing.[code]

View 15 Replies

The Name "The" Is Not Permitted In This Context. Valid Expression Are Constants, Constants Expression, And (in Some Contexts) Variables

May 31, 2012

I am calling this function when a button is CLICKED and received the error; The name "The" is not permitted in this context. Valid expression are constants, constants expression, and (in some contexts) variables. Column names are not permitted. Unclosed quotation mark after the character string 'True)'.

The function is as follows;

Private Sub Save()
Dim conn As SqlConnection = GetDbConnection()
Dim query As String
Dim cmd As New SqlCommand

View 3 Replies

Loading An Image From A Jpeg That Exists In Memory (but Not On Disk) Using Direct Memory Access

Nov 5, 2009

In VB 2005, I am calling a C++ DLL function that returns the address in memory and size in bytes of a jpeg image. How can I load that jpeg image directly from memory into a picture box in my VB form? I cannot afford to save it to disk first.

View 10 Replies

Attempted To Read Or Write Protected Memory / Often An Indication That Other Memory Is Corrupt

May 22, 2007

Im getting a problem with one of my programs I have made in visual basic.NET where it gives me a memory error when i debug the program in the IDE. the exact error is this: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt". My program basically has a few forms with text fields on that get their text values from an access database on the same hard drive. Im wondering if im doing something wrong because my program just seems to eat up memory whenever it does anything. For example I have one form that has a combobox on it and when you change the drop down list selection it retreives a few strings from the database and puts them into the relevant text boxes, if you keep changing the selection then the memory usage (in task manager) just keeps going up and up. occasionally I get the error mentioned above when debugging but in my built version of the program it throws an exception everytime the memory usage gets past 49K.

Also I noticed when debugging in the "immediate window" frame I get the following message often:A first chance exception of type 'System. Invalid OperationException' occurred in System.Data.dll...Do I need to somehow be "releasing" the memory that is used to gather data once it becomes redundant?

View 12 Replies

Attempted To Read Or Write Protected Memory. This Is Often An Indication That Other Memory Is Corrupt

Nov 24, 2011

I am using the following code

This error occurs :

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Public Class FormRegEnumValue

[CODE]......................

View 2 Replies

Attempted To Read Or Write Protected Memory. This Is Often An Indication That Other Memory Is Corrupt?

Feb 1, 2009

QuoteSystem.AccessViolationException was unhandled Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt." Source="System.Windows.Forms"

Im designing a web browser and i continue to receive this error after going to about 3 websites it crashes with that error.

View 6 Replies

Necessary To Detach Event Handlers To Ensure That Memory Is Cleaned Up And That There Are Not Memory Leaks?

Jan 20, 2010

I have a BackgroundWorker object that I instantiated to perform a DB process on a background thread ansynchronously. I have event handlers for DoWork and RunWorkerCompleted. I can tell that the BackgroundWorker is disposing of itself because I added a message box into the Disposed event handler.Is it necessary to detach the event handlers to ensure that the memory is cleaned up and that there are not memory leaks?

View 1 Replies

Thread And Memory Leaks - Memory Usage Jumps About 1000k And It Never Goes Back Down

Apr 17, 2011

I've noticed that every time I start a new thread in my program, the memory usage jumps about 1000k and it never goes back down. I have ensured that the thread is no longer running, and only one instance of my worker thread is ever running at a time. I am using ThreadPool.QueueUserWorkItem and ASyncOperation to get stuff done. The program starts using a Sub Main in a module that uses STAThread; I read that using STAThread instead of MTAThread makes it impossible for the Garbage Collector to get in and consider objects for garbage collection. However, when I change the STAThread to an MTAThread, the WebBrowser control in my frmMain cannot be instantiated.

I get this exception:

Code: An unhandled exception of type 'System.Threading.ThreadStateException' occurred in System.Windows.Forms.dll

Additional information: ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment. I do threading with the WebBrowser control, so will using MTAThread fix my problem? If so, how should I partition my code so that the WebBrowser control won't be affected by the above exception? I call the thread repeatedly with a timer (although only one instance ever runs at a time), and my program's memory usage starts at about 5000k and can jump to 300,000k+ depending on many times the thread needs to be called.

View 6 Replies

2008 Express Edition: Attempted To Read Or Write Protected Memory, This Is Often An Indication That Other Memory Is Corrupt?

May 27, 2009

I cannot use Visual Basic 2008 at all. When I go to "new project" and choose "Windows Form Application" I get this error.I have tried multiple uninstall/reinstall with no result.A microsoft reply to this suggested that I needed: " .NET Framework 2.0 Service Pack 1 " I checked, and I did not have the .netframework 2.0 service Pack 1.
When I tried to download and install the above from Microsoft.com, the istaller said that "it was not allowsed" and I was not able to install the service pack 1.

I tried Uninstalling net framework 3.5, 3.0, 2.0 and then reinstalling .netframework 2.0 sevice pack 1; then reinstalling Visual basic 2008 express edition. At the reinstall of Visual basic 2008, .netframework 2.0 sevice pack 1 is unistalled by .net framework service pack 2.When I check the foruims for simiar problems, the formus are mostly for Visual basic 5.0, or other programs that I do not have.

Here is the programs I have installed:

Operating system: Windows XP
Microsoft .net framework 1.1
Microsoft .NET framwork 1.1 Hotfix(KB928366)
Microsoft .Net Framework 2.0 Service Pack 2

[code]....

All the security updates and hotfixes for Widows XP.

View 4 Replies

DirectoryEntry Memory Leak - Gets A Out Of Memory Error In The Last Catch Statement?

Jan 11, 2012

The follow code can be called about 6K times on the server it is run on then gets a out of memory error in the last catch statement. I don't see what is wrong with the code, it works well up until the out of memory..

Public Function AddUserToGroup(ByVal sSamAccountName As String, ByVal sGroupName As String) As Boolean
Try
Dim returnStatus As Boolean = True[code]......

View 3 Replies

Read Or Write Protected Memory Often An Indication That Other Memory Is Corrupt?

Feb 9, 2011

I have two forms, Form1 and Form2. Form2 has a button to show OpenFileDialog. I call Form2 from Form1 by a button. My startUp Form is Form1. When i start debugging, i press my Form1's button to show my Form2, it shows, but when i click On Form2's Button to show OpenFileDialog it is giving me exception that

"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

When i set my startup Form to Form2 and click Form2's Button to show OpenFileDialog then it shows!

View 13 Replies

.net - Convert Constants From Vb To C#

Nov 28, 2010

There are a bunch of constants like vbTab in VB.Net, is there corresponding one in C# ?

View 1 Replies

Can't Understand What Constants Are

Apr 24, 2012

i cant understand what constants are.

View 3 Replies

Container For Constants In .NET?

Jun 29, 2010

Say I have some constants that depends one of other, and I decided to keep them together in a container instead of keeping it as individual constants in a class.I thought use a Structure for that scope, but compiler force me to declare a private member for that structure.

[Code]...

View 4 Replies

Declaring Constants From DLL

Jan 8, 2009

How would you declare constants from a .dll, so you can use it in your program.

View 2 Replies

How To Define Pen Constants

Sep 2, 2011

I want to define several constants of pens like SystemPens. How do I do that?

View 6 Replies

What Are The Following Key Constants On The Keyboard?

Sep 24, 2011

Can anyone explain what the following vbkey constants are as actual key presses? I've tried searching and really can't find any info other than vbKeyCancel = CANCEL key. Well, what's a cancel key? I dont have one on my keybaord...I read somewhere that CANCEL = Ctrl+C. Is that true? If so, what are the other few I have listed?

Constant
Value
Description[code].....

View 2 Replies

.net - VB Struct With All Windows Constants?

Apr 6, 2011

Every time I do something that ends up using windows API calls in VB, I always end up having to look up the values for the windows constants. Does anyone have a file with a class or something for VB that defines all the WIN-API constants?

View 2 Replies

Access Constants In List Box?

Oct 17, 2011

I have two list boxes that have a list in each and each one has a constant. I am trying to add the selections that are made together and output the total in a third label. I am stuck at this point and am not sure how to proceed, it is entirely possible that i am doing it wrong. Would someone please have a look at this and let me know what the next step would be or if there is a different wayof doing it than I am.[code]...

View 4 Replies

Add Built-in Constants To Program?

Jul 30, 2010

It would be good if visual basic had standard math constants like pi, the Euler number, and others built-in so one doesn't have to define them each time and have the possibility of making typos. Even some of the physical constants in MKS unit could be included like the Boltzmann's Constant, speed of light, permittivity and such. Each could be a special simple like kb for the Boltzmann's constant. Or it could be a properties like phyconst.c for the speed of light, phyconst.kb for the Boltzmann's, phyconst.sb for the steffan-Boltzmann's constant, pmathconst.e for e=2.71.

View 3 Replies

Create Constants In Project?

Dec 10, 2009

Calculate and display the total cost of the sale, as well as the total cost of all sales and the average cost of all sales. - Clear the box for the number of yards, the total cost, and return the quality, padding, and installation settings back to their defaults. Use constants for the cost of each quality of carpeting ($4.95 for Fabulous Flat, $8.95 for Precious Plush, or $12.95 for Super Sculptured), the padding charge ($1.25 per yard), and the installation charge ($3.50 per yard).

[Code]...

View 5 Replies

Make Array Of Constants?

Feb 23, 2010

I've got a situation where I need a table of constants in my app. It's actually a table of 43 formatting options where the description will appear in a drop down and the detailed settings will be used by the codeIt appears that VB can't do arrays of constants. So I've fiddled around with a Constructor in a class that creates a new array then loads up each element with hard-coded .Add statements. It doesn't seem elegant though.So I then decided to try an XML file, that I load in the Constructor and assign the contents to an array. This is what I've decided is the best, most elegant, option - but I'm throwing this question in to see what you people might recommend ! The data is mostly strings

View 11 Replies

Replace VbLf And Chr() With Constants?

Mar 18, 2009

We're trying to trim the number of assemblies we load during startup, and one of the easiest to cut is the Microsoft.VisualBasic assembly. There are alot of things in it that were easy enough to replace, like Left(), but I'm struggling to find a good way to replace vbLf and Chr(). vbCrLf was easy enough to replace with Environment.NewLine, but we have a few spots where we generate content for a Unix-based system that is expecting line feeds only.

View 5 Replies

Use The Correct Values For The Constants?

Sep 24, 2010

The code underneath works when I use WM_MOUSEMOVE but not when I use WM_NCMOUSEMOVE. Is WM_NCMOUSEMOVE not supported anymore?I use the correct values for the constants too.Protected Overrides Sub WndProc(ByRef m As Message)Dim MousePosition As Point

Select Case m.Msg Case WM_NCMOUSEMOVE MousePosition = New Point(m.LParam.ToInt32())
If MousePosition.Y < 50 Then CloseButtonState = ButtonState.Flat
Else
CloseButtonState = ButtonState.Normal

[Code]...

View 14 Replies

Where Are Excel VBA Constants Defined For .Net

Nov 13, 2009

I am exporting data to an Excel spreadsheet from a VB.Net 2008 application. Now I'm trying to format the spreadsheet. So I am creating macros in Excel that format the spreadsheet, and then using the code it generates in my application. The problem is that the constants used in VBA are not being recognized in VB.Net (They are recognized in VB6). I have the following imports:

Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Excel

Is there something else I should be importing? For example, in this line, xlNone and xlDiagonalDown are flagged as not declared.

oXL.Selection.Borders(xlDiagonalDown).LineStyle = xlNone

View 5 Replies

Where Should Put Global Constants In A Library

Apr 19, 2012

I'm working with an API that spits out alot of data in name=value format. At first I processed everything by doing simple string comparison:

Sub ProcessData(ByVal name As String, ByVal value As String)
If name = "thisname" Then
DoThis(value)

[code].....

View 2 Replies

Access Compiler Constants In Code?

Jan 11, 2011

Is it possible to use a constant defined by the compiler in code like below?[code]...

I'm running batch processes and I'm experiencing problems with one of my customer's data. I want to add special code for only that customer, but I want to keep the code there so I can easily switch the customer ID in the future should i need to debug a different customer.[code]...

View 2 Replies

Assigning Large UInt32 Constants

Jan 4, 2011

I inquired on VB's erratic behavior of treating all numerics as signed types back in this question, and from the accepted answer there, was able to get by. Per that answer:

[Code]...

View 3 Replies

Changing Value Of Hardcoded Double Constants

Feb 15, 2011

after working with some VB.net files in a project, I find that somehow the values of hard coded numeric double values have changed,that is:[code]This has happened in a lot of the source files of the project.When does this replacement take place? While I can understand that the original numbers cannot be exactly represented as double, I do not want this substitution, is there some way to prevent them? Initially I thought that was some behavior of the source control system (TFS)

View 18 Replies







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