Results 1 to 13 of 13

Thread: Simple Problem [SOLVED]

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Posts
    23

    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.

  2. #2
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961
    u need to declare ur FORM1 as Friend/Public. then u can access its contorls from any form.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Posts
    23
    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

  4. #4
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961
    na na,

    when u instantiate ur form, u need to dim it as public.

    Dim Form1 as New Form1

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Posts
    23
    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

  6. #6
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    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:
    1. dim frmObj as new credit
    2. 'transfer the values you need to work with
    3. frmObj.MyProperty1=MyValue1
    4. frmObj.MyProperty2=MyValue2
    5.  
    6. frmObj. showDialog
    7. 'Transfer the changes back
    8. MyValue1=frmObj.MyProperty1
    9. 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...

  7. #7
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045
    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

  8. #8
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539
    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

  9. #9
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045
    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

  10. #10
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045
    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

  11. #11
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539
    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:
    1. Public Sub ShowSingleInstance(ByVal childType As Type)
    2.         'This sub handles the MDI Children
    3.         For Each child As Form In Me.MdiChildren
    4.             If child.GetType Is childType Then
    5.                 child.Activate() 'already loaded so bring to foreground
    6.             Return
    7.             End If
    8.         Next
    9.  
    10.         Dim frm As New Form
    11.  
    12.         frm = Activator.CreateInstance(childType) 'not loaded yet so create
    13.         frm.MdiParent = Me
    14.         frm.Show()
    15.  
    16.     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:
    1. 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:
    1. Dim parent As MainApp = CType(Me.MdiParent, MainApp)
    2.  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

  12. #12
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045
    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

  13. #13
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539
    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
  •  



Click Here to Expand Forum to Full Width