I have 2 forms that I need to go back and forth on a regular basis.
I am using Hide/Show to only display one form at a time.
If Form1 puts a value in a variable, then I Hide Form1 and Show Form2, how can I move the value to Form2 so Form2 can display and change it?
Basically, how do I define a sub that runs each time its Form is Shown?
8 6080 - Public Class Form1
-
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
-
Dim form As New Form2
-
form.Show()
-
Me.Label1.Text = form.Label1.Text
-
End Sub
-
End Class
-
-
Public Class Form2
-
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
-
Dim form As New Form1
-
form.Show()
-
Me.Label1.Text = form.Label1.Text
-
End Sub
-
End Class
The forms keep the values of the variables, accessing them is therefore easy. Put 2 forms in a project and paste the code behind each form. You should be able to see what happens to the variables. Note that the forms are not destroyed so that you can create many instances of the forms.
Good luck.
Thank you! I will give this a try.
Is there a way to pass the information without the need of a button click or other user action?
For example, on Form1 the variable: username="Dan". When I Show Form2, how can I have a label's text show the value of the username variable ("Dan")?
Thank you! I will give this a try.
Is there a way to pass the information without the need of a button click or other user action?
For example, on Form1 the variable: username="Dan". When I Show Form2, how can I have a label's text show the value of the username variable ("Dan")?
use a variable in a module and make a function to call and a sub to write.
e.g.: - '(in a module)
-
option explicit
-
dim Str1 as string
-
-
sub WriteFn(wStr1 as string)
-
str1 = wstr1
-
end sub
-
-
public function ReadFn() as string
-
readfn = str1
-
end function
-
-
'(in Form1)
-
sub command1_click()
-
call writefn(textbox1.text)
-
end sub
-
-
'(in Form2)
-
sub form2_load() 'or initialize, or watever
-
label1.caption = readfn
-
end sub
HTH
I like the idea of writing it to a file.
From what I've seen, the Load contents are only executed the first time a Form is Shown. If I bounce back and forth between Forms, the Load contents do not get executed each time the Form is Shown.
Is there a simple way to have a section of code run each time a Form is shown that does not involve a user action?
I like the idea of writing it to a file.
From what I've seen, the Load contents are only executed the first time a Form is Shown. If I bounce back and forth between Forms, the Load contents do not get executed each time the Form is Shown.
Is there a simple way to have a section of code run each time a Form is shown that does not involve a user action?
use the Load, or the Initialize sub in the form, that actions are done when the sub is initialized or loaded. (it vary with the version of vb, but you should be able to find which sub fits you)
The problem I've had with "Load" is it only gets performed the first time the Form is Shown. Each time I re-Show the Form, it isn't performed.
Does Initialize get performed every time a Form is Shown?
I'm a little confused. I would have thought that running code everytime a Form is Shown would be a casual everyday thing to do.
Yet, everything involved with this seems to be a major hassle.
Any ideas?
Got It!
I called a friend who is a programmer.
To get code to run each time a Form is Shown, put it inside its "Activate" event.
Many thanks to everyone who replied!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Casey |
last post by:
Yeah, I know this question was asked by someone elselike 2 weeks ago. But I
need some additional help. I have a program I'm developing, and multiple
different forms will be opened. For now though,...
|
by: Zlatko Matić |
last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL
Server) and that we want to execute some parameterized query as a
pass.through query. How can we pass parameters to the...
|
by: Brian F |
last post by:
Exactly what the subject says.
I have an ASP page that I want my C# windows application to open in
Internet Explorer, and if possible have it send along a list of values
from a list box. Thank you.
|
by: Hermit Dave |
last post by:
Hi,
Trying to pass a value to user control within a page.
1. Couldnt find a way to pass it from code behind file.
2. Trying to pass it from aspx page... using EditURL='<%
"mypage.aspx?myvar=" +...
|
by: prabodhtiwari |
last post by:
function submitPartsForm(str) {
var count=document.getElementsByName("partId");
for(var i=0;i<count.length;i++)
{
document.mylist.myNum.value= document.getElementsByName("partNum")...
|
by: Atli |
last post by:
Introduction
At some point, all web developers will need to collect data from their users. In a dynamic web page, everything revolves around the users input, so knowing how to ask for and collect...
|
by: Robert Dailey |
last post by:
Hi,
I noticed in Python all function parameters seem to be passed by
reference. This means that when I modify the value of a variable of a
function, the value of the variable externally from the...
|
by: =?Utf-8?B?Umljaw==?= |
last post by:
I have seen examples of passing data from FormB to FormA (Parent To Child)
but I need an example of passind data from FormA to FormB. My main form is
FormA; I will enter some data in textboxes and...
|
by: magickarle |
last post by:
Hi, I got a pass-through query (that takes about 15 mins to process)
I would like to integrate variables to it.
IE: something simple:
Select EmplID from empl_Lst
where empl_lst.timestamp between...
|
by: raylopez99 |
last post by:
Keywords: scope resolution, passing classes between parent and child
forms, parameter constructor method, normal constructor, default
constructor, forward reference, sharing classes between forms....
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |