Take Pity on a procedural programmer Please

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • marcmc

    #1

    Take Pity on a procedural programmer Please

    frmMIS.UserName .Text is defaulted to 'sa'
    I change it to 'sa1' when logged in as admin.
    I hit btnApply.
    I want frmMISRoutine.U serName.Text to become 'sa1' immediatly.
    I do not want to show the form immediately.
    I hit btnRoutines and load frmMISRoutine screen.
    I want to see frmMISRoutine.U serName.Text as 'sa1'
    How the hell can I do it...my code is below:
    I don't mind learning how to write classes/modules but shouldn't this be a
    simple enough thing to do. I still think that it is not much use beeing able
    to share objects between screens if you have to load that screen straight
    away. It doesn't seem very dynamis, what if you wanted to update the value on
    4 screens, would you have to show them all?

    UserName.Text on both forms is defaulted to 'sa'

    ' Apply button to set Routines.UserNa me.Text from 'sa' to 'sa1'
    Private Sub btnApply_Click( ByVal sender As System.Object, ByVal e As
    System.EventArg s) Handles btnApply.Click
    Dim frmMISRoutine As New Routines
    frmMISRoutine.U serName.Text = Me.UserName.Tex t

    Me.ClientSize = New System.Drawing. Size(584, 435)
    pnlProperties.V isible = False
    btnProperties.E nabled = True
    btnApply.Visibl e = False
    btnCancel.Visib le = False
    sbMIS.Text = "Use buttons to navigate the application (e.g.) [Properties
    sets the database and log parameters]."
    PollDirectory = txtPollDirector y.Text
    End Sub

    ' Open Routines Form. the UserName.Text should be 'sa1'.
    Private Sub btnRoutines_Cli ck(ByVal sender As System.Object, ByVal e As
    System.EventArg s) Handles btnRoutines.Cli ck
    Dim frmMISRoutine As New Routines
    frmMISRoutine.S how()
    Me.Close()
    ' When this loads Routines UserName is still sa aaarrrrgggghhhh hh!!!
    End Sub

  • Chris

    #2
    Re: Take Pity on a procedural programmer Please

    marcmc wrote:[color=blue]
    > frmMIS.UserName .Text is defaulted to 'sa'
    > I change it to 'sa1' when logged in as admin.
    > I hit btnApply.
    > I want frmMISRoutine.U serName.Text to become 'sa1' immediatly.
    > I do not want to show the form immediately.
    > I hit btnRoutines and load frmMISRoutine screen.
    > I want to see frmMISRoutine.U serName.Text as 'sa1'
    > How the hell can I do it...my code is below:
    > I don't mind learning how to write classes/modules but shouldn't this be a
    > simple enough thing to do. I still think that it is not much use beeing able
    > to share objects between screens if you have to load that screen straight
    > away. It doesn't seem very dynamis, what if you wanted to update the value on
    > 4 screens, would you have to show them all?
    >
    > UserName.Text on both forms is defaulted to 'sa'
    >
    > ' Apply button to set Routines.UserNa me.Text from 'sa' to 'sa1'
    > Private Sub btnApply_Click( ByVal sender As System.Object, ByVal e As
    > System.EventArg s) Handles btnApply.Click
    > Dim frmMISRoutine As New Routines
    > frmMISRoutine.U serName.Text = Me.UserName.Tex t
    >
    > Me.ClientSize = New System.Drawing. Size(584, 435)
    > pnlProperties.V isible = False
    > btnProperties.E nabled = True
    > btnApply.Visibl e = False
    > btnCancel.Visib le = False
    > sbMIS.Text = "Use buttons to navigate the application (e.g.) [Properties
    > sets the database and log parameters]."
    > PollDirectory = txtPollDirector y.Text
    > End Sub
    >
    > ' Open Routines Form. the UserName.Text should be 'sa1'.
    > Private Sub btnRoutines_Cli ck(ByVal sender As System.Object, ByVal e As
    > System.EventArg s) Handles btnRoutines.Cli ck
    > Dim frmMISRoutine As New Routines
    > frmMISRoutine.S how()
    > Me.Close()
    > ' When this loads Routines UserName is still sa aaarrrrgggghhhh hh!!!
    > End Sub
    >[/color]

    Well your problem seem to be you are dealing with two different Routines
    objects. Everytime you do Dim frmMISRoutine As New Routines it makes a
    new Routines object and set everything to the default. If you only want
    to deal with one object, make a class level variable called
    frmMISRoutine and then only use the "new" keyword once.

    Public Class XYZ
    dim frmMISRoutine as Routines

    Private Sub btnApply_Click( ByVal sender As System.Object, ByVal e As
    System.EventArg s) Handles btnApply.Click
    frmMISRoutine = New Routines
    frmMISRoutine.U serName.Text = Me.UserName.Tex t

    Me.ClientSize = New System.Drawing. Size(584, 435)
    pnlProperties.V isible = False
    btnProperties.E nabled = True
    btnApply.Visibl e = False
    btnCancel.Visib le = False
    sbMIS.Text = "Use buttons to navigate the application (e.g.)
    [Properties sets the database and log parameters]."
    PollDirectory = txtPollDirector y.Text
    End Sub

    ' Open Routines Form. the UserName.Text should be 'sa1'.
    Private Sub btnRoutines_Cli ck(ByVal sender As System.Object, ByVal e As
    System.EventArg s) Handles btnRoutines.Cli ck
    'Dim frmMISRoutine As New Routines
    'Now the frmMISRoutine already exists, don't make a new one
    frmMISRoutine.S how()
    Me.Close()
    ' When this loads Routines UserName is still sa aarrrrgggghhhhh h!!!
    End Sub

    Comment

    • Chris Dunaway

      #3
      Re: Take Pity on a procedural programmer Please

      I presume that btnApply and btnRoutines are both buttons on the main
      form? In that case replace these lines:

      Dim frmMISRoutin As New Routines
      frmMISRoutine.U serName.Text = Me.UserName.Tex t

      with:

      Me.UserName.Tex t = "sa1"

      Comment

      • marcmc

        #4
        Re: Take Pity on a procedural programmer Please

        yes Chris they are on the main form, thankyou and more aaaarrrrggghhhh ...

        First example says that frmMISRoutine is not declared even though I declare
        it within a class called dbProps
        The second example does not even come close to ythe requirement i need. I
        need to set the textBox on form2 when i hit the apply button on Form1, not
        show form3 until button1 is pressed. That is all.

        I have programmed in many languages and have never seen a rediculous means
        of sharing global variables like this. Insane and Why?


        "Chris" wrote:
        [color=blue]
        > marcmc wrote:[color=green]
        > > frmMIS.UserName .Text is defaulted to 'sa'
        > > I change it to 'sa1' when logged in as admin.
        > > I hit btnApply.
        > > I want frmMISRoutine.U serName.Text to become 'sa1' immediatly.
        > > I do not want to show the form immediately.
        > > I hit btnRoutines and load frmMISRoutine screen.
        > > I want to see frmMISRoutine.U serName.Text as 'sa1'
        > > How the hell can I do it...my code is below:
        > > I don't mind learning how to write classes/modules but shouldn't this be a
        > > simple enough thing to do. I still think that it is not much use beeing able
        > > to share objects between screens if you have to load that screen straight
        > > away. It doesn't seem very dynamis, what if you wanted to update the value on
        > > 4 screens, would you have to show them all?
        > >
        > > UserName.Text on both forms is defaulted to 'sa'
        > >
        > > ' Apply button to set Routines.UserNa me.Text from 'sa' to 'sa1'
        > > Private Sub btnApply_Click( ByVal sender As System.Object, ByVal e As
        > > System.EventArg s) Handles btnApply.Click
        > > Dim frmMISRoutine As New Routines
        > > frmMISRoutine.U serName.Text = Me.UserName.Tex t
        > >
        > > Me.ClientSize = New System.Drawing. Size(584, 435)
        > > pnlProperties.V isible = False
        > > btnProperties.E nabled = True
        > > btnApply.Visibl e = False
        > > btnCancel.Visib le = False
        > > sbMIS.Text = "Use buttons to navigate the application (e.g.) [Properties
        > > sets the database and log parameters]."
        > > PollDirectory = txtPollDirector y.Text
        > > End Sub
        > >
        > > ' Open Routines Form. the UserName.Text should be 'sa1'.
        > > Private Sub btnRoutines_Cli ck(ByVal sender As System.Object, ByVal e As
        > > System.EventArg s) Handles btnRoutines.Cli ck
        > > Dim frmMISRoutine As New Routines
        > > frmMISRoutine.S how()
        > > Me.Close()
        > > ' When this loads Routines UserName is still sa aaarrrrgggghhhh hh!!!
        > > End Sub
        > >[/color]
        >
        > Well your problem seem to be you are dealing with two different Routines
        > objects. Everytime you do Dim frmMISRoutine As New Routines it makes a
        > new Routines object and set everything to the default. If you only want
        > to deal with one object, make a class level variable called
        > frmMISRoutine and then only use the "new" keyword once.
        >
        > Public Class XYZ
        > dim frmMISRoutine as Routines
        >
        > Private Sub btnApply_Click( ByVal sender As System.Object, ByVal e As
        > System.EventArg s) Handles btnApply.Click
        > frmMISRoutine = New Routines
        > frmMISRoutine.U serName.Text = Me.UserName.Tex t
        >
        > Me.ClientSize = New System.Drawing. Size(584, 435)
        > pnlProperties.V isible = False
        > btnProperties.E nabled = True
        > btnApply.Visibl e = False
        > btnCancel.Visib le = False
        > sbMIS.Text = "Use buttons to navigate the application (e.g.)
        > [Properties sets the database and log parameters]."
        > PollDirectory = txtPollDirector y.Text
        > End Sub
        >
        > ' Open Routines Form. the UserName.Text should be 'sa1'.
        > Private Sub btnRoutines_Cli ck(ByVal sender As System.Object, ByVal e As
        > System.EventArg s) Handles btnRoutines.Cli ck
        > 'Dim frmMISRoutine As New Routines
        > 'Now the frmMISRoutine already exists, don't make a new one
        > frmMISRoutine.S how()
        > Me.Close()
        > ' When this loads Routines UserName is still sa aarrrrgggghhhhh h!!!
        > End Sub
        >[/color]

        Comment

        • Cor Ligthert [MVP]

          #5
          Re: Take Pity on a procedural programmer Please

          Marc,

          Place in the load event of your mainform this

          dim frm as new frmMisRoutine
          frm.mypassword = "whatever"
          frm.showdialog
          dim myresult as string = frm.mypassword
          frm.dispose

          In your frmMisRoutine you create

          Friend mypassword as string

          In the load event of that form you set
          TheTextBoxYouWa nt.Text = mypassword

          And before you close you do
          mypassword = TheTextBooxYouW ant

          There are easier methods however this is in my opinion well to understand
          the behaviour.

          You have to know that VBNet controls have no child controls direct however
          VBNet controls (Form is one of those) have only control arrays. It is a
          little bit confusing that so many VB6 people have written that the
          controlarrays don't exist anymore in VBNet. The way the controlarray as it
          was in VB6 does not exist anymore.

          I hope that this gives some ideas

          Cor


          Comment

          Working...