VB .net help

The geek forum. PHP, Perl, HTML, hardware questions etc.. it's all in here. Got a techie question? We'll sort you out. Ask your questions or post a link to your own site here!

VB .net help

Postby Kenshin17 » Thu Mar 17, 2005 10:54 am

Ok here's the deal:
I am making a multi-form program, and I am having trouble moving data between forms. I need to know how to dim a form without using the
,dim objectname as new frmname, command. It will work when I return from one of the forms but when I load the next form it makes a new version of the main form and erases the data I input into it from the previous form. So I need to know if anyone knows how to dim a form so I can use it but dim it in such a way that its contents remain when I load another form to input more data.
A nightingale in a golden cage
That's me locked inside reality's maze
Come someone make my heavy heart light
Come undone, bring me back to life
It all starts with a lullaby
User avatar
Kenshin17
 
Posts: 860
Joined: Tue Nov 02, 2004 9:17 am
Location: On the earth, perhaps

Postby TheMelodyMaker » Fri Mar 18, 2005 10:17 am

If transferring data from one form to another is your only issue, you could set up a bunch of public variables to temporarily store the values from the first form just before it closes -- which could then be loaded into the second form. (I hope I'm understanding you correctly here, and if so, I hope it works for you -- it's all I can think of at the moment and I'm not sure how different VB.NET is from VB6. ^_^; )

Edit: You could also try DIMing it dynamically and then REDIMing it with the "Preserve" keyword; I'm not sure if that'll help or not.
[color=RoyalBlue]@)}~`,~ [/color]Carry this rose in your signature as thanks to Inkhana, for all she has done for us in the past.Even though she is no longer a moderator, she has done an awful lot for us while she was and she deserves thanks. ^_^
TheMelodyMaker
 
Posts: 1904
Joined: Sun Jul 20, 2003 10:13 pm

Postby Kenshin17 » Fri Mar 18, 2005 6:49 pm

Well that could help. I do have several globals. The problem is because for each subform I have to dim the main one as a new form it erases the data in the original form. Therefore the text I put in a label from one subform is erased when I return to the main form after exiting another sub form. What is the exact syntax for the preserve command?
A nightingale in a golden cage
That's me locked inside reality's maze
Come someone make my heavy heart light
Come undone, bring me back to life
It all starts with a lullaby
User avatar
Kenshin17
 
Posts: 860
Joined: Tue Nov 02, 2004 9:17 am
Location: On the earth, perhaps

Postby TheMelodyMaker » Fri Mar 18, 2005 8:10 pm

Preserve isn't really a command so much as an optional keyword used with the ReDim command. Just use it like this:

Code: Select all
ReDim Preserve varname (dimensions)


I do hope that helps. ^_^;
[color=RoyalBlue]@)}~`,~ [/color]Carry this rose in your signature as thanks to Inkhana, for all she has done for us in the past.Even though she is no longer a moderator, she has done an awful lot for us while she was and she deserves thanks. ^_^
TheMelodyMaker
 
Posts: 1904
Joined: Sun Jul 20, 2003 10:13 pm

Postby Cap'n Nick » Sat Mar 19, 2005 2:22 pm

I have a hunch about what's going on but I'll need some more information. Are you by chance using Dim (name of main form) to call the main form from the subforms? This would not call your old main form but would create a blank copy of the main form, resulting in the apparent loss of data you are experiencing. If this is correct then your data is still there. All you need to do is refer to your original instance of it instead of creating a new copy. I would do this by passing a reference to the main form to each of the subforms as they are created.
User avatar
Cap'n Nick
 
Posts: 1008
Joined: Sat Nov 13, 2004 10:00 am
Location: Kojima, Japan

Postby Kenshin17 » Sat Mar 19, 2005 8:02 pm

You hit her right in the center. That is exactly what is happening. So exactly how do I pass a refrence to the subs?
A nightingale in a golden cage
That's me locked inside reality's maze
Come someone make my heavy heart light
Come undone, bring me back to life
It all starts with a lullaby
User avatar
Kenshin17
 
Posts: 860
Joined: Tue Nov 02, 2004 9:17 am
Location: On the earth, perhaps

Postby Cap'n Nick » Sun Mar 20, 2005 12:06 pm

Set up a variable in each of the subforms to hold the reference. Then set this variable to your main form. When your subform needs to pass information to the main form or call it back up it uses this reference instead of creating a new copy of the main form. Here is how I would do it:

In the subform:

Code: Select all
'A variable to hold the reference to the main form.
Private mainForm As (class of main form)

