Begineer looking for help with forms 
Author Message
 Begineer looking for help with forms

What I wanted to do was have a nice window pop-up when a menu idem was
selected. This window would would except input fron the user as strings. when
this window closes I want that information to be transferd to the form1. Here
is what I have done. I made a second form with a dialogbox that has text boxes
etc for the input. If the cancel button is clicked, non of the information is
used but if the OK button is clicked I want to send that data from form2 to
form1.
Form2 is called with a .show statment in form1 I have a user typr array in for
one that I would like to put this data in but at this point anything will do.
The array is both defined and created in the " General" portion of form1 and
the compiler will not let me make it global or public. I have tried the same
things in the Form load segment on form1. I have tries so many things that I
have lot track. So...

What should I be doing ???? Please !




Wed, 27 Aug 2003 13:06:03 GMT  
 Begineer looking for help with forms
You could put your UDT declarations in a Module instead of a Form.
Alternatively, you could keep them as Private in Form1 (as in your existing
code) and use a publicly declared temporary variable as a sort of "go
between". For example:

In Form1:

Option Explicit
Private Type mytype
  first As String * 20
  second As String * 10
  ' etc
End Type
Private mike As mytype
Public tempstring1 As String
public tempstring2 As String
Private Sub Command1_Click()
Form2.Show vbModal
mike.first = tempstring1
mike.second = tempstring2
End Sub

and in Form 2:

Private Sub Command1_Click()
Form1.tempstring1 = "First test"
Form1.tempstring2 = "Next test"
Unload Me
End Sub

It seems a bit complicated, though. Hardly worth having a nice little UDT in
the first place! So I would suggest that you use a module instead of a Form
to declare your UDTs and then you will be able to make them Public.

Mike


Quote:
> What I wanted to do was have a nice window pop-up when a menu idem was
> selected. This window would would except input fron the user as strings.
when
> this window closes I want that information to be transferd to the form1.
Here
> is what I have done. I made a second form with a dialogbox that has text
boxes
> etc for the input. If the cancel button is clicked, non of the information
is
> used but if the OK button is clicked I want to send that data from form2
to
> form1.
> Form2 is called with a .show statment in form1 I have a user typr array in
for
> one that I would like to put this data in but at this point anything will
do.
> The array is both defined and created in the " General" portion of form1
and
> the compiler will not let me make it global or public. I have tried the
same
> things in the Form load segment on form1. I have tries so many things that
I
> have lot track. So...

> What should I be doing ???? Please !





Wed, 27 Aug 2003 18:47:25 GMT  
 Begineer looking for help with forms


Quote:
> What I wanted to do was have a nice window pop-up
> when a menu idem was selected. This window would
> would except input fron the user as strings. when
> this window closes I want that information to be
> transferd to the form1.
> Here is what I have done. I made a second form
> with a dialogbox that has text boxes etc for the input.
> If the cancel button is clicked, non of the information
> is used but if the OK button is clicked I want to send
> that data from form2 to form1.
> Form2 is called with a .show statment in form1 I
> have a user typr array in for one that I would like to
> put this data in but at this point anything will
> do.
> The array is both defined and created in the
> " General" portion of form1 and the compiler will
> not let me make it global or public. I have tried the
> same things in the Form load segment on form1.
> I have tries so many things that I have lot track. So...
> What should I be doing ???? Please !

===================================
(1)  You /could/

(a) Declare your arry using 'Dim' in Form1. i.e.

Dim MyArray(100)

(b) Have  a Public Sub in Form1 which reads the data from the Text boxes on
Form2 i.e.

Public Sub Read_Data

MyArray(0) = Form2.Text1.Text
MyArray(1) = Form2.Text2.Text
'etc

End Sub

(c) On Form2, in the Click event for your 'OK' button have

Form1.Read_Data
=====================================

=====================================
(2) Much better is to

(a) Add a .bas module to your project

(b) Declare your array in this module as /Public/, i.e.

Public MyArray (100)

(c)  In the Click event for your 'OK' button on Form2:

MyArray(0) = Text1.Text
MyArray(1) = Text2.Text
'etc
======================================

Christina

Christina West



Wed, 27 Aug 2003 20:45:49 GMT  
 Begineer looking for help with forms

In the menu event that loads form2 ...

   Load Form2
   'preset any text box items on form2 as needed
   Form2.Text1.Text = "hello"

  'pass command to form2
   Form2.Show vbModal

  'form2 is hidden, so retrieve values from hidden form
   Text1.Text = Form2.Text1.Text 'form1 text1 now holds "hello"

  'done, so unload form2
   Unload Form2

In form2's exit button click event ...

  Me.Hide  'NOT unload

--

Randy Birch
MVP Visual Basic

Take the vb.net poll at:
http://www.mvps.org/vbnet/
http://www.mvps.org/ccrp/

Please respond only to the newsgroups so all can benefit.


: What I wanted to do was have a nice window pop-up when a menu idem was
: selected. This window would would except input fron the user as strings.
when
: this window closes I want that information to be transferd to the form1.
Here
: is what I have done. I made a second form with a dialogbox that has text
boxes
: etc for the input. If the cancel button is clicked, non of the information
is
: used but if the OK button is clicked I want to send that data from form2
to
: form1.
: Form2 is called with a .show statment in form1 I have a user typr array in
for
: one that I would like to put this data in but at this point anything will
do.
: The array is both defined and created in the " General" portion of form1
and
: the compiler will not let me make it global or public. I have tried the
same
: things in the Form load segment on form1. I have tries so many things that
I
: have lot track. So...
:
: What should I be doing ???? Please !
:



Thu, 28 Aug 2003 02:06:49 GMT  
 Begineer looking for help with forms
Thanks Everyone. So... The Global modual is a new modual that is not part of a
form. You have to add it to your project and it will have a .BAS extention. I

Hiding form2. If form2 is modal it takes and returns control much like a
function. On form2 you "Hide" it  when you are done insted of unloading it. All
I added was a flag in form2 to tell form1 weather form2s cancel button or OK
button was used. Since control is then passed back to form1 at the calling
point. It is easy for form1 to read form2s text boxes, or not depending on
cancel or OK and then form1 unloads from2.

This works quit well and...
Does not need a global modual
Does not need a "temp" Array to hold values to see if there needed
And no code needs to be written for the text box click event on form2 to stor
the changes in the temp array.

A very nice solution. Thank you

-DA-



Sun, 31 Aug 2003 12:57:42 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Visual Basic Begineer

2. Scroll Bar (begineer)

3. Begineer Multithreading

4. Help: 3D looking form

5. MVP-looking for help with .addnew, Please help!!!

6. MVP-looking for help with .addnew, Please help!!!

7. Create a Help looks like a office help !!!

8. Design Form -> Look In List

9. Custom Contact Form - Looking for Programmer

10. Looking at Forms

11. when I print IE form, my page looks different on paper

12. Look up record based on form input

 

 
Powered by phpBB® Forum Software