Problem in VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shailja
    New Member
    • Feb 2007
    • 123

    #16
    Originally posted by vijaydiwakar
    which form is opened first ? are u showing frmsales modally?
    now tell me the execution flow of thy programm

    I am running frmSales first and from form load event of that form i am calling function of frmMain form.

    Comment

    • sashi
      Recognized Expert Top Contributor
      • Jun 2006
      • 1749

      #17
      Originally posted by Shailja
      I am running frmSales first and from form load event of that form i am calling function of frmMain form.
      Hi there,

      Just one question, is your frmMain is an MDI container?

      Comment

      • vijaydiwakar
        Contributor
        • Feb 2007
        • 579

        #18
        Originally posted by Shailja
        I am running frmSales first and from form load event of that form i am calling function of frmMain form.
        Now forget abt all the things happened and try this on new project
        add one more form to it
        rename first form to frmSales
        in frmsales
        add this code
        Code:
        Private Sub Form_Load()
        frmmain.LockTextBoxes me
        End Sub
        rename second form to frmmain and paste the code in it
        Code:
         
        public Sub LockTextBoxes(byref frm as form )
        Dim ctrl As Control
        For Each ctrl In frm
            If TypeOf ctrl Is TextBox Then ctrl.Enabled = False
        Next
        End Sub
        Now u don't have any problem
        I've checked it and it is doing the things fine
        k.........

        Comment

        • willakawill
          Top Contributor
          • Oct 2006
          • 1646

          #19
          Originally posted by Shailja
          An error is coming when I execute the statment
          frmMain.OnLoad( Me)
          I am writting this statment into other form and calling function written into frmMain. Whats wrong with above statment?
          Shailja, when you use the word 'Me' in vb you are using a pointer or reference to the object. If you pass this word as a parameter in a function then you are passing by reference and not by value. This will give you the error you are getting.

          Aside from the error, this is very bad coding practise. You are tying yourself up in knots just to avoid writing 4 more lines of code. You should never open a form and perform initializing of controls based on a function in another form module. That is crazy coding. don't do it.

          Comment

          • sukeshchand
            New Member
            • Jan 2007
            • 88

            #20
            Hi try like this

            Paste the following code to any one module. if there is no modules present Add one module

            Code:
            public Sub LockTextBoxes(byref frm as form )
            Dim ctrl As Control
            For Each ctrl In frm
                If TypeOf ctrl Is TextBox Then ctrl.Enabled = False
            Next
            End Sub
            And you can call this function anyware in your program
            Like
            Code:
            Private Sub Form1_Load()
               LockTextBoxes Me
            End Sub
            
            '  Or
            
            Private Sub CmdOK_Click()
               LockTextBoxes frmSalesMaster
            End Sub

            Comment

            • willakawill
              Top Contributor
              • Oct 2006
              • 1646

              #21
              Originally posted by sukeshchand
              Hi try like this

              Paste the following code to any one module. if there is no modules present Add one module

              Code:
              public Sub LockTextBoxes(byref frm as form )
              Dim ctrl As Control
              For Each ctrl In frm
                  If TypeOf ctrl Is TextBox Then ctrl.Enabled = False
              Next
              End Sub
              And you can call this function anyware in your program
              Like
              Code:
              Private Sub Form1_Load()
                 LockTextBoxes Me
              End Sub
              
              '  Or
              
              Private Sub CmdOK_Click()
                 LockTextBoxes frmSalesMaster
              End Sub
              Again, this is poor coding practise. This means that your form code is not encapsulated and not reuseable. Bad idea

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #22
                Originally posted by Shailja
                An error is coming when I execute the statment
                frmMain.OnLoad( Me)
                I think that may be simply because of the parentheses. This probably should have been
                Code:
                frmMain.OnLoad Me

                Comment

                Working...