'The constructor is altered to accept the reference to the main form as the subform is created.  Make sure this variable is passed ByRef.  ByVal will create another copy, leading again to your original problem.
Public Sub New(ByRef MainFormReference As (class of main form))
    .
    (whatever VB.NET already put in here, don't mess with it)
    .
    mainForm = MainFormReference
End Sub


Now you can pass a reference to the main form to the subform when you create it. In fact, VB.NET will generate an error if you attempt to create a subform without passing this reference.

In the main form:

Code: Select all
'Creating a new instance of the subform with a reference to the main form, "Me".
Dim subform As New (class of subform)(Me)


Use the reference you wrote into the subform, mainForm, to manipulate the main form.

In the subform:

Code: Select all
'Brings up the main form.
mainForm.Show()

'Passes data to the main form.
mainForm.FictionalVariable = whatever

'Changes the text of a text box on the main form.
mainForm.TextBoxName.Text  = "whatever"


This is assuming that your main form stays open. If your main form closes and you attempt to call it you will generate an error.
User avatar
Cap'n Nick
 
Posts: 1008
Joined: Sat Nov 13, 2004 10:00 am
Location: Kojima, Japan

Postby Mithrandir » Sun Mar 20, 2005 12:34 pm

General Computer Science:
If you pass a ref to a defunct object, you'll get an error. On the other hand, if you pass the actual object, you can avoid this - but you'll have a (object) MB of memory in use each time.

I just LOVE polymorphing methods, and over-writing classes, don't you?

:lol:
User avatar
Mithrandir
 
Posts: 11071
Joined: Fri Jun 27, 2003 12:00 pm
Location: You will be baked. And then there will be cake.

Postby Kenshin17 » Sun Mar 20, 2005 6:48 pm

:dance: :dance: :dance: :dance:
:dance: :dance: :dance: :dance:
IT WORKED!!!!!!!! IT WORKED!!!!!!!!!!

Now all those hours of form making are not in vain!!!!
Cap'n Crack you are my hero!!!!!!!!!!
Thanks MeldoyMaker for your help as well. I guess we both learned something ;)
A nightingale in a golden cage
That's me locked inside reality's maze
Come someone make my heavy heart light
Come undone, bring me back to life
It all starts with a lullaby
User avatar
Kenshin17
 
Posts: 860
Joined: Tue Nov 02, 2004 9:17 am
Location: On the earth, perhaps

Postby Cap'n Nick » Sun Mar 20, 2005 7:47 pm

Hooray for programs that do things!

EDIT: Good things! Programs that do good things!
User avatar
Cap'n Nick
 
Posts: 1008
Joined: Sat Nov 13, 2004 10:00 am
Location: Kojima, Japan

Postby Kenshin17 » Mon Mar 21, 2005 11:04 am

I just ran into a problem. When I try to retern to a form after I have already called it it freezes. Any way around this?
A nightingale in a golden cage
That's me locked inside reality's maze
Come someone make my heavy heart light
Come undone, bring me back to life
It all starts with a lullaby
User avatar
Kenshin17
 
Posts: 860
Joined: Tue Nov 02, 2004 9:17 am
Location: On the earth, perhaps

Postby anime4christ » Wed Apr 06, 2005 2:51 pm

uhm, not sure what you mean. I've been working with VB.NET for a while now. What exactly is going on? How are you returning to the form? In code or windows?
User avatar
anime4christ
 
Posts: 487
Joined: Wed Dec 01, 2004 10:00 am
Location: California

Postby Cap'n Nick » Wed Apr 06, 2005 3:48 pm

Yes man! We want code so me we help you with your troubles!
User avatar
Cap'n Nick
 
Posts: 1008
Joined: Sat Nov 13, 2004 10:00 am
Location: Kojima, Japan

Postby Kenshin17 » Wed Apr 06, 2005 5:09 pm

Um...actually I figured it out. My VB teacher gave me some pointers and they work fine. Sorry :sweat: You guys where a big help though :thumb:
A nightingale in a golden cage
That's me locked inside reality's maze
Come someone make my heavy heart light
Come undone, bring me back to life
It all starts with a lullaby
User avatar
Kenshin17
 
Posts: 860
Joined: Tue Nov 02, 2004 9:17 am
Location: On the earth, perhaps

Postby Cap'n Nick » Thu Apr 07, 2005 7:59 am

Ooh, help from an educated professional! That's better than I could do considering that I am self-educated and that I am a professional only through a grand error of the cosmos.
User avatar
Cap'n Nick
 
Posts: 1008
Joined: Sat Nov 13, 2004 10:00 am
Location: Kojima, Japan


Return to Computing and Links

Who is online

Users browsing this forum: No registered users and 137 guests