473,387 Members | 1,569 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,387 software developers and data experts.

How to pass variable between forms?

hi,

The MainForm will have 2 buttons:
1.) Button A :
User click button A, hide Mainform then go to form1. User enter data in the textbox.Click finish button,form1 close then go back to MainForm.

2.) Button B :
User Click Button B,hide Mainform then go to form2. Click a button & some mathematical operations will be done using all parameters that have been entered in form1.

My method of passing variable is:
* Before Finish button is click, Form1 pass variables to Mainform
* a function created in MainForm to receive variables
* Click button B, Mainform pass variables to form2
* a function created in Form2 to receive.


My problem now is the Mainform doesnt received any value from form1.Here's my code:

Expand|Select|Wrap|Line Numbers
  1. FORM 1 FINISH BUTTON CODE
  2. def FINISH(self, sender, e):
  3. #----Passing Variable to MainForm----
  4.    MainForm._a = int(self._txtbox1.Text)
  5.    MainForm._b = int(self._txtbox2.Text)
  6.    MainForm._c = int(self._txtbox3.Text)
  7.    MainForm._d = int(self._txtbox4.Text)
  8.    MainForm._e = float(self._txtbox5.Text)
  9.    self.close() #CLOSE FORM1
  10.  
  11. FUNCTION TO RECEIVE VARIABLE in MAINFORM
  12. #--Receive variable from Form1----
  13. def variables(self):
  14.    self._a = 0
  15.    self._b = 0
  16.    self._c  = 0
  17.    self._d = 0
  18.    self._e = 0
  19.  
  20.  
  21. BUTTON B
  22. #----Passing Variable to FORM2----
  23. def Model(self, sender, e):
  24.    self.Hide()  #hide MainForm
  25.    form2 = Form2.Form2()
  26.  
  27.    ##-----Pass Variable to Form 2
  28.    Form2._a  = self._a
  29.    Form2._b  = self._b
  30.    Form2._c  = self._c
  31.    Form2._d  = self._d
  32.    Form2._e  = self._e
  33.  
  34.    form2.ShowDialog()
  35.    self.Show()
  36.  
  37. FUNCTION TO RECEIVE VARIABLE in FORM2
  38. def variables(self):
  39.         self._a = 0
  40.         self._b = 0
  41.         self._c  = 0
  42.         self._d = 0
  43.          self._e= 0
  44.  
help! Can anyone spot my mistake?
Sep 9 '10 #1
2 2860
bvdet
2,851 Expert Mod 2GB
Without seeing all the code, I can only speculate.

What GUI are you using?

Are you using control variables? In Tkinter, that would be either DoubleVar(), IntVar(), BooleanVar() or StringVar(). The values would be set and retrieved with the control variable methods set() and get().
Expand|Select|Wrap|Line Numbers
  1. self.var1 = Tkinter.StringVar()
  2. self.var1.set("some_value")
  3. self._a = self.another_var.get()
Are you encapsulating the main form and the sub forms in one application?
Sep 9 '10 #2
im using SharpDevelop to create my GUI.
Sep 10 '10 #3

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

Similar topics

2
by: jongyoo | last post by:
Hey guys, I was doing some mysql database stuff and I wanted to have a pop up window with some other forms on it. The problem I'm having is that I have no clue how to pass a variable for PHP to...
5
by: GB | last post by:
Hello: In my MS Access project I have two objects - my form and my report. I need to pass variable value from Command_click procedure of my form to Report_open procedure of my report. How can I...
1
by: Ben Kial | last post by:
I'd like to write a wrapper function "mysprintf(char *buffer, char *format, ....)" which calls sprintf(). My question is how can I pass variable argument in mysprintf() to sprintf(). Thanks in...
8
by: darrel | last post by:
I'm still trying to fully understand how best to pass variables between pages/usercontrols/each other. On a current site I've done, I've had one userControl do the logic and set the variable,...
1
by: dollar | last post by:
I want to ask what is the best way to pass variable between asp.net we pages, and user controls , any examples - dolla -----------------------------------------------------------------------...
4
by: Ronald S. Cook | last post by:
I have a form open and when a user clicks a button I do a frmNew.Show() and this.Hide. But I have a value that I need to pass to the new form. How can I do this, please? Thanks very much, Ron
1
by: drec | last post by:
I need to pass a variable from script1.php to script2.php. The problem is that these scripts use frames and therefore I am able to pass the variable through the URL. It also does not use forms to...
1
by: vijaynarang | last post by:
strCmdLine = " " + " -o restore -url " + sSitePath + "/sites/" + sToplevelSiteName + " -filename " + sFileName+ " -overwrite "; process1 =...
8
by: Dan Verssen | last post by:
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...
12
by: simon2x1 | last post by:
i have a page which is home.php on that page i have a CSS tab which is tab1 and tab2 on that page in both tabs i have a link called next that pass variable to the next page (<a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
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 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.