Iteration Of Class Variables?

Sep 23, 2011

Background: I am working on an ASP.net project that basically fills out a form from user input. The generated form (for reasons which I have no control over) must be a JPEG or TIFF. So the user fills out the web form, which takes all of the input values and meges them into a blank image (jpeg) of the form. Using System.Drawing, it merges all of the text onto the form at designated Points. The points are defined as variables which are modified at runtime to compensate for the resolution of the image (in case it get modified/re-generated at a different dpi). All of this is working fine.

Problem: Currently I have a Sub that determines the dpi of the master image, then adjusts the Points accordingly. However, there are ~50 variables that have to be adjusted. So currently I have the Sub go thru each point variable and manually adjust the X & Y values. I have been working on a Sub that will iterate thru all of the Point variables and do adjustment. Here's a functional sample of what I have working:Imports System.Drawing

Partial Class test Inherits System.Web.UI.Page

[Code]...

This works...sort of. It allows me to grab each variable and modify it, but only in the instance. The original variable in the class is unchanged. Which means that when the program gets to the point where it's drawing text to the image, the points are unmodified. my basic question is: Is it possible to modify the original variable using this sort of process? If not, is the best way to use these modified values to declare the new class instance at a global level, then have the Sub that draws the text use the instance versions of the variables?

I realize that I could define all of the points in an array which would be easy to loop thru and update, but I've named each point variable something meaningful to correspond to the related text to be drawn.

View 1 Replies


ADVERTISEMENT

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

Use Derived Class Shared Variables In Shared Methods Of Base Class?

Jun 4, 2010

I am trying to add shared members in derived classes and use that values in base classes...

I have base

class DBLayer
public shared function GetDetail(byval UIN as integer)
dim StrSql = string.format("select * from {0} where uin = {1}", tablename, uin)
end function
end class

[Code]..

currently there is error using the tablename variable of derived class in base class but i want to use it i dun know other techniques if other solutions are better then u can post it or u can say how can i make it work? confused...

View 2 Replies

Variables In A New Class

Oct 18, 2011

I have some variables in my main Form, but I want them in all my other forms, how can I make them kinda global or something?

View 1 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

.net - Override Variables Declared In A Class?

Dec 16, 2010

I'm trying to create a generic Controller Class for generic events. But these these events still need to access their class variable. So my idea is to create the Base Controller Class with a ModelBaseclass variable as _ClassVar, which is inherited by all of the other class Controller classes will derive from. But I want the derived controller classes to override the _ClassVar with whichever one they need.

I want to do this, so the ControllerBaseClass can have all the generic functions that all the Derived Classes would use.

Model :

Public Class ModelBaseClass
Public Overridable Function Foo() As String
Return "Name"

[Code].....

View 2 Replies

Access Shared Variables Of A Class?

Jul 23, 2009

I am making a small application in which i have added a class module and a window forms in vb.net. i want to acess the shared variables and mathods of class without making any object.

View 8 Replies

Assign A Value To The Variables In The Class File?

Jan 28, 2009

I have a class file, myClass.vb. Here is an example of the file:

Private _active As Integer
Private _categoryID As Integer
Property active() As Integer

[code]....

when I want to assign a value to the variables in the class file, should I assign them like what I have in line 24, and 25 or line 28 amd 29? how I assign the variables in terms of performance?

View 2 Replies

Class - Using Variables For Referencing Objects?

Feb 25, 2010

when using variables in object names.I have a Public class which is called "Tank".In that class, there is a public property called "direction" of an integer type.I keep getting the error:

"Tank is a type and cannot be used as an expression"What I'm doing wrong here ?

Public Class mainroutines()
Create Instances of tank
Private Tank1 As New Tank()[code]....

View 3 Replies

How To Access Variables In Another Class Without Deleting Any

Oct 31, 2011

I have been charged with porting a VB6 project into VB.NET. In vb6, if you were in a class separate to a particular variable, you could access that variable easily:

Public Class Foo
Public k As Integer
End Class
Public Class Bar
k = 12
End Class

In VB.NET, my understanding is that before you can use a variable in another class, you must declare a new instance of it:
Dim foobar As New Foo
This would be fine, but I have to access these variables from different classes and every time I declare a new instance, it wipes all old values from the variables, which I need. I tried using Inherits statements but they presented many problems.

View 2 Replies

Naming For Namespace / Class And Variables

Jul 7, 2009

