Variable Scope When Using Forms VB2008?

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


ADVERTISEMENT

Variable Scope Error/

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

Variable Scope Outside A Class?

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

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

Public Variable Goe Out Of Scope In Private Sub?

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

Variable Scope And Event Timer

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

VS 2010 Variable Scope In Nested Classes?

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

Variable 'line' Of Type 'SomeTable' Referenced From Scope' / But It Is Not Defined

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

Serialport VB2008.net - Input Variable And Output Variable Of This Terminal?

May 14, 2010

I am using vb2008.net express,I test vs2005term it work, can any tell me what is the input variable and output variable of this terminal?how to catch the input and output variable to a textbox1 for sending and a textbox2 for receiving when I press send button? is that possible?

View 1 Replies

Error The Type For Variable 'Index' Will Not Be Inferred Because It Is Bound To A Field In An Enclosing Scope

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

Warning5 The Type For Variable 'FolderObj' Will Not Be Inferred Because It Is Bound To A Field In An Enclosing Scope

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

Error: A Local Variable Named 'arow' Cannot Be Declared In This Scope Because It Would Give A Different Meaning To 'arrow'

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

Pass A Variable To Another Form Or Else Make The Variable Visible To Both Forms?

Sep 5, 2010

Using Visual Basic 2008 Express. I need to pass a variable to another form. Or else make the variable visible to both forms.

View 4 Replies

Access Forms From VB2008?

Dec 22, 2009

I have programmed in VB before (vbexpress 2008) and used "formname.show()" to open and show new forms that I wished to open. I try the exact same code in vb10express(beta) and get errors! Did the code change? I cannot find any information on it if it did... or is it possibly a "betatest error" that needs to be addressed?

View 3 Replies

Date Fields On Windows Forms VB2008?

Feb 23, 2009

I've got a data entry form with 3 date fields which can be null.When I open up the form the fields display as today's date when the value is null.I want to be able to display to the user that the value is null and not some spurious or misleading value.Any ideas on how I can do this?

View 3 Replies

Forms :: Load A Second Form In Vb2008 Express?

May 6, 2010

I have a perhaps simple problem but cannot deal with it.What would be the code for loading another form.let me explain in more details.im writing a very simple game for my project and want to load another form when "level" on my first form finishes

[Code]...

View 1 Replies

[VB2008] Create & Initialize Data Structures So That They Are Seen By All Forms?

Mar 11, 2010

what the results I need in a Windows Form Application.

Requirement:
(1) I need to create class objects with all various methods and properties, etc.

(2) I will create only one instance of the each class

(3) I need to be able to call the methods and properties of the created class objects (1) from any form I create.

(4) I use the class objects to store data so that separate threads can access them..

Question: how I would code this into a WFA? (I have console application code that works but need to convert it into a GUI).

[Code]....

View 5 Replies

Forms :: Can Make Variable Actually Seen As A Variable?

Feb 17, 2011

I have a VBA form in Microstation I am using to try and help automate a task. The only problem I am having is I am reading a textbox (Filebox.Text) and setting it as the variable (FN). It works, because I used Msg.Box (FN) to test it. However, in two of the lines of code, I am trying to use (FN) to pass the typed in filename to the command to run in Microstation. Unfortunently, it gets passed on as (FN).dgn instead of the actual filenale typed into the textbox. Is there a way I can make the variable actually seen as a variable? Code on Pastebin: url....Also, not sure if this is the right section, 100% new to VBA, coming from a world Bashed together.

View 3 Replies

Forms :: Wonky Variable Passing In Forms

Apr 22, 2010

This is my first Windows app to create since VB6. I've been in the world of ASP and ASP.NET for many years. However, now I have been asked to create a simple app that needs to be windows based.

[Code]...

View 4 Replies

Convert A VB2008 Console Application To Windows Forms Application

Feb 7, 2010

I have a fully functional multi-threaded VB2008 console application that I need to convert to a windows forms application. I am doing this to add additional functionality at a later time. How would I go about doing this?

View 9 Replies

How To Use A Variable Between Forms

Oct 23, 2009

I have two windows forms in my application, and I want to have variables that work between them. How would I do this?

View 2 Replies

Use The Same Variable On Different Forms?

Oct 28, 2009

I want to calculate the score on one form and display the score on another form

View 7 Replies

CanNot Pass Variable Between Forms?

Sep 11, 2009

i have a dialogbox (dialog1) i will assign the input from textbox a variable to the from1 but i cant do that.the variable in form1 is Dim get_from_dbox As Long i try to assign to it from dialog1 like below it fails form1.get_from_dbox = Textbox1.Text but i can assign to textbox??like that which works well

form1.RichTextBox1.Text=Textbox1.Text I am new programing i know i am wrong .don't know where?

View 1 Replies

Forms :: Display Variable In Msg Box?

Sep 20, 2010

I am struggling to find out how to use a msg box to display the value of a variable.

I've tried a number of permutations, and searched for hours to find a tip.

My code is currently:

Private Sub btnShowTotalCost_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowTotalCost.Click
If (radCorpTravel.Checked) Then

[Code].....

View 10 Replies

Passing Variable Between 2 Forms?

Jun 15, 2010

i have 2 forms -> form 1 and form 2

in form 1 -> 1 button
in form 2 -> 1 textbox and 1 button

when I click button in form 1, it will show the form 2..how can i pass the variable (data from textbox in form 2) into a variable in form 1 after clicking the button in form 2 ?

View 8 Replies

Sharing Variable Value Between Forms

Jul 31, 2009

When I declare a variable as public, shouldn't it be available in another form? I am trying to write a windows mobile prg with 12 static mileage points, form1 has the 12 buttons for start point, but when I call form2 with the destination points, my start variable value is not carried over. I intend to then assign a mileage based on the two points and write to file on mobile device. We support 12 schools, and I want my employees to track mileage easily.

Public Class main
Public start As String = "start"
Public dest As String = "dest"
Public miles As Decimal = 0
[Code] .....

View 4 Replies

Using A Variable Between Multiple Forms

Apr 20, 2009

I want to create a variable to be used by multiple forms, so I created a module that looks like this:[code]I expected the title of that specific form to be "(Name)'s Settings"But instead, it just says "'s Settings," as if the variable had never been assigned a value.

View 4 Replies

Variable Readable From All Forms?

Feb 7, 2010

Variable readable from all forms?

View 14 Replies

VS 2008 Variable Could Be Used Across All Forms?

Jun 26, 2010

In my previous knowledge of programming, i used to use global.variable = true how could i achieve this so the variable could be used across all forms?

View 1 Replies

Forms :: Can't Pass Variable From One Form To Another?

Jun 8, 2011

I have one form, which the user enters upto 5 websites then clicks go - I have on the second form, the one with the webbrowser. A timer which checks if the web browser is busy then either a green light or black image will be shown along side the assocaited input box on the first form.I am finding it impossible to feed variables into the clock through ByVal, like I would a subroutine or function.

Private Sub ActiveMe_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ActiveMe.Tick
If ((WebBrowser1.IsBusy)) Then
Hey.BackColor = Color.Black[code]....

'Error message says Hey is not declared, as i can't pass it through to timer

The variable Hey is determined by the first form - Which picturebox.I have an if statement which simply says if inputbox one has url enter then Hey = Picturebox1, If input box2 has url entered then Hey= Picturebox2 etc.What I want is the timer to check the page has completed loading or is still loading or refresing and the appropriate green or black to be shown aside url input box on first form.I considered using a sub or procedure to act as a clock (a large for loop with another for loop within it, acting as a delay). But found this slowed down theapp to the point of crashing it.

View 1 Replies







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