VS 2010 - Public Variables, Functions Are Not Visible In Form2

Jun 26, 2011

I've got a program that runs from one Windows form, Form1, with stuff declared all in that class: public variables, public functions, subs, etc. I decided that the form was getting cluttered, so I added one button to bring up a new form, Form2, and I put some of the buttons & check boxes for testing over there, so that Form1 can be more visually clean. Problem: when I go to put the code for the tests into the buttons on Form2, none of the public variables or subs or functions that reside in Form1 are visible in Form2. What statement/s do I need to add (and where) so that the public "stuff" that's declared in the class for Form1 is visible within Form2, please?

View 6 Replies


ADVERTISEMENT

Declare Public Variables, Constants, Functions In A Proper Way?

Jan 13, 2011

I'd like to get a more refined programming style and I was wondering if any of you might give me a hand...(How to declare public variables, constants, functions...in a proper way),is there any useful link or pdf document I could have a look in order to improve my style?

View 5 Replies

Difference Between A Private, Public, Shared Functions/Sub/Variables?

Jul 22, 2009

give me a good resource that explains the difference between a Private, Public, Shared Functions/Sub/Variables? I normally use Public for Subs/Functions inside of Modules I call from other parts of the program. But I'd like to get more of an understanding of how and when to use them. I want as little as impact to a system that is running my programs as possible, so i guess the key here is I'm trying to just get more proficient in my coding.

View 8 Replies

VS 2010 Public Variables For All Classes?

Mar 30, 2011

I have a MDI application and a very complicated class there which populates its properties from a dataset derived from an external database. Each form, including child forms have to be able to access that class and use its properties thorughout the whole session.I don't know where to 'preserve' these property values within the application. I kmow many books etc. suggest not to use public variables but I really can't find a way to solve this other than to use a public variable (which is a list(of my custom class) in this case.
I have a separate class called PublicItems.vb and declared there my public variable as

Public Shared secuniverse As List(Of myCustomClass)Is there something wrong with the syntax because if I try to use the variable secuniverse in my main application class, I get the following exception:'sectoruniverse' is not declared. It may be inaccessible due to its protection level.

View 7 Replies

DataSet On Form1 Not Visible On Form2?

Jan 6, 2010

Using VS2008 I created a dataset in the designer and created a table with one column in the dataset. I pulled this table to create a DGV on Form1 and my column appeared (DS & BS were created on the form as well). It is on Form1 that I would like to initially populate the DT. (The DS is internal and does not have a connection string) On Form2 I would like to create a DGV and use the BS on Form1 as the data source. This is not visible, however, from Form2. I can set the data source programatically but then the column is not visible on Form2 until run time and I would like to make my formatting changes on Form2 using the designer. I tried making the DS and BS on Form1 both public but they still are not visible as a data source on the Form2 DGV.Is there a way to make a data source on a form visible to other forms in the project using the designer?

View 3 Replies

Using Variables From Form1.vb To Form2.vb?

Apr 29, 2010

I have an equation on Form1.vb that calculates a number. I need that number to be used in another separate formula that's on Form2.vb. How do I do this? I thought using a Module would work but I can't get the function on the Module to "see" the formula and/or variables that I need on Form1.vb. I am using VB 2005.

View 8 Replies

Possible To Copy Form2 Three Times On Form1 With Different Variables In Text Boxes?

Oct 18, 2009

I recently bought a barcode scanner for God knows what reason, just to play around and now it seems that its easy to sort out everything at house with it (e.g. Disc Collection). So I decided that I need a special program for it to get sorted with the collection. I am new to Visual Basic, but used to do programs with Java 6 years ago, but it doesn't seem to be any similar to each other. Basically I have a Microsoft Visual Basic 2008 and here is what I want to do:I have Form1 which contains of a textbox and a button (which will be Enter further), a textbox for total amount spent (which has to be calculated from Form2 and a nice background. I also have a Form2 in the same project, which contains 3 textboxes (Title, Price and the barcode numbers)So my problems are: As I said there are just 3 textboxes in Form2. Is it possible to copy Form2 three times on Form1 with different variables in text boxes? For example Form2 1st copy will have one Title in textbox, Form2 2nd copy will have another Title in textbox and etc. The Titles are in excel (.xls) file.That is a problem further, but my problem for now is how to make barcode scanner working. The barcode scanner basically reads barcode and inputs numbers in a textfield and automatically presses enter.As I am new, I do not know how to make this work. When I launch the program the textbox has to be selected rightaway, so that I do not have to use mouse. As it is selected I read the barcode and the numbers are in the textbox right away and Enter key is pressed (but I did not assign OK button with a Enter key and I cannot output anything now). So how do I assign the button with Enter key and the textbox? Now as the button is pressed (OR ENTER KEY is pressed) The text in the textbox has to be selected again (so that I can input a new barcode) and Form2 has to be called on a certain place of the screen (e.g. 200x100px is the starting location).

Now when the Form2 was called it read the data from Excel spreadsheet and now the textfield in Form1 is ready to input new barcode. As new barcode was read the same situation is happening, but now the Form2 is copied into a new place with new parameters (e.g. 300x100px is the starting point).Same for the third time, but on 400x100px.For the fourth time the Form2 is not copied again. However the parameters of the third copy are getting the new data. Parameters of the third one are going to the second copy, second copy to the first one and the first one is stored in a text file or somewhere else to use further. (I wanted to use up and down buttons to search for what I have scanned)

View 2 Replies

Make Do Public Sub/functions While Accessing Excel?

May 27, 2009

I was thinking about writing some VB 2005 code that would be able to open an excel file and keep it open while I do things in separate functions/subs basically just check boxes, so each check box is its own sub but HOW do I do that with out opening and closing the excel file for every check box sub, since every time I make a check box the sub comes up as private?

View 9 Replies

Public Shared SqlConnection - Used In Multiple Functions

Jan 29, 2010

I have an asp.net web app. It has a shared class, and I want to have the connection string the same through out the site. My string is in my web config, but I don't want to type this all over the place:

View 3 Replies

Pass Data Between Subroutines And Functions Using Public Classes?

Oct 31, 2009

I would like an overview of System.EventArgs. I have an understanding of System.Object where I can pass data between subroutines and functions using Public Classes. I am curious what EventArgs do?

View 3 Replies

Take Some Existing Classes We Retrieve From A Web Service And Hiding Public Functions?

Nov 18, 2009

[code]...

EDIT: The above class is just an example of what could be returned from a web service. I won't have access to modify it at all, sorry if I didn't make that clear.Is it possible to somehow make a clone this class, so that it retains all of the properties values, but hides the fact that there is a Public function?I'd like to be able to take some existing classes we retrieve from a web service(which we didn't write) and be able to pass them on for use in an application, but without exposing the functions. I don't want to go down the route of creating my own classes that specifically define each property and write the values in (due to the sheer size of some of them), so I'm looking to see if there is anything dynamic I can utilise (maybe there is a way using reflection?).