In the code below, the namespace is called "Navigation" which I think is correct. Then I have a class called "Heading", which by definition is the direction a person/vehicle is truly pointing towards. I think that is also named correctly. In the code below, I have four things I have named:
_WhatToName1, WhatToName2, WhatToName3, and WhatToName4.
The value that gets passed in and stored is a double between 0 and 360 -- essentially the degree value from a circle. For WhatToName3 and WhatToName4, I have seen a lot of places that just use "value" as the name. Is that standard?

Namespace Navigation
Public Class Heading
Private _WhatToName1 As Double
Public Sub New(ByVal WhatToName3 As Double)
Me.WhatToName2 = WhatToName3
[Code] .....

View 18 Replies

Net's Assembly Class Store Variables?

Aug 20, 2010

Ok so here's the story. I have an array of Assemblies which are initiated by [Assembly].LoadFrom() that load a number of DLL's. Upon initialising, a method called InitMain (from the DLL!) is called, which sets a number of variables outside of this method, like here:

Public Class Example
Dim C As Integer = 0
Public Sub InitMain()
C = 50
End Sub

[Code]...

If I call the method Test using that same array of Assemblies somewhere later in the main application (like pressing a button or something to trigger it), it will pop up a messagebox with that says: "C = 0"Why is this? Is it fixable without any odd workarounds?

View 2 Replies

Passing Variables Between Instances Of A Class

Jun 17, 2009

I created a program a while back, in the traditional VB.NET way by drawing a bunch of forms. I have started playing around with creating the forms at runtime using classes. I have a placeholder form called frmStartup which merely calls the CreateLogin() sub from the CreateFormClass. The CreateLogin() sub creates a new blank form, then calls the grpbxLogin(), btnSave() and btnExit() subs from the FormElementClass which adds all the buttons and textboxes to the form. Within the FormElementClass, I have associated btnSave and btnExit with event handlers. These even handlers call subs from the DataProcessingClass. The event handler for Exit works just fine.I am having a problem with the Save event handler. Precisely, I don't know how to pass either the username or password from the Login form to the btnLogin_Click() sub in the DataProcessingForm. I have tried using Me. and frmLogin., but the program doesn't see either of those. If the Login form is an instance that is disposed of once another Sub is called, then it won't exist later on to call from. I have tried declaring variables and passing those along to btnLogin_Click, but no matter where I put it, the program doesn't see txtbxUsername.Text or txtbxPassword.Text. Not even from within FormElementsClass, which is were the boxes are created.Any ideas on how to pass variables in this case? I am not even sure what you would call this such as passing between classes, or passing between instances.[code]

View 9 Replies

.net - When Are Inline Static Variables Initialized In A Class

Aug 10, 2010

Suppose we have a class like:

Public Class Question
Private Shared _field as Integer = CrazyIntegersRepository.GetOne()
' Some other useful things go here
End Class

And the method GetOne throws an exception... How can we manage that? Is a good practice to rewrite that into a static constructor? When is the GetOne method going to be executed if we leave it there in the inline _field declaration?

View 3 Replies

Accessing Public Class Variables In Asp.net Without Session?

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

Accessing Variables In Partial Public Class?

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

Array Of Objects Also Saving Variables Of Class?

Dec 21, 2011

I have a small class of Object CellValue

Friend Class CellValue
Public CellColor As Color = Color.White
Public CellShape As Shape = Shape.Blank
Public CellName As String = ""
End Class

Then in my main I make an array of CellValue but I want to know if the values are also being passed down with the array.

Dim Plan(SizeW - 1, SizeH - 1) As CellValue
Dim CellW As Integer = PictureBox1.Width \ SizeW
Dim CellH As Integer = PictureBox1.Height \ SizeH

[Code].....

Are CellName, CellShape and CellColor being tied to each element in the array?. The reason is because I need to use these properties to tie certain functions to them. The CellName should have a MachineID which I would have to use to pull some info from a Database.

The Array should also be serialized and deserialized to XML as customer needs to create/edit and delete certain values in the array. And in order to save the array has to be in XML

So the Questions are does it save the CellName, CellShape and CellColor for each element, will it be affected if I serialize and deserialize using XML. If possible, how can I call up the Cellname p.e for a specific array element.

View 5 Replies

Class - Parsing The URL In Order To Retrieve Variables

Jul 26, 2010

I am trying to make 2 variables available throughout my site. I am parsing the URL in order to retreive both of them. This code on the page itself works fine.

[Code]...

View 3 Replies

Class Member Variables Methods And Their State

