Event Variable Scope Across Whole Project
Jun 7, 2011
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?
View 3 Replies
ADVERTISEMENT
Mar 15, 2011
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]
View 8 Replies
Dec 16, 2011
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].....
View 4 Replies
Jun 12, 2011
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.
View 4 Replies
Aug 23, 2009
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]...
View 6 Replies
Mar 11, 2010
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]....
View 16 Replies
Jul 13, 2011
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.
View 4 Replies
Jun 11, 2012
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 Replies
Apr 19, 2009
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..
View 9 Replies
Mar 12, 2009
This 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').
View 3 Replies
May 24, 2010
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]....
View 1 Replies
Oct 18, 2010
If I declare my object at the beggining of my page class, and instantiate it in a dropdownlist selected_index change event. Shouldn't this object be available thru out the entire page and also persist thru a postback? I lose the object in my selected date change event in my calendar.
[Code]...
View 3 Replies
Jan 16, 2009
i declared a global variable button:
Dim button1 As New Button()
Now, i dont know how to add a click event in this button since it is a variable.
View 3 Replies
Feb 27, 2011
just Addition only at this time each number 0 to 9 have this code[code].....here what he says..Write the code for the equals button. There's only three lines in total, and here's a little help.
You need to use the other variable that was set up at the top of the coding window, total2. The variable total1 will be added to whatever is total2.The first line of code will be this
total2 = total1 + (something missing here)
Your job is to supply the missing code. In other words, replace "(something missing here)"
Remember that total1 contains the first number to be added. And you know where that came from. The only thing left to do is to add the second number.For the second line of code, you need to transfer the total2 variable to the textbox.For the third line of code, all you are doing is resetting the variable total1 to zero. That's because after the equals button has been pressed, we have finished adding up. If you wanted to do some more adding up, that total1 will still hold the value from the last time. If you reset it to zero, you can start adding some new numbers.
View 2 Replies
Aug 3, 2010
I've been looking at using PROPERTIES [URL] but frankly I don't understand it that well. Before I invest the time to read, understand, and truly comprehend this, I want to make sure it's the best way. My intended goal is to create my database connection string in a function/sub somewhere, then assign it to this project wide string variable, then I can use it in any form, project wide without having to recreate it.
[Code]...
View 7 Replies
Sep 25, 2010
I can't figure out how to make it so that when a variable reaches a certain value, an event is triggered. For example if I wanted a user's level to change to 2 when he gets 1000 exp.
Dim level as integer
Dim exp as integer
*****What do I put here?*****(when exp reaches 1000)
level = 2
View 2 Replies
Jul 30, 2011
Dim conn As MySqlConnection Reuse a variable from another event?
View 3 Replies
Jan 1, 2011
I've gone brain dead and can't remember how (where) to declare a variable to be shared by 2 forms (classes) in the same project.
View 2 Replies
Mar 9, 2010
If I have a string that contains the name of a control is there a way to call that control's click event?
Dim a as string = "MyButton1"
Now I want to call MyButton1.Click Method or MyButton_Click Event using the contents of a.
View 7 Replies
Apr 25, 2012
I have a form in VB.NET that is used as a dialog in a mainform. Its instances are always locally defined, there's no field for it. When the user clicks the OK button in the dialog, it will fire an event with exactly one argument, an instance of one of my classes. Since it is always a local variable, how can I add an event handler for that event?
Code for the event, a field in MyDialog:
public Event ObjectCreated(ByRef newMyObject as MyObject)
Code for the main form to call dialog : (never mind the syntax)
Dim dialog As New MyDialog()
dialog.ShowDialog(Me)
AddHandler ObjectCreated, (what do I put here?) //Or how do I add a handler?
View 2 Replies
Apr 27, 2010
I can create event prodcedures for form objects, but is there a way to create an event that triggers when a certain variable equals a certain value?
View 3 Replies
Jun 22, 2010
I haven't quote grasped this whole "class" concept yet, but I'm working on it. When following the instructions below, the "test" portion of this code: "test.variable". It has an underlined error that says that "test" is not declared. If I remove the "test" word then the ".variable" shows not declared. I'm using Visual Studios 8 if that makes any difference. I have a pre-existing variable in a project that I would like to monitor for changes.
Re: Detect variable change.
Make your variable a class with an event.
Make your class:
VB.NET Syntax (Toggle Plain Text)
Public Class myVar
Private mValue As Integer
Public Event VariableChanged(ByVal mvalue As Integer)
[Code] .....
View 1 Replies
Jan 3, 2010
How can I make an event that is raised when a variable or property is changed (or can I just put the code I would put in an event in the Set section of a property?
View 5 Replies
Dec 8, 2010
How is conditional compilation controlled for a VisualBasic web? For a VB Windows app, I put a conditional variable in Project > Compiler tab > Advanced > Custom controls.
How in a VB web app is a conditional compilation variable assigned that can be accessed by all the files of the web app?
View 1 Replies
Mar 11, 2009
I've 2 projects- one containing GUI and another a DLL project containing some implementations. I'm using Classes in DLL in my GUI. All that I wanna do is when some results are manipulated in the DLL, the final output from DLL should be made available in the RichTextBox present in the GUI project. I tried the WithEvents and also Add Handler. But its not working.In the DLL, I added...
Public Event Report(ByVal info As String)
RaiseEvent Report("The folder has been Copied.") In the GUI, I added...
Public WithEvents Log As RTAF_DLL.CServer // RTAF_DLLis the project name.
CServer is the class // in which the event has been writtenLog = New RTAF_DLL.CServer
Protected Sub Log_Report(ByVal info As String) Handles Log.ReportMsgBox(info)
// Even this is not getting printedMe.RichTextBox2.AppendText(info)End Sub
The problem here is I'm not sure whether or not the event is getting raised. But I set a breakpoint and found that the Event is not handled.I tried including Imports System.Runtime.InteropServicesBut its not working.
View 10 Replies
Nov 22, 2010
How could I create declaration(event) to a variable control in VB .net ? [code]please i need to know how to insert this (declaration) newweb_ DocumentCompleted it's similar to WebBrowser_DocumentCompleted but it's a variable
View 5 Replies
Sep 12, 2011
How can i use a js variable in mouseOver event?Here is my code:
<script type="text/javascript">
window.String1 = <%=GetLocalResourceStringEscaped("String1")%>;
window.String2 = <%=GetLocalResourceStringEscaped("String2")%>;
[code].....
View 3 Replies
Dec 7, 2011
I have a question regarding VB.Net and Object-oriented programming.
I have a solution consisting of two projects.
One project is dedicated to the logic of the application, and one is only to show the Winforms form, and to reflect changes made in the logics project. In other words, when an array filled with various attributes residing in the logics project gets changed, then these changes should be reflected on the form (not that strange in theory).
Here comes the - for me - really tricky part:
I have created user controls, and these are residing in the forms project and placed on the aplication's form. When I click on any one of them, their respective onclick sub gets called okey, but how can I send a message to the logics project from their onclick subs? Basically, I'm not sure on what should be private or not, or possibly how to call the other project correctly. In any case, I can't get it to work.
To sum up: What I need is a line of code calling a class in another project, and someone telling me what should be private, static etc.
View 4 Replies
Apr 27, 2009
Im making a site in Visual Studio using vb and I have a variable in page_load but need its value in the event handler of a button for passing on session.
View 5 Replies
Jun 8, 2011
I'm wondering whether it is possible to declare a global variable in a click event. I need to declare an array of a specific size. The specific size is generated using a series of IF statements. I only need to know how to declare it.
View 1 Replies