Declared A Class Variable Inside Sub?

Jul 26, 2010

I have a text file to read, at the first line will have a size of array, that means I cannot guess size of array, and I have to create a array in side a sub (Local Variable). Then, I want to use value of array in another sub, but I cannot use value of variable of another sub. What I have to do to make an array con be used in every sub/function in a class? Also, I've post an example file, code and error list.

[Code]...

View 1 Replies


ADVERTISEMENT

Variable Declared Inside A For Loop - Make This To A Compile Time Error?

Mar 27, 2012

Today I investigated a logical bug in our software and figured out that this is related to the way VB.NET thread variables inside a loop.Let's say I have the following code:

Dim numbers As New List(Of Integer) From {1, 2, 3, 4, 5}
For Each number As Integer In numbers
Dim isEven As Boolean

[code]....

The problem is that isEven is declared but not assigned.In this specific case, it would be correct to write dim isEven as Boolean = false but I haven't done this.In VB.NET, a variable that is declared inside a for loop keeps its value for the next itaration. This is by design: [URL]but this is also dangerous pitfall for programmers.

However, until now, I haven't been aware of this problem/behaviour. Until now.Most of our code base is C# anyway, which doesn't allow the use of an uninitialized variable, so there is no problem. But we have some legacy code that is written in VB.NET that we have to support. So the best thing would be to generate a warning or even an error in this specific case.But even with Option Explicit / Option Strict this does not generate a warning / an error.Is there a way make this a compile time error or maybe a way to check this with FxCop?

View 2 Replies

Inside The Service Class, Declare A Class Variable Named Started?

May 8, 2012

Create a class named Service. Inside the Service class, declare a class variable named Started. The datatype of this variable is Boolean.Public Class Service Dim started as Boolean End Class Create a class named Server. Inside the Server class, declare a dynamic array that can contain elements of the type Service.(Note: For convenience, both the array and the variable Started can be accessible from a client program that creates an instance of Server and Service respectively)

Create a constructor for the Service class. When the constructor is executed, it will set the value of the class variable Started to True. Create two new classes: WebServer and DatabaseEngine. Both of these classes inherit from the class Service. Inside the Service class, declare a Sub procedure (method) named Terminate. This method should display the following text Service stopping in a message box when executed.This method can be overridden in classes that inherit from Service class.

Inside both the WebServer and DatabaseEngine class, override the method Terminate inherited from their base class Service. Both methods should first call the base class Terminate method. The messages Web server stopping and Database engine stopping should also be displayed in a message box when the Terminate method for the WebServer and DatabaseEngine are called respectively. These messages should only be displayed if the Started variable inherited from their base class is not equal to False.

Inside the Server class, declare a method named Shutdown. This method does not return any value. When executed, it will call the Terminate method for each of the Service instances (if any) in the arrServices
array. You should call the Terminate method within a For Each loop that loops through the elements of the arrServices array.

In the Sub Main method, create an instance of the class Server. Set the size of the arrServices array in
your Server instance to contain 2 elements. Create first a WebServer instance and then a DatabaseEngine
instance into this array. Call the Shutdown method from your Server instance.

View 7 Replies

Access A Class Variable Inside Shared Method (JSON)

Jun 20, 2012

Inside my .aspx I have some JSON code that looks like this:

[Code]....

Basically what I'm doing is pulling text from two labels on one page, and sending them to another page by calling the "doIt" function which looks like this:

[Code]....

Just so I'm clear, the "doIt" function and the JSON call are on two separate web forms. My problem is that with the "doIt" function being Shared, I can't access any global variables of the class. And if I remove the Shared, my JSON doesn't execute.

View 1 Replies

Access Global Variable Inside Class Contained Within Module?

Nov 25, 2009

I've got a console app with a sub main then i have a seperate class inside the module..i can't seem to update the public global variable from inside the class as i can't declare the variable as shared...

View 6 Replies

WithEvents Variable 'PreviousPage' Conflicts With Property 'PreviousPage' In The Base Class 'Page' And Should Be Declared 'Shadows'?

Feb 1, 2012

I am converting an application from vb.net 2003 to 2005. I got the following warning and need help how to resolve it. withEvents variable 'PreviousPage' conflicts with property 'PreviousPage' in the base class 'Page' and should be declared 'Shadows'

View 1 Replies

Declared Variable Appearing Not Declared?

Feb 24, 2011

The following is a screenshot of the problem: What can I do?

View 3 Replies

VS 2010 Compiler Creates New Variable Automatically When Use If Statement Without Strictly Declared Variable?

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

Variable Naming Conventions To Illustrate Variable Type And Where Variables Are Declared