View 4 Replies

Forms :: Random Functions - When Start Program And Click Picturebox - Same Card Will Always Come Visible

Mar 30, 2011

Okay, so I'm doing a card game and I'm trying to set that when picturebox (PictureBox1) is clicked, a random card from 13 cards will come visible. Problem is, that when i start the program and click the picturebox, the same card will always come visible. As you can see i've put a button (Button1) which will hide every card. If I press Button2, then Button1 and then the PictureBox1 it will show differend card, but the cards which come visible are always the same.

e.g i press PictureBox1 (which will make card visible), then Button1 (which will make PictureBox1 non-enabled) and then Button2 (which will hide every card and make PictureBox1 pressable). Lets say i pressed the PictureBox1 four times and i got cards: 9, 6, 7, 3, then I close the program, start it again and press PictureBox1 again 4 times and it will show the same cards (9, 6, 7, 3). How can this be done that it will not show the same cards always?

Here's my code...
Public Class Form1

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
End

[CODE]....

View 3 Replies

Declaring The Public Variables?

Sep 23, 2011

I've created a 30 point wizard. Every step gathers between 1 and 3 variables. I've created a module and publicly declared the variables there. At the end of the wizard, one master form opens, gets all the variables, and displays them on one form. At this point calculations are run too which populates more variables. This works fine for one instance of the process.

the user may want to be running two instances of the wizard at once. Obviously, if the previous wizard is part complete and they start a new one, the variables are going to get crossed or replaced by the new wizard.Is there a way for the variables to be declared publicly but used in multiple instances?

View 8 Replies

Public Variables Not Available In Module

Jan 17, 2011

I have a variable declared at Public on a form. But when I try to access it in a module I get an error that its not declared.

[code]...

View 15 Replies

VS 2008 - Difference Between Public, Private, Protected When Declaring Functions And Subs?

Jul 19, 2009

i have have a few questions about the syntax of the lan.:

1) What is the 'Get' statement and when do you use it?

2) Whats the difference between public, private, protected etc... when declaring functions and subs.

3) When would you use the overrides property?

View 4 Replies

[2005] SyncLock And Multithreading - Public Class Utilities With A Many Shared Functions

Feb 11, 2009

I am trying to get a handle on SyncLock and multithreading, but I am having some trouble wrapping my head around exactly how it should be implemented. I have a Public Class Utilities with a many Shared Functions. I want to make sure that each function can only be executed when there are no other concurrent calls to the same function. So If I have 2 functions, A and B in a Public Class Utilities, what is the syntax so that a function "locks" while it is being executed, preventing any subsequent calls until the "locking" thread has completed?

CODE

Public Class Utilities

Public Shared Function A (ByRef i As Integer) As Integer

[CODE].............................

I know I need to wrap the statements of execution in a SyncLock block, but I am unsure of the scope of the parameter used with SyncLock...is it private to the function, class, etc? Can the same object be used to lock both functions if they are independent?

