Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 11th, 2007, 3:22 PM   #1
randum77
Programmer
 
randum77's Avatar
 
Join Date: Jun 2006
Location: Fayettehell, NC
Posts: 56
Rep Power: 3 randum77 is on a distinguished road
Passing variable from one form to another

I've not been around in a while, but i've not had time to work on programming in a couple months. Anyhow, i'm wondering how i would go about passing variables between forms. I want to use them to control what appears on another form, rather then reformation one form everytime a button is clicked.

I searched through the MSDN and I've come up dry. Do i need to store the variable in a function or something of that sort? Thanks in advance.

_marshall_
__________________
_Marshall_

"America has bred a society that is innocent and incapable of accepting responsibility, but yet, is able to place blame on others without guilt."
randum77 is offline   Reply With Quote
Old Apr 11th, 2007, 3:37 PM   #2
randum77
Programmer
 
randum77's Avatar
 
Join Date: Jun 2006
Location: Fayettehell, NC
Posts: 56
Rep Power: 3 randum77 is on a distinguished road
Excuse me, I meant to say class. Do I need to store the variable I want available in all the forms in a class of some sort?
__________________
_Marshall_

"America has bred a society that is innocent and incapable of accepting responsibility, but yet, is able to place blame on others without guilt."
randum77 is offline   Reply With Quote
Old Apr 12th, 2007, 9:47 AM   #3
melbolt
Hobbyist Programmer
 
melbolt's Avatar
 
Join Date: Feb 2005
Location: PA, USA
Posts: 233
Rep Power: 4 melbolt is on a distinguished road
Send a message via AIM to melbolt Send a message via Yahoo to melbolt
Hi Marshall (btw, that's my first name as well)

There are a couple of ways you can go about exchanging the data between forms(or rather classes).

The first way, which it appears you know about already, is by instantiating or creating one form from within the other so you have a reference to this class in which you can access its public variables or properties. What I mean by this is you dim the new form within the initial form, this new form contains public variables or properties which you can then get at using classinstancename.variablename

I assume you already know about this way from reading your first post but it sounds like you want to have the ability to update the 2nd form automatically each time the data on the initial form changes?

If it were me, here is the approach I would take. you can use events to pass the data between forms automatically when something happens. so, for example, if the user clicks the save button on form1, the data in the textbox on form1 can automatically be sent to form2 when this happens using this technique.

So what you need to do is raise the event on the first form and catch it on the second form and in the event handler on the second form you can go get the data from the property or public variable.

alternatively you could put the data in the event args being sent with the event.


here is a look at an example I found online:
http://www.devcity.net/Articles/102/multipleforms3.aspx

If you have questions about what is going on here, feel free to post again.

good luck.
__________________
I have never let my schooling interfere with my education. -Mark Twain-

Xbox live gamertag: melbolt
melbolt is offline   Reply With Quote
Old Apr 12th, 2007, 2:44 PM   #4
randum77
Programmer
 
randum77's Avatar
 
Join Date: Jun 2006
Location: Fayettehell, NC
Posts: 56
Rep Power: 3 randum77 is on a distinguished road
Melbot, I appreciate the reply. I'll take some time to understand what's going on so I can ask some questions if I get confused. The example link looks like it will do what I want, I just may modify it. I've been looking at some of the code i wrote a couple months back and it's coming back to me.

_marshall_ (a great name!)
__________________
_Marshall_

"America has bred a society that is innocent and incapable of accepting responsibility, but yet, is able to place blame on others without guilt."
randum77 is offline   Reply With Quote
Old Apr 16th, 2007, 2:55 PM   #5
randum77
Programmer
 
randum77's Avatar
 
Join Date: Jun 2006
Location: Fayettehell, NC
Posts: 56
Rep Power: 3 randum77 is on a distinguished road
More questions

Ok, I understand what's going w/ the previous link. It's working more on the theory of having Frm1 and Frm2. When you type in Frm2 it updates the info in labels on Frm1. What I am doing is when you hit a button on Frm1, it opens Frm2 w some variable from Frm dictating how Frm2 should look.

What I've done is push the variable into the class i have built. I then try and access that class on Frm2 when it loads to decide how the screen should look. And it's not working. I'm sure it's something simple. I probably have 2 different instances of the class alive with 2 different sets of variables.

Based on the link you gave me, I should be able to figure it out, so I am going to blow some time working on that. In the mean time, any info?

_marshall_
__________________
_Marshall_

"America has bred a society that is innocent and incapable of accepting responsibility, but yet, is able to place blame on others without guilt."
randum77 is offline   Reply With Quote
Old Apr 16th, 2007, 3:44 PM   #6
randum77
Programmer
 
randum77's Avatar
 
Join Date: Jun 2006
Location: Fayettehell, NC
Posts: 56
Rep Power: 3 randum77 is on a distinguished road
Ok, I got it all working the way I wanted. I appreciate the help Melbolt. I just setup all the event sequences in Frm1 and forced the changes to Frm2 from Frm1 based on variables.
__________________
_Marshall_

"America has bred a society that is innocent and incapable of accepting responsibility, but yet, is able to place blame on others without guilt."
randum77 is offline   Reply With Quote
Old Apr 16th, 2007, 5:42 PM   #7
melbolt
Hobbyist Programmer
 
melbolt's Avatar
 
Join Date: Feb 2005
Location: PA, USA
Posts: 233
Rep Power: 4 melbolt is on a distinguished road
Send a message via AIM to melbolt Send a message via Yahoo to melbolt
congrats
__________________
I have never let my schooling interfere with my education. -Mark Twain-

Xbox live gamertag: melbolt
melbolt is offline   Reply With Quote
Old Apr 17th, 2007, 10:38 AM   #8
randum77
Programmer
 
randum77's Avatar
 
Join Date: Jun 2006
Location: Fayettehell, NC
Posts: 56
Rep Power: 3 randum77 is on a distinguished road
Interesting side note. I found that if I put the following at the top of FrmMain, then FrmLocate is available from FrmMain.

Dim WithEvents Locate As New frmLocate()

Then when I want to modify a variable or property from FrmLocate, i can just use the following.

 Locate.lblType2.Text = "Manufacturing"

I"ll be posting later about another section of this application I have to work through. I'm sure it'll be confusing the hell out of me.
__________________
_Marshall_

"America has bred a society that is innocent and incapable of accepting responsibility, but yet, is able to place blame on others without guilt."
randum77 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing a string to a variable fresher Java 5 Jan 11th, 2007 6:31 AM
FFT DWTIB -> Optimization -> Choosing An Appropriate Run Time Sane Software Design and Algorithms 7 Dec 1st, 2006 10:40 AM
Compiling Maverik 6.2 (from C) megamind5005 C 16 May 3rd, 2006 5:41 PM
Javascript: form processing, component name - variable Druid JavaScript and Client-Side Browser Scripting 8 Mar 16th, 2006 5:23 PM
Pointers in C (Part II) Stack Overflow C 2 Apr 29th, 2005 10:39 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:33 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC