Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does a VB 6 procedure have a line limit?

Status
Not open for further replies.

asmith555

Programmer
Oct 7, 2002
97
US
I keep getting a "Procedure is too large" error. The procedure in question has 12000 lines of code. Is there a limit? If so what is it and how can i get around it. This procedure cannot easily be broken out.
 
A procedure can be no bigger than 64KB. It's going to have to be broken down into smaller procedures.

"Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'."
 
Hi asmith555:

Good programming practices has a limit of one to two pages per procedure. A procedure of 12000 lines strongly indicates extremely bad programming practices. I would like to suggest learning structured programming and object-oriented programming. (True that VB6 is not a true OOP language, but some of the programming paradigms of OOP can be applied.)

Any long procedure can be broken down. Passing variables between the sub-procedures would become a major headache, but would still be doable.

As for a VB limit, don't know whether there is one, but a procedure may or may not be able to cross the 64 kB segment limitation. How many bytes per line? I don't know.

Cassandra
 
The procedure was a dts package generated from sql server in the form of a .bas file. Its basically an import data function to a extremly poorly designed database that contains 477 fields.
 
How many parameters and how many local variables. You ma be able to break it into pieces and call each piece from the preceding.

Call TooLong(args)

Sub TooLong(args)
Dim local stuff
.......
' Break here
Call TooLong2(args,localstuff)
End Sub
Sub Call TooLong2(args,localstuff)
.....
End Sub


Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
Back when I first started using VB, I tried to to Fill a 8000 x 2 string array at startup with a procedure...

I had to break it into about 5 parts, maxing out each procedure, and chaining them from where the last left off...
Code:
Public AnArray(8000,1) as string
Sub Set1()
  AnArray(0,0) = "Looong Text"
  AnArray(0,1) = "Abv Txt"
  ...
  AnArray(1000,0) = "Looong Text"
  AnArray(1000,1) = "Abv Txt"
  Set2
End Sub
Sub Set2()
  AnArray(1001,0) = "Looong Text"
  AnArray(1001,1) = "Abv Txt"
  ...
  AnArray(2000,0) = "Looong Text"
  AnArray(2000,1) = "Abv Txt"
  Set3
End Sub
...

I have since learned that you do not want to do that anyway :-|

I now use a text file for the same data, that is about 200k in size, and save 3MB on the size of the program...
(And it still loads just as fast)

So as you can see, typically having a bloated procedure generally is a bad practice...

Try to split up your code into as many tiny, reuseable, subs and functions as you can...

In theory, you should never have to max out the size limit, if you do, you need to review your code.

Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
I have a similar dts package that I run. I didn't have to break it up because it wasn't as big, but I do see how they can get pretty large letting the wizard from sql create it.

You probably have a tons of lines such as:
Set oStep = goPackage.Steps.New
after which all of the properies are set. What I would do is create and call a seperate procedure that sets these properies, passing in the oStep object. This should reduce the number of lines by thousands. Sorry there is no easy way around it.

"Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'."
 
If this is a procedure to load a database type structure...

I STRONGLY suggest looking into XML.

You can set up A utility to convert your data into XML easily in less than 50 line of code... (usually less than 20 ;-))

then to load the XML file it takes 3 basic lines:
Code:
Set xmlDOM = New DOMDocument
xmlDOM.async = False
xmlDOM.Load ulPath

Here is a little module you can look over to get you started...
Code:
[COLOR=green]'/*****************************************/
'/*    User List XML interface Module     */
'/*  Created by: Josh Stribling 4/5/2004  */
'/*****************************************/
'/*  Modifications: Removed PDM Specific  */
'/*    Functions for use on Tek-Tips -JDS */
'/*****************************************/[/color]

Option Explicit

[COLOR=green]'*** User List Document Object Model[/color]
Public ulDOM As DOMDocument, ulDOMCreated As Boolean

Private ulPath As String

[COLOR=green]'********************************************************************
'************************** Public Functions ************************
'********************************************************************[/color]
Public Sub ulLoad()
  ulPath = GetSetting("UserListXML", "Path", "Path", "C:\My Documents\mqlusers.xml")
  
  If Dir(ulPath) <> "" Then
    Set ulDOM = Nothing
    Set ulDOM = New DOMDocument
    ulDOM.async = False
    ulDOM.Load ulPath
    ulDOMCreated = True
  Else
    ulCreate
  End If
End Sub

Public Function ulSearch(UserID As String) As String
  If Not ulDOMCreated Then ulLoad

  Dim X As IXMLDOMElement, Temp As String
  
  [COLOR=green]'Find Tag with User ID and return Name from Text[/color]
  Set X = ulDOM.documentElement.getElementsByTagName(UserID)(0)
  If X Is Nothing Then
    [COLOR=green]'Node NOT found...[/color]
    [COLOR=red]Temp = PDMGetName(UserID)[/color]
    If Temp <> "" Then
      [COLOR=green]'Return Name and add Tag to UserList[/color]
      ulSearch = Temp
      ulAdd UserID, Temp
    End If
  Else
    [COLOR=green]'Node found...
    'Return text[/color]
    ulSearch = X.Text
  End If
End Function

Public Sub ulSave()
  [COLOR=green]'Save XML data to file[/color]
  If ulDOMCreated Then
    ulDOM.save ulPath
    SaveSetting "UserListXML", "Path", "Path", ulPath
  End If
End Sub

[COLOR=green]'********************************************************************
'************************* Private Functions ************************
'********************************************************************[/color]
Private Sub ulCreate()
  [COLOR=green]'Create new DOM with <USERS> root tag...
  [b]'<USERS>
  '</USERS>[/b][/color]
  If Not ulDOMCreated Then
    Set ulDOM = Nothing
    Set ulDOM = New DOMDocument
    ulDOM.appendChild ulDOM.createElement("USERS")
    ulDOMCreated = True
    ulSave
  End If
End Sub

Private Sub ulAdd(UserID As String, UserName As String)
  [COLOR=green]'Add UserID Element with User Name to <USERS> root tag...
  '<USERS>
  [b]'  <id00001>User Name</id00001>[/b]
  '</USERS>[/color]
  If ulDOMCreated Then
    ulDOM.documentElement.appendChild(ulDOM.createElement(UserID)).Text = UserName
  End If
End Sub

This is a structure I set up to query user names from a local DB structure as opposed to querying our PDM system (which saves a lot of time)

It is automated so that if the xml file is not loaded on the first query, it loads it automatically, and if the file does not exist, it creates a new structure.

I removed a few senitive areas where I actually query the PDM if the user id is not found in the list and replaced it with a generic PDMGetName(UserID) function so you can change that to whatever you need/want, to make it work on your system...

I'm sure this won't be an imediate solution to your problem, but it can be an example of a structure that you can build on and modify to what you need...

See in the XML section for more information on this...

You will need to add the XML reference to your project...
it's usually something like:
Microsoft XML, v3.0
or something similar

Good Luck,
Josh

Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
The procedure was a dts package generated from sql server in the form of a .bas file.

OK, so it's not your fault.
;-)

I would talk to your DBA about restructuring that table (477 columns!?!?!). The other way to do it is look at what it's given you thus far and see if you can figure out it's structure so that you can manually break it up into a better form (and then add the missing part).

One other idea would be to look at what DTS has given you, and use that as a basis for a code generation routine that would output a better program structure.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top