Variable Scope Error/
Dec 16, 2011ok I have two procedures:This is for the tick of a timer
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
intTickCounter = intTickCounter + 1
[code].....
ok I have two procedures:This is for the tick of a timer
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
intTickCounter = intTickCounter + 1
[code].....
I have some code and there are 2 errors which I don't understand I have tried all sorts...
1)The type for variable 'Index' will not be inferred because it is bound to a field in an enclosing scope. Either change the name of 'Index', of use the fully qualified name (for example, 'Me.Index' or 'MyBase.Index').
2)Function 'GetNewPhrase' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.
I can't get it to work..
This webservice is almost converted form VB to C#, except I get this error shown below on the DataRow arow object when I use it in the foreach statement below to populate the Results Class with a DataSet Object...
Error: A local variable named 'arow' cannot be declared in this scope because it would give a different meaning to 'arrow', which is already used in a 'parent or current' scope to denote something else
using System;
using System.Web;
using System.Collections;
[code]....
how to declare scope for variables outside their class?
Here's what i have in a class known Create_User:
Public Class Create_User
Public conn As New SqlConnection(My.Settings.HotelConnectionString)
Public usercmd As SqlCommand
[Code]....
How can i increase the scope of these variables to be used in another class? I dont want to keep declaring them again and again.
I'm moving from VB6 to VB.net and there are a few things confusing. In vb.net, your program just automatically has a form, now the form in in a class and so it may or may not be there. In vb6, the main subroutine controls program flow and I don't see that in vb.net. However, my biggest problem is that I have a com dll that has a connect class with events. I need to be able to access these variable outside of that class. I don't understand how to do that. I can't seem to declare public withevents outside of the class and in the namespace so it can be shared with other code. Its say "not valid" in Namespace.
So what is the best way to do that. Do I create a set/get property for the class that holds this value? And, if I do that, is the connect class automatically instantiated as a part of the COM dll? Right now I don't instantiate the connect class, I assume the application does. But I'm not sure exactly how the property of the class would be set...perhaps I would need to call the property set from the on-connection method. Anybody know what the answer to these two questions are and this 3rd one? How can I have a variable that has "events" have scope across the entire project?
I have a public variable which seems to be going out of scope. I am confused as it has been dimensioned as a public variable: Public xlCell as As Microsoft.Office.Interop.Excel.Range
I originally had all my code in the same module in the same project and it was wrapped within a For/Next Loop (Example 1). I decided to clean up my code and make it more modular (Example 2). All the code is still in the same module in the same project.
Upon doing so, my public variable is not recognized in any of the private subs that I have created. I keep getting the following error: Message="Object reference not set to an instance of an object." When I test the variable using ?IsNothing(xlCell) in the Main Sub I get False in the main sub. this tells me te variable is recognized. However as soon as the Call SelectCaseSub() is triggered, I get a True value for ?IsNothing(xlCell). Why is this? Shouldn't this variable be in scope regardless?
[Code]...
I'm trying to create a simple media player that will scan a directory for certain filetypes, add them to a playlist then play a random playlist entry - changing every x seconds.I figured this would be simple in VB and, to an extent it was. I have the code running that chooses the directory and plays the random file.I just need to now make this repeat every 30 seconds or so.I have all the coded attached under the sub for the 'open' function of the player so it's quite flat. I think I need to use a timer here, to trigger the routine to pick and play the media every 30 seconds?In doing this I think I need to break the variables out of the function I currently have as they need to be shared between the timer loop function and the central 'creating file list' function.
I'm having trouble - I'm no coder (as you'll tell!) and although getting this far was easy I'm now (I think) bumping into threading / variable scope issues which are a bit of a brick wall.I've tried making the variables public / global by declaring in the class rather than the sub but I get errors at runtime. Presumably because of how I'm creating the windows media objects? [code]
where I should declare my variable when using forms and the scope in my test code.
In my code below I have declared variable x in my form1 which can be printed in form2.
But when I create a structure in form1, initialize an array of the type protorec and try to assign values to cards(1).firstname etc... I get a "declartion expected" error.
Why does it work for x but not for cards(x) my array of records?
Public
Class Form1
Public Structure protorec
[Code]....
I have put together the following code to illustrate the problems I've been struggling with:
Public Class OuterClass
Private _OuterProp1 As Boolean = False
Public Property OuterProp1 As Boolean
[code]....
I need to be able to refer to outer class properties and variables in an inner class, and I need to have a variable in one inner class set in a different class. I've tried Public, Private, Protected, Friend and all kinds of combinations of them, and I can't figure it out.
I'm working with legacy data, which often brings me one information splited in multiple columns. I'm trying to reproduce the following SQL query.[code]This own statement will run into the following exception:Variable 'line' of type 'SomeTable' referenced from scope '', but it is not defined. Any directions? I'm trying to avoid magic strings, but I'm always giving up to it (as using HQL the concatenation expression + like function works like a charm).
View 1 RepliesThis program was created with vb6 to find and remove empty folders. i converted this program to VB.NET code and it isn't working like it should.. it seems to stop scanning at 'C:\documents and settings' instead of scanning other folders in other directories...Does this code look right? I can provide the entire program if needed... I just want to know why it isn't scanning like it should. Btw im switching from vb6 and trying to learn vb.net.. vb.net is a lot different..
Private Sub ScanForEmpty(ByRef vFolder As String)
Dim nSize As Integer
System.Windows.Forms.Application.DoEvents()
If bExit Then Exit Sub
[code]....
I get this message at the bottom:Warning5 The type for variable 'FolderObj' will not be inferred because it is bound to a field in an enclosing scope. Either change the name of 'FolderObj', of use the fully qualified name (for example, 'Me.FolderObj' or 'MyBase.FolderObj').
plain how error handling scope works. What I mean by that is if I have a sub called ImportData and in there I have a for loop to go through a list of files and in the for loop I call another sub routine called CheckData. All have catch error in. If a sub has a catch error in where does it go from its call.
Private Sub ImportData
Dim iLoop as Int16
Try
[code].....
I am getting the error:"Range variable 'sender' hides a variable in an enclosing block or a range variable previously defined in the query expression."for this
Imports System.Data.SqlClient
Imports System.Linq
Public Class Form1
[code]....
I can select any other item from the table without the error. "sender" has the same properties as "receiver" in the SQL table.
I receive the error -
[Code]...
Been getting this error with my program. Using framework 2.0
[Code]...
I'm trying to enter automatically todays date in a number of records in the Table 'Applications' into the field 'Date_refund_request'.
However it is giving me the error 'object variable or withblock variable not set' in the line "Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)".
The code is as follows:
Private Sub Command16_Click()
On Error GoTo Err_Command16_Click
Dim db As DAO.Database
[Code].....
I'm writing in ASP.NET 4 / VB.NET. I am querying an MSSQL database and sometimes have records come back with no results...so I enclosed the call I was making upon the results in an If..Else clause to set a default value if the database comes back with no results...but now I am getting this "Object variable or With block variable not set error". Here is the relevant code:
Dim clcfirst
Dim rhcfirst
Dim clcdate As Date
Code].....
I am populating combo box from database. In debug i can see that the combo box has been populated . here is the code
[Code]...
My coding, I got error: Error Handles clause requires a WithEvents variable defined in the containing type or one of its base types.
For information i am using visual studio 2005. Here i highlight my probleam with in my coding
Public Class Admin
Private Sub TextBox6_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
[CODE]...
I'm probably missing out on something fundamental here but it seems rather tricky and confusing to me so here goes.to demonstrate the issue I have the following example .aspx page
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
[Code]...
Am looping a list object. The list contain 18 object. The loop running 18 times but the end of the 18th one getting Object reference not set to an instance of an object..
@For Each Slogs As SFAMobile.MobileServices.CustomerDetail In Model.Customers
@<option value='@Slogs.CustomerId' @selectedVal >@Slogs.Name ( @Slogs.CustomerId ) </option>
Next
I have been working on a VB app to edit an excel document. I want to keep my excel workbook in scope for the whole app.
For example here is how my program looks now
private sub
open workbook
end sub
private sub
reference workbook
end sub
I want a way to just call my workbook at the top and have all of my subs recognize it. I guess like a global variable or something.
[URL]
Does VB.NET have any scope nesting operators like {} in C type languages? Example C++ type code:
int i;
i = 0;
{
int i;
i++;
}
[code]In the above code what will be state of 'conn' variable and the 'cmd' variable and the State of the Connection to the DB in the following two case
i. Me.Close line
2. If any error occurs
While DataReader.Read
Dim Foo as New FooBar
Foo.Property = "Test"
Loop
In VB.net, does this create a new Foo instance every for every loop? Or just one Foo instance with block level scope? Do all blocks (If..EndIf, For..Next) work the same in this regard?
I am writing an App that automates file uploads from users desktops to a specified file server. On the first run of the app, I need the user to select a file server and save it for all other users of that PC. I thought I could do this
with application settings but it appears it is not suitable for this purpose. I need suggestions on how I can make this work.
I thought about a registry setting but the user may not have permission to edit the registry based on group policy/security settings.
I also thought about creating an XML file with the file server name that I can read from the installed project directory, but I was hoping there was a more streamlined way.
Below is example code of what I want to do:
Public Class Test
Sub New()
Dim cool As New B
cool.Doit()
[code]....
I am porting php code to vbnet (i'm a little better at vbnet than c#). In the php is the scope resolution operator.
Here's the bit:
$args = phpZenfolio::processArgs( func_get_args() );
Equivalent in c#/vbnet?The whole function is the following which i gues is equivalent to the sub new in vbnet.
public function __construct()
{
$args = phpZenfolio::processArgs( func_get_args() );
$this->APIVer = ( array_key_exists( 'APIVer', $args ) ) ? $args['APIVer'] : '1.4';
[code]....
I have a Function for checking the input in a textbox and only allowing Numeric & Backspace; everything works fine so far. My form is for financials and it has about 20 textboxes; they all receive Numeric only data; there is NO alpha data on the entire form required. Note in the snippet below that I don't even need a decimal point as well.
Is there a way to handle ALL textboxes on this form without having to place the Function call in each textbox KeyPress event. took a long (5 year) hiatus from developing VB6
Public Function TrapKey(ByVal KCode As String) As Boolean
If (KCode >= 48 And KCode <= 57) Or KCode = 8 Then
TrapKey = False
[Code].....
I have a complex Regex which is used to help strip out HTML from user input. I'm aware that .NET caches static Regex calls to some extent, but this one is big and used frequently, so I'd like it to hang around.[code]...
View 1 Replies