View 36 Replies

Global Variables And Functions

Mar 24, 2010

how can i create global variables and functions within a visual basic project?

View 6 Replies

Cant Access Public Variables From Another Form?

Aug 25, 2010

I have a string on my main form called String1. When I open another form, I need access to this value. In the form I open, I have always done something like:Dim NewString as String = Main.String1

This has worked in the past. Well, I ended up renaming my forms (from Form1 to Main) in the property window and it now when I type the above code, it does not list Main as a form. Nothing that I renamed seems to exist now.

View 2 Replies

Declaring Public Variables New Hashtable

Dec 8, 2009

recently started converting our project from 1.1 to 2.0

It was fine with the following:

Public ghtAllAppMsgs As New Hashtable(300)

Now it is complaining to change to the following is this the right way:

Public ghtAllAppMsgs As New System.Collections.Hashtable(300)

This is under global.vb class file: here are the imports i already had in this file:

Imports Microsoft.Web.UI.WebControls
Imports Microsoft.Web.UI.WebControls.MultiPage
Imports System.Web

[Code]......

View 1 Replies

Dynamically Concatenate Public Variables?

Mar 10, 2012

This seems basic but here's my problem. I am trying to build my connect string as a public variable that will connect to either an express version of SQL Server or a non-express version. The app.config defines it as being express or not and is modified to the user's choosing when it is deployed using the a firstRun routine.

The problem is that even though I'm modifying the value of the variable SQLexpress when the app is initiated which in turn should modify the value of the variable g_strConnectionString it doesn't. The value of g_strConnectionString will always take on the initial value of SQLexpress. I know I can define 2 separate variables for the connection string but I'd prefer not to have to change all of the references throughout each of the various programs in this system as they all have the same issue.

So in the following load event I've traced it and when it sets globals.SQLexpress = "", I then look at the value of g_strConnectionString and it still contains "SQLEXPRESS". It seems I need to somehow force vb to refresh this variable after it's been changed.

[Code]...

View 5 Replies

Private / Public - Subtracting Variables

Mar 11, 2010

I am a little new to .NET Developing, and have learned a great deal recently, but I'm stuck with something. I come from an ASP Background, I'm trying to subtract 2 variables, but they don't seem to 'see' one another.

[Code]...

View 6 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 From A Public Shared Subroutine?

Feb 15, 2009

I have created a public shared subroutine in a class file in asp.net 2 (vb.net) web site app_folder.The subroutine retrives some values from a sql database via an sql query and assigns the datareader field values to several variables The problem is I can't seem to assign the variables from the subroutine to the variables and textbox controls in the asp.net page I am calling the subroutine from. The textbox text value just appear blank.By the way, if I response.write the variables in the subroutine they appear populated by the sql data reader.

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

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

Public Variables - Copying / Pasting Some Lines From Another One

Jan 2, 2012

I'm writing a new app and copying/pasting some lines from another one. In the new app, I get error when I use variables defined as public.

[Code]....

View 1 Replies

Declare Some Global Variables For Use In Various Subs/functions?

Oct 21, 2011

At the head of a module, I wish to declare some global variables for use in various subs/functions.

What is the difference between.Dim x as string and Private x as string / Public x as string, and when would I use one over the other?

View 1 Replies

Lifespan And Scope Of Shared Variables And Functions?

Jul 31, 2010

Are the following three the same upon compilation

dim x as new assigningfunction
dim x as new assigningfunction()
dim x as assigningfunction = new assigningfunction()

[code].....

View 4 Replies

VS 2005 Global Functions And Variables Within Solution?

Jun 23, 2009

I have a solution with 5 visual basic projects in it. Each project has an identical module with a few functions and constants - like handling our RS232 data, outputting events to log files, etc, etc..

If I want to change any of this common code, then I have to manually go through and change in each project. Is there a way to have a single module or class that's shared throughout the projects in the entire solution? I've considered creating and referencing a class library, but I'm likely to be making several little tweaks and changes to this "global code" and that method sounds like it could be just as awkward. Can I not just have a module that's visible to all projects, and compiled into each one seperately when the solution is built?

View 3 Replies

Copying A Set Of Private Variables Into Corresponding Public ReadOnly Properties?

Oct 18, 2011

I have a bunch of private variables I've typed out and I want to put all of my corresponding Public ReadOnly Properties in a bunch below them.Is there some way of copying ten lines of

Private _myVar As String

and pasting in ten sets of

Public Readonly Property MyVar As String
Get
Return _myVar[code]....

I'm currently copying the whole bunch of variable declarations, Find+Replacing Private _ into Public ReadOnly Property then going line-by-line expanding the definitions and writing return statements.how to avoid all this nonsense in the future, as I'm developing on a virtual terminal server, and the input lag on my little copy/paste/type operations on the code is driving me up the wall.

View 1 Replies







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