May 27, 2010

How should class member variables be used in combination with class methods?Let's say I have a class 'C' with a member variable 'someData'.I call C.getData(), which does not return a value but instead puts data in C.someData. The class that instantiated 'C' first calls C.getData and then uses the data by accessing the member variable C.someData.I call C.getData() in the class that instantiated 'C' which is a function that returns data.I myself prefer the second way. But it also depends on the situation and it's a small difference. Is it 'bad' to have class methods that depend on the classes internal state? What are the best conventions?

View 2 Replies

Class Not Updating Variables Passed Byref

May 5, 2012

I have a class in vb.net defined as public class A

class A is created on Load and gets called once per program loop

The constructor for class A includes the argument (byref Value as long)

I have a global variable called varB that is passed to class A on creation.

now why when varB is altered during the program loop, the change is not reflected within the class?

View 1 Replies

Class Variables - Preserve The Last Window Position

Jun 4, 2011

I have two forms that are called by the main form. One is named frmEdit, and is invoked by the ShowDialog (modal) method. The other is named frmSearch and is invoked by the Show (non modal) method. In both cases I want to preserve the last window position so each form (class) begins with Public Class frmEdit (or frmSearch):

Dim lastx as Integer = -1
Dim lasty as Integer = -1

in the Shown event handler for each form I have the code
If lastx >= 0 Then
Me.Left = lastx
Me.Top = lasty
End If

and in the FormClosing handler I do
lastx = Me.Left
lasty = Me.Top

What I don't understand is why the frmEdit (modal) form remembers its previous position but the frmSearch (non-modal) does not. frmSearch always invokes with lastx and lasty equal to -1.

View 5 Replies

Declare Variables In Public Class Form1?

Apr 29, 2012

When and why do you declare variables in the Public Class Form1 section?

View 1 Replies

Losing Class Variables - Use Classes More In My Programs

Sep 24, 2010

I'm trying to use classes more in my programs. I'm using classes. This is the section of the main form that is causing the problem:

If conType = Nothing Then
TaOrIbt()
End If
objGetECaptureType.CaptureType(conType)

[CODE]...

View 12 Replies

Naming Convention For Variables In Class Constructor

Nov 26, 2010

In the past when I have written classes and constructors, I named the variables in the constructor parameter something different than what would have been stored in the actual class itself.What I do now is name them the same, and reference the internal variables with Me.varname.Here is a class I just started building.Is my naming convention incorrect? [code]

View 1 Replies

Passing Variables From One Project To Class Library

Mar 10, 2009

How to pass a variable in one project to dll in vb.net

View 1 Replies

VS 2008 Writing Methods That Act Upon Class Variables?

Mar 24, 2010

I'm not sure I used the right lingo in the subject header. But, here's what I want to do. Let's say I have a class with some variables:

Class XYZ
Public InfoNo1 As Integer
Public InfoStr1 As String = " ".PadRight(200) 'Hahaha
Public InfoStr2 As String = " ".PadRight(100)
End Class

I've been looking around for examples of writing methods that act on variables defined within the class. What I want to do is make it so that doing something like this:

[Code]...

I don't need to know how to write the method, I think I can do that. I need to now how to make the method cause a ".Fixed" option to be added to the class string variables so that assigning a string using that method will cause the variable itself to be equal to the string plus the padding.

View 39 Replies

VS 2010 Class / Properties And Variables W/ MySQL

May 3, 2012

Ok so my boss told me that I can't use DataSet's and dataadapter and such like this because it isnt good for scalability. So, I must change the way I have my 28,000 records binded to my form. The problem is, I'm only 3 months in with VB.NET and I don't know of any other way to accomplish what I need to do. I was reading somewhere that I can use a Class as my "Order" and I can bind the variables/properties to the form and with this, I can navigate through records while having controls on each important part of the "Order". Unfortunately, I don't know what I'm doing, this is as far as [code]Any guidance as to what I am to do from here in order to pull the data from my database and bind to the property, then to a text box/combo box, and a way that I can use my binding navigator to go through the many records.

View 13 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

C# - Initialize The Variables - Name Property Of The Dings Class To Be Initialized At First?

Jan 27, 2011

I have classes similar the following:

[Code]...

I want the Name property of the Dings class to be initialised at first, I know, I could also create the foo-object (as member of dings) later in the constructor. But I want to have it this way, because in the end there are very much singleton objects instantiated in the Dings-class that I want to be created in only one line.

[Code]...

View 3 Replies







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