|
-
Apr 28th, 2004, 02:04 AM
#1
Thread Starter
Junior Member
Simple Problem [SOLVED]
Hi there
my program starts up with the form called FORM1
it has a grid, with 2 textboxes, username and password
after successful login, there is 2 textboxes that displays the username and userlevel in txtUN and txtUL respectively
i have another form called credit
which i call on credit_click
with this code
dim frmObj as new credit
frmObj. showDialog()
i wish to get the values found in the txtUN and txtUL on the form credit also. ?? how do i do that ?
Thanks
Last edited by virusdude; May 5th, 2004 at 12:06 AM.
-
Apr 28th, 2004, 02:11 AM
#2
Fanatic Member
u need to declare ur FORM1 as Friend/Public. then u can access its contorls from any form.
-
Apr 28th, 2004, 02:13 AM
#3
Thread Starter
Junior Member
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Dim timeStr As String
Dim str As String = "'"
Dim strPath As String = "\\Universi-lab-12\c\UCBCDB1.mdb"
Dim remindState As Boolean
Dim todayState, yesterdayState As Date
isnt is declared to Public??
but still i cant access the values
i can access the controls... but the values doest come up
Help plz
Thanks
-
Apr 28th, 2004, 02:17 AM
#4
Fanatic Member
na na,
when u instantiate ur form, u need to dim it as public.
Dim Form1 as New Form1
-
Apr 28th, 2004, 02:23 AM
#5
Thread Starter
Junior Member
U mean to say
when i create an object of the FORM1 in the credit form
i declared it like this
public frmObj as NEW form1
txtUserName.text = frmObj.txtUN.text
??
but the txtUserName.text does not display the value
-
Apr 28th, 2004, 04:16 AM
#6
Hi.
You have to make sure that you don't instantiate another NEW Form1. If you do that then you have 2 Form1 objects.
And by the looks of it, that's what you are doing. Because you declare a NEW FORM1 inside the credit, you are not refering to the caller, but to a new instance of form1.
But instead of trying to keep track of instances and references, I find it easier to add properties to the second form.
VB Code:
dim frmObj as new credit
'transfer the values you need to work with
frmObj.MyProperty1=MyValue1
frmObj.MyProperty2=MyValue2
frmObj. showDialog
'Transfer the changes back
MyValue1=frmObj.MyProperty1
MyValue2=frmObj.MyProperty2
This way, you can add all the objects and references needed, without having to think about instances, and when they were created.
If you don't want to do that, create a module, where you put your public statement. This will make the form1 instance public to everyone on the project.
I hope this helps you.
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
May 4th, 2004, 02:33 PM
#7
Frenzied Member
Pax and
Esteemed Forum Participants and Lurkers:
NEWBIE ALERT!
Thanks, Pax for your response to VirusDude's Simple Problem. It looks really close to what I want to do ... what are the "Dim"s that are required in Form1 and in frmObj (Explicit ON) for:
frmObj.MyProperty1 and MyValue1
frmObj.MyProperty2 and MyValue2
where (perhaps) MyValue1 is a string, and MyValue2 is an integer.
If I understand correctly, Form1 can set the values and passes them to frmObj ... frmObj modifies the values, and after closing, the new values are available to Form1.
Is anything special required in frmObj other than identifying the variables and setting them to some value?
Thank you for your gracious assistance, comments, or suggestions.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
May 4th, 2004, 02:38 PM
#8
Fanatic Member
theres a real simple solution to a simple problem like this
add a module then put this in the module
Public frmMainForm As MainForm
i always stick frm is front of the name of the form that way you know you getting the module value
then in my mainForm i stick frmMainForm = me
in the windows code just under InitializeComponent()
this way you can access any property on the form from anywhere in the project simply by using frmMainForm.{Properties of that form are shown}
Nice nice
I am curretly building a defect management system for software and web developers,
If you wana try it out (beta test) and keep it for free just send me a message
-
May 4th, 2004, 03:21 PM
#9
Frenzied Member
Carl Blanchard and
Esteemed Forum Participants and Lurkers:
THANK YOU CARL! It works, and someday I'll even figure out exactly why! I only have one problem ...
I open Form2 (my popup) in a radio button click event with:
'Popup a modal form for selecting a table
Dim frm As New Form2
AddOwnedForm(frm)
' "ShowDialog" opens the form MODAL
frm.ShowDialog(Me)
In Form2, in each of the 4 radio button handlers I set my Form1 textbox.Text successfully and exit with:
Dispose(True)
I have a MsgBox in Form2 Dispose:
If disposing Then
' Acknowledge Disposal
>>> MsgBox("Bye Bye from Form 2")
' Continue with Disposal
If Not (components Is Nothing) Then
components.Dispose()
End If
This 'ByeBye' pops up when I click a Form2 button and Form2 closes ... but it ALSO pops up when I close Form1 ... once for every time I had Form 2 open!
Obviously, a new Form2 gets instantiated every time I click my Form1 button, and when Form1 is closed, all it's children finally get put out of their misery.
I put all the ownership junk in Form1 when opening Form2 from another example I found. While I'm waiting for an answer, I'll play with taking that stuff out again
Thank you for your gracious assistance.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
May 4th, 2004, 03:31 PM
#10
Frenzied Member
Carl ...
As I expected (hoped?) ... if I get rid of all the ownership junk and just do:
Dim frm As New Form2
' "ShowDialog" opens the form MODAL
frm.ShowDialog()
It works beautifully!
My 'ByeBye' fires only when Form2 is closed and does NOT fire at all when Form1 closes. Now I can select things from a sophisticated popup!
Thanks again for your help. Getting started in this stuff can really be a daunting experience.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
May 4th, 2004, 03:40 PM
#11
Fanatic Member
It's very simple think about it
Module are accessible to everything and they dont need to be initialized, therefore when MainForm open it tell the module ("hey im main form so store me as the value") So basically the module stores the properties of the form nice hey
OK with ref to the last post you got me a little bit lost (firstly are you using MDI form ? )
if you are trying to use mdi forms then use the following function
VB Code:
Public Sub ShowSingleInstance(ByVal childType As Type)
'This sub handles the MDI Children
For Each child As Form In Me.MdiChildren
If child.GetType Is childType Then
child.Activate() 'already loaded so bring to foreground
Return
End If
Next
Dim frm As New Form
frm = Activator.CreateInstance(childType) 'not loaded yet so create
frm.MdiParent = Me
frm.Show()
End Sub
Just copy and paste that entire sub into the main mdi parent
then to open and close forms use the follow
(this is within the parent mdi form )
VB Code:
ShowSingleInstance(GetType(NewAccount))
New account is the name of the form ie form2 if you double click on newaccount and remove it intellisense will show you all the forms + more you can access
ok i know next question - how to control form1 from form2
VB Code:
Dim parent As MainApp = CType(Me.MdiParent, MainApp)
parent.ShowSingleInstance(GetType(NewAccount))
Hope it helps
I am curretly building a defect management system for software and web developers,
If you wana try it out (beta test) and keep it for free just send me a message
-
May 4th, 2004, 05:19 PM
#12
Frenzied Member
Carl ...
No, I don't think I'm using MDI. I'm just implementing a popup for a user interface for selecting function specific operating parameters. Click RadioButton1 on Form1 for one particular function, and the Form2 popup allows the user to select which one of 4 table types will get built in Form1 - "W", "X", "Y", or "Z". Other functions on Form1 do not need and do not have this selection capability.
Sorry I confused you ... I threw a LOT of crap in my code trying to implement various suggestions and samples. Now it is all cleaned up.
Here is the sum total of what I did to get the plain VB.Net foundation to work ...
Form1 is my main form
Form2 is my popup that I designed and added
Added a module per your instruction: MyModule1
I added to it only: Public frmForm1 As Form1
At the front of my RadioButton1_Click handler I added:
'Popup a modal form for selecting a table type
Dim frm As New Form2
' "ShowDialog" opens the form MODAL
frm.ShowDialog()
In Form2 I have 4 Radio Buttons. Each handler does the following, loading W, X, Y, or Z:
' Set the Table id to Z
frmForm1.idlabel.Text = "Z"
'TEST MsgBox("Z")
Me.DialogResult = DialogResult.OK
The DialogResult is totally Ignored ... it just closes Form2. "Dispose(True)" also works.
That's it! "idlabel" is a Form1 TextBox that gets loaded with the Table Type character by the popup. In the program, I use idlabel.Text to do the proper operations I need.
The end result of this whole operation is to build 1 of 4 HTML tables. I take a list text file and a directory, and build a table of all of the list items, linking each file to it's list item. Not all list items have a corresponding file, so those are built "grayed out" (unlinked). I then insert the HTML code into a web page (actually Intranet). There are up to 166 files to link! The only other way to do this with our publishing software (Collage) is to MANUALLY link each and every file ... a terribly time consuming and tedious operation that takes about 2 hours to complete. Not to mention that the master list changes about every month or two!
There are about 5 other types of tables that I build as well. Does that make any sense?
I actually have all the Table Generators all working in Python, but that's an interpretive language and I can't port that to other machines in the office. VB gives me the exe's.
Thanks for everything ...
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
May 5th, 2004, 03:32 AM
#13
Fanatic Member
Yeah it kinda makes sense, however i cant really see how your using winforms for a webapp ???
If you have an intranet site with loads of pages in a directory that no one can get at because no index page linking them all together, why not just make an asp.net webpage using the file system object which looks in a perticular directory and write a a href to the page for each file in the directory ?
I am curretly building a defect management system for software and web developers,
If you wana try it out (beta test) and keep it for free just send me a message
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|