Aug 24, 2009

I am looking for a good resource on variable naming conventions to illustrate variable type and where variables are declared. So I will have public variables, Private variables, private or local variables. I also may want to declare variables with the same name in different class code (i.e. in the code behind different forms). I am assuming good coding would dicatate a prefix for declaration location.

View 4 Replies

VS 2008 Error "WithEvents Variable 'Move' Conflicts With Event 'Move' In The Base Class 'Control' And Should Be Declared Shadows"

Sep 3, 2010

What does this error mean? I havent modified anything in the designer code, but its giving me an error? WithEvents variable 'Move' conflicts with event 'Move' in the base class 'Control' and should be declared 'Shadows'. The error relates to Friend WithEvents Move As System.Windows.Forms.DataGridViewCheckBoxColumn

View 1 Replies

Possible To Return A Value That Is Not Declared Any Where Inside A Function?

Aug 15, 2009

Module Exercise
Private Function SetMembershipLevel()
Dim MemberAge

[code].....

View 6 Replies

Use Variable In A SQL Query - Says - Variable Is Not Declared

Mar 6, 2012

In one function I have the variable: dim StrProjectNumber = UCase("23-EXP-16284")

However in another form I want to use that same variable in a SQL query, and when I try it says the variable is not declared. Do I have to make a global variable or is there a way around it? If so, how would I go about declaring a global variable?

View 3 Replies

For Each Variable Is Not Declared

May 17, 2010

when I was using vs2008, code below was working without defining mystudent variable.It was recognizing type automaticly because of mystudents list of object.Has anyone know the reason why compiler returns error that "It is not declared"?

View 16 Replies

Variable Has Not Been Declared

Jun 17, 2008

If I modify this code (written by Luis Esquivel) because I want to dimension a variable and cast it either as a polyline or a polyline2d inside a select statement...it doesn't recognize the variable outside the select statment. I can't dimension it outside (or rather) before the select statement because I don't yet know how I want to cast it.

' by Luis Esquivel on June 29 2007
' using the idea/algorithm by John F. Uhden,
' one of the masters that use to frequent the customization ng of AutoDesk

[Code]....

View 7 Replies

Variable Is Not Declared

Sep 13, 2011

[code]...

Private Sub btnData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnData.Click[code]....

View 1 Replies

Variable Not Declared Before It Is Used With DAO?

Jan 11, 2012

I'm using DAO (been asked not to use ADO.NET) to update an Access database. I'm currently thus far, however, VB2008 is telling me that the variable "daoengine" is not declared before it is used. What am I doing wrong in the following code?

Function update_db()
Dim daoengine As DAO.DBEngine
Dim dbs As DAO.Database

[Code]....

View 2 Replies

Error - Variable Is Not Declared

Aug 11, 2011

I have a simple IF THEN ELSE block which checks for the presence of a querystring and then checks if it is set. The idea is that if no querystring, the form is empty and people can enter a new form. If there is a querystring and it isn't blank, a db query for the form data occurs, fields are populated and a user can update the form.

so here is my code block.

Dim strQueryStingCheck As String
If Not (Request.QueryString("pid") Is Nothing) Then ' is there a querystring?
If Request.QueryString("pid").ToString <> "" Then ' does it have a value?

[code]....

I am getting the "Variable is not declared; it may be inaccessible due to its protection level" for strQueryStringCheck ONLY on the Else code block - that is when I set strQueryStringCheck to "e". I can't figure it out.I've looked at other posts, particularly this one. and it was helpful. I can make the error go away, but I want to understand why I am getting it in the first place. I declared it within the subroutine. And if I was doing something wrong, shouldn't it throw an error on BOTH blocks of the IF THEN ELSE block? It doesn't when I set strQueryStringCheck to "u". Why only in the ELSE block?

View 2 Replies

Variable (aooreE) Declared But Never Used

Feb 27, 2012

catch(ArgumentOutOfRangeException aooreE){}
catch(NullReferenceException nreE){}
I got the error state that The variable 'aooreE' is declared but never used.

View 6 Replies

C# - Initialize An Array Variable That Has Already Been Declared ?

Sep 15, 2011

In C#, I can declare an array variable like this: object[] Parameters;

And initialize it like this: Parameters = new object[20];

In VB, declaring and initializing an array is easy:

Dim Parameters(19) As Object
Dim Parameters As Object(19) ' Alternative Syntax

How would I initialize an array variable that has already been declared in VB.NET? Parameters = New Object(19) doesn't work.

For example, how would I translate the following to vb.net?

