Procedure too large error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • darrel
    New Member
    • Nov 2006
    • 72

    Procedure too large error

    Hi can somebody tell me how can i resolve my "PROCEDURE TOO LARGE ERROR",,, my code is too large.. how can i resolve it.
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    I've never heard of that error. What version of Visual Basic is this?

    Of course, the obvious answer is "make it smaller". If a procedure is too large, you probably need to break it up into smaller routines.

    Comment

    • Dököll
      Recognized Expert Top Contributor
      • Nov 2006
      • 2379

      #3
      Originally posted by darrel
      Hi can somebody tell me how can i resolve my "PROCEDURE TOO LARGE ERROR",,, my code is too large.. how can i resolve it.
      Listen to him darrel, break it down today, bit by bit. I have had this problem before, assuming you are using VB 6.0. The line of code you are using is too large, even if you build modules to handle some routines, VB will consider the code too long.

      One option could be to add an aditional button and plug in the remaining code there, an ugly way of solving this but if you have a number of calls to make in one procedure, VB will be unhappy and will yell at you. There's gotta be an easier way, I stopped there after solving in my primitive fashion:-)

      Sorry for your troubles, not fun...

      Comment

      • darrel
        New Member
        • Nov 2006
        • 72

        #4
        yah i know the only way to solve it is to break it up!!! but i dont know how! i think i need to create a function in a module but i dont know how?? can you give me some details on how can i achieve it.. its like am going to create a function and then calll it in my form everytime i need it.. hope you can help, i cant post my code here coz i will be too long...

        Comment

        • Dököll
          Recognized Expert Top Contributor
          • Nov 2006
          • 2379

          #5
          Originally posted by darrel
          yah i know the only way to solve it is to break it up!!! but i dont know how! i think i need to create a function in a module but i dont know how?? can you give me some details on how can i achieve it.. its like am going to create a function and then calll it in my form everytime i need it.. hope you can help, i cant post my code here coz i will be too long...
          The module will again record length of your routine thus deemed too long per VB. I need you to tell me a little more about your program so I can tell you how to break it down:

          (1) Are you seaching/loading a file?
          (2) How many command buttons do you have on the form
          (3) Do you have sub forms

          Answer these and we'll continue. Also it will be helpful to post your code, at least a portion of it to be specific.

          In a bit!

          Comment

          • darrel
            New Member
            • Nov 2006
            • 72

            #6
            Thank you for replying. Yes am Searching with my database, I only have one command button fro now. And i dont know what is a sub form.

            To give a background of my program, the program is a time scheduling of subjects in a particular university. Thats wer i work for,,,

            I almost have 2400 line of commands,,, it has many selection. e.i. when i chose a particular choice with in my program it has to display details in my form, and the details are in my databse, i think i have a bunch of loops and tables..

            Question: How can i combined a loop with diffenrent tables in my databse. heres the code:

            Code:
            'Time Connection
            If rs.State = adStateOpen Then rs.Close
                   rs.Open "Select * from [Time]", cnn, adOpenKeyset, adLockOptimistic
                While rs.EOF <> True
                    For x = 0 To 7
                    Combo1(x).AddItem rs.Fields("Time").Value
                    Next x
                 rs.MoveNext
                Wend
            'Time Connection
            
            'Room Connection
            If rs.State = adStateOpen Then rs.Close
                   rs.Open "Select * from [ROOMS]", cnn, adOpenKeyset, adLockOptimistic
              While rs.EOF <> True
                For x = 0 To 7
                    Combo2(x).AddItem rs.Fields("ROOM").Value
                Next x
              rs.MoveNext
              Wend
            'Room Connection
            
            'Days Connection
            If rs.State = adStateOpen Then rs.Close
                   rs.Open "Select * from [DAYS]", cnn, adOpenKeyset, adLockOptimistic
              While rs.EOF <> True
                For x = 0 To 7
                    Combo3(x).AddItem rs.Fields("DAYS").Value
                Next x
              rs.MoveNext
              Wend
            End If
            'Days Connection
            how can i combined it in one single loop... i have the code with all the lines in my code so far... i always use those code for able for me to load the details in my database i hope youre getting what am trying to say, I hope you can help to simply this code or to teach how can i can a function and just call it up of my form. rhank you

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Unfortunately, this sort of thing depends entirely on your code. The kind of thing you want to look for is anything which is done repeatedly, that you could put into a Sub or Function and call. Anything which can be done independently of the rest of the form. Things like that.

              You have to try and work out how you can carve up your code into pieces, then move the pieces into a code module. This may mean setting up globals variables, or you may simply pass the relevant data to/from the routines as parameters and/or function return values.

              Comment

              • darrel
                New Member
                • Nov 2006
                • 72

                #8
                yes i know thats the solution to my problem, can i just copy paste the code that has been repeatedly done in my form, how can i do it! could you site me some example on how to build a function in a module and call it up when it is needed.. thank you very much

                Comment

                • Dököll
                  Recognized Expert Top Contributor
                  • Nov 2006
                  • 2379

                  #9
                  Originally posted by darrel
                  yes i know thats the solution to my problem, can i just copy paste the code that has been repeatedly done in my form, how can i do it! could you site me some example on how to build a function in a module and call it up when it is needed.. thank you very much
                  I hear your pain, darrel. You can get through it...

                  A sub form by the way is only another form within your main form, it could be included on a frame.

                  Alright, what must happen when the command button is pressed?

                  In my case, I was searching/reading/loading text to either a .txt file or MS Access database. I added three button: Search/Commit/View

                  (1) A portion of the code resided under Search (Added data to part of the form while the form remains invisible

                  (2) A portion of the code resided under Commit (Added data to part of the form while the form remains invisible

                  (3) Remaining code resided under View (Added remaining data to form and then form was visible.

                  What this means, you'll need to figure out a way to have a form that used solelly for searching your database, and only when the View button is pressed should the results form appear...

                  TIPS: Search button disappears and makes visible Commit buttton, then Commit button disappears to make visible View button. Search form disappears respectively upon entry of your results form

                  Good luck, and I hope this helps!
                  Last edited by Dököll; May 19 '07, 04:47 PM. Reason: Text

                  Comment

                  • Killer42
                    Recognized Expert Expert
                    • Oct 2006
                    • 8429

                    #10
                    Originally posted by darrel
                    yes i know thats the solution to my problem, can i just copy paste the code that has been repeatedly done in my form, how can i do it! could you site me some example on how to build a function in a module and call it up when it is needed.. thank you very much
                    Sorry, I'll try to come up with something when I can. Have been extremely busy.

                    Comment

                    • AnuragShrivastava
                      New Member
                      • May 2007
                      • 1

                      #11
                      What u can do is in every table add a field SI No
                      Then Run The Sql

                      rs.open "Select Time.SINo as Slno ,Time as Time1,Room as Room1,Days as Days1 from [Time],Room,Days where Time.SINo =Room.SINo and Time.SINo =Days.SINo"
                      While rs.EOF <> True
                      For x = 0 To 7
                      Combo1(x).AddIt em rs.Fields("TIME ").Value
                      Combo2(x).AddIt em rs.Fields("Room ").Value
                      Combo3(x).AddIt em rs.Fields("DAYS ").Value
                      Next x
                      rs.MoveNext
                      Wend

                      I'm not sure
                      jus chk it and try

                      Comment

                      Working...