473,246 Members | 1,410 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 software developers and data experts.

passing variables between forms in vb.net 2005

I have VB2005 and I need to pass intnumplayers from form1 to form2. Simply declaring the variable in a global module WILL NOT SOLVE MY PROBLEM, as I need to pass the values themselves from form1 to form2. Specifically, I have a textbox that acts to input the value for the number of players on a soccer team in form1. I did the necessary code to make sure it's a positive integer, so that code is not necessary. However, after that info (among other bits of info) is gathered, I want to use it in an array in form2, but the value is stored in the private class for the button that gathers the values from form1 (btnNext). Also, I have VB2005, and I noticed that using the code form1.intnumplayers DOES NOT WORK. How do I get the fact that there are, say, 22 players on the soccer team from btnNext in form1 to form2?
May 12 '07 #1
10 9863
Hi,


I'm not sure if this is the easiest way to do this, but you could just access the textbox data directly.

I'm assuming btnnext opens a new form, if so you could do this...

Expand|Select|Wrap|Line Numbers
  1.  [size=2][color=#0000ff]
  2. Private[/color][/size][size=2] [/size][size=2][color=#0000ff]Sub[/color][/size][size=2] Form2_Load([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] sender [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Object, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.EventArgs) [/size][size=2][color=#0000ff]Handles[/color][/size][size=2] [/size][size=2][color=#0000ff]MyBase[/color][/size][size=2].Load
  3.  
  4. TextBox1.Text = Form1.txtTop.Text
  5.  
  6. [/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]Sub
  7.  
  8. [/color][/size]
May 13 '07 #2
Okay.


Sorry first time I have used the code input, not sure what happened there but basically add

TextBox1.Text = Form1.txtTop.Text

on form load event or whatever you're text boxes are called
May 13 '07 #3
No, I used that info to determine the the size of an array. Now I need to get the values of the arrays from one button to another. I'm bailing on the two form thing. That was too much work and an awful mess. I'm keeping everything to one form using visible/hide operations, but I need to pass the info gathered from btnA to btnB. For example, stringvariableA(x) was assigned a value of "blah" in btnA via inputboxes. Now I need to transfer the values of stringvariableA(x) (which is "blah") from btnA to btnB without repopping up the inputboxes, thereby preventing the user from having to repeatedly type in the data.
May 13 '07 #4
Killer42
8,435 Expert 8TB
It's not clear what you mean about transferring values to or from a button. The button is merely an interface element used to get input from the user, in the form of a "click". Are you trying to display this info as the caption on the button?

Can you explain further?
May 14 '07 #5
No. I mean I have one button that gathers all the data and stores it in the necessary variables. I.E. when you click on the button, inputboxes pop up and ask for the values of different parts of the array. Once all the information is gathered, the information is outputted onto a listbox. Under the listbox is a new set of buttons designed to search for values and edit them, as well as print the form and close the application. However, when I tell it to search for, say, "John Doe" in the array, VB can't find a "john doe" because that was assigned to str1 in btn1, and the value of str1 is now "". I need it to stay as "John Doe". Specifically:

The form opens up with three labeled textboxes and two buttons designed to gather information regarding a hypothetical soccer team. One textbox asks for the team name, the second the number of players on the team, and the last the number of games they play. When the user types in proper values for each and clicks the button btnNext (text "Next ->"), the form hides and inputboxes appear asking for the number of goals each player scored in each game, as well as each players' name and the date of each game (that's 2 1d arrays and 1 2d array). Once all this is done, the form reappears, resized, and a listbox appears displaying the scoring information for the team with a spreadsheet look: the team's name becomes the heading, and the dates and player names assume the labels of the columns and rows, respectively, with the game scoring info filling in the "spreadsheet", as well as total scoring for each game and player and the team total for the season. Underneath the listbox are several new buttons, including one to search for a player's stats, one to search for the team's stats on a given date, one to edit the scoring/player info, one to print the form, and one to close the application.

The problem is that the arrays are stored in the private subroutine for btnNext; the private subroutine btnsearchname has none of the array's values. I realize I could cut and paste the code to each of these buttons and just simply ask for all the scoring information all over again, but that doesn't seem very user-friendly. I assume there HAS to be code to call the numerical values themselves from one subroutine to another, but I obviously don't know what it is. This is what I am asking for.
May 14 '07 #6
Killer42
8,435 Expert 8TB
Sorry, in a real rush right now.

But it sounds as though you need to define the arrays at the form level, not within the button's event procedure.
May 14 '07 #7
ok totally different project, but same problem. for some reason the project refuses to pass variables from one form to another, and this project is huge so i have to use multiple forms. once again, simply declaring the variables at the global level WILL NOT WORK. I know that you can cheat the system and do like form.control.text, but in this case that's not going to work (way too many variables, way too many forms, way too much code, and some of them are in array format).
Dec 3 '07 #8
Killer42
8,435 Expert 8TB
Ok, for starters, why don't globals fit the bill?
Dec 9 '07 #9
Killer42
8,435 Expert 8TB
Hello? Earth to captainphoenix...
Dec 12 '07 #10
QVeen72
1,445 Expert 1GB
Hi All,

This is for people who are stuck with passing control values between forms in VB.Net. Unlike VB6, we cannot access form control variables using Form1.Text1.Text.
Easy way out is keeping global variables. But if you have too many variables to pass, overhead simply increases.

In VB.net, forms are classes. You need to do a bit of work around.
Say you have Form1 as parent form and you are calling child for Form2,
and you are wanting to show some textbox values of Form1 in Form2.

In Form2 (child) add a "New" constructor. Something like this :
Expand|Select|Wrap|Line Numbers
  1. ' Declare a Form Level Variable and New Constructor
  2.     Dim ParForm As Form1
  3.     Public Sub New(ByVal myParForm As Form1)
  4.         MyBase.New()
  5.         ParForm = myParForm
  6.         InitializeComponent()
  7.     End Sub
  8.     ' In Form Load, Show the Contents of Form1
  9.     Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  10.         Me.TextBox1.Text = ParForm.TextBox1.Text
  11.         Me.TextBox2.Text = ParForm.TextBox2.Text
  12.         Me.TextBox3.Text = ParForm.TextBox3.Text
  13.         Me.TextBox4.Text = ParForm.TextBox4.Text
  14.         Me.PictureBox1.Image = ParForm.PictureBox1.Image
  15.     End Sub
  16.  
And in parent form (Form1), to show child Form2 :

Expand|Select|Wrap|Line Numbers
  1.     Dim TForm As New Form2(Me)
  2.     TForm.Show()
  3.  
Hope it helps.

Regards
Veena
Dec 12 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jason Us | last post by:
Does anyone have experience with passing variables from an ASP page to a JSP page. The way it currently works in passing the SSN in the URL. This cannot be good. I thought that storing a...
2
by: Richard | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** HI, I am working on a project where I need to input data to a (local) HTML page using multiple form elements, such as text,...
5
by: Jack | last post by:
Hi, I need to pass multple variables in a link in order to go to a asp page with the two varables. The following are the values of the variables using response.write: <%'Response.Write Mypage...
9
by: Max | last post by:
I'm new with Javascript and can't seem to figure out what I'm doing wrong here as I'm not able to pass a simple variable to a function. In the head of doc I have: <script...
5
by: Ross A. Finlayson | last post by:
Hi, I'm scratching together an Access database. The development box is Office 95, the deployment box Office 2003. So anyways I am griping about forms and global variables. Say for example...
39
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down...
2
by: Michael C | last post by:
What's the best wat to pass data between two separate forms. For instance, Form1 invokes Form2 like this: Form z = new Form2(); z.Show(); How can I pass back strings and boolean values from...
8
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
6
by: Scott Zabolotzky | last post by:
I'm trying to pass a custom object back and forth between forms. This custom object is pulled into the app using an external reference to an assembly DLL that was given to me by a co-worker. A...
7
by: The Doctor | last post by:
A rather elementary question, In VB5, how can I pass a variable from one form to another?
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.