int value = 20;
object[] Parameters;
if (value > 10)
{
Parameters = new Object[20];
}

View 3 Replies

Check When Variable Is Declared In A Page?

Nov 18, 2011

I have some web pages that include other pages, and I need to check if a variable (a string) has been declared in the page or not.

I was exploring try catch and finally, but im always getting a compiler error saying the variable doesnt exits.[code]...

View 3 Replies

LINQ Variable Not Declared Error

May 24, 2012

I am trying to run this line of code: Dim OrderedFiles() As String = Directory.GetFiles(FilePath).OrderBy(x >= x.CreationTime)

I get an error on x saying x is not declared. I have my project set to Option Strict Off and Option Infer On. If I turn ON Option Strict then I get thousands of errors from the project(it is inherited) and I don't have the time to fix all of them, but x no longer gives me an error. I have googled until I want to throw my computer out the window.

I was hoping for a more elegant solution but here is what I came up with to solve this particular problem.

[Code]...

It is not particularly elegant but it does the job. I was hoping for a one liner LINQ solution and I just don't have the background in LINQ to know how to do the job, time to go buy a book.

View 2 Replies

Pass Declared Variable To A Sql Query?

Nov 17, 2010

I have 2 public variables that I declared in form1 of an application. I am trying to call that variable in form2 and then pass that variable in a sql query. [code]...

View 14 Replies

Passing A Declared Variable To A Sql Query

Nov 15, 2010

I have a public variable that I declared in form1 of an application. I am trying to call that variable in form2 and then pass that variable in a sql query. If I declare:

Public Class Form1
Public payPeriodStartDate, payPeriodEndDate As Date

How then to I declare that variable in form2 and how to I pass it to my sql query.

Here is the code I have for form1: [Code]

and when I debug this form, no data will appear. I'm sure that it's something wrong with how I'm either calling the variable in form2 or in the query. Can anyone offer any assistance on this?

View 9 Replies

Use A Variable That Has Been Declared In Program In Xslt?

Oct 13, 2011

In my xslt file I want to apply templates to the xml but only if an id of that piece of content within the xml matches an id calculated in vb.[code]...

ContentparId is the attribute parId of Content in the xml. I want to compare this with mnPageId which is defined in vb (a foreign reference is passed through and the pageId that matches that foreign reference is returned)

I know the rest of the code does what I want it to do because if I manually change mnPageId for a correct pageId then I get the xml that I want back.

So, is it possible to use a variable that has been declared in vb in xslt?

View 1 Replies

Use Variable On Aspx Which Is Declared In Program?

Mar 18, 2010

I am getting some value from another form using Request.QueryString.Get(" test") and then i need to use this value on aspx page.[code]...

View 3 Replies

Variable Declared On Separate Button?

Oct 11, 2010

refering to a different object (in this case, a button). If somebody could explain to me the method for refering to this,

Current
(nrbRand1 and 2 are the variables on the separate button; this should be a quick fix for you guys)

[Code]....

View 12 Replies

VS 2005 Getting A...."Name 'Variable' Is Not Declared?

Sep 14, 2010

I'm trying to debug my program on a fairly new WIN7 64 Home Premium bit machine. Whenever I try to add a variable to the Watch window, I get the message... Name 'My Variable' is not declared.or Microsoft.VisualBasic.Right(StringRow, 14)'Microsoft.VisualBasic.Right' is not declared or the module containing it is not loaded in the debugging session

View 3 Replies

VS 2008 How To Get Value Of Variable Declared In Javascript

Mar 11, 2011

I'm login to the website with WebBrowser1 The source code of the website:[code]

View 4 Replies

VS 2008 VB: Getting Value Of Variable Declared In Javascript?

Sep 26, 2010

I'm using Microsoft Visual Basic 2008 Express Edition. In the little program I'm creating, I added a WebBrowser and a button that will make the WebBrowser navigate to a designated website when clicked. So far, it's fine.

The problem is that I want to be able to get the value of a variable declared in the website's javascript. How do I do this?

The following is a part of the source code of the website.

<script language="javascript">
var contextPath = "/websmsn";
var noSessionPath = "/websmsn

[Code]....

I want to get the value of "activeMsgSessionId" and store the value in my own variable. The value of "activeMsgSessionId" changes every time the website is loaded.

View 1 Replies

'variable' Is Not Declared / Inaccessible Due To It's Protection Level

Nov 27, 2010

i'm sort of a n00b to VB and was wondering how to make a variable available across multiple Subs. It's just a test app to get familiar with VB.My Code:[code] "Sentences" is not declared. It may be in accessable due to it's protection level."

View 4 Replies







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