Greetings everyone!
im having my final project. My program is all about retrieve data from Excel Worksheet then show/calculate it in VB6.

The problem im having here is i keep getting compile error "Procedure too large". I understand that VB6 procedure max is 64k and to make it small is by using Sub or Function modular.

The big problem is.. i have no idea how to create one. I did quite few research but still dont get it.

Does anyone have any idea how overcome my problem? Thank you in advance in helping this newbie

i've uploaded the code where got this compile error
-Zumie-

Recommended Answers

All 5 Replies

It is real easy to define a sub or function but the choice on which may be the hard part. For example...

Public Function MyFunction() As Long

End Function

Public Sub MySub()

End Sub

So your choices are...
Public/Private Function/Sub (optional argument list) as somethingoranother

End Function/Sub

Just remember, a sub does not "traditionally" return anything and a function normally only returns one thing.

Now, for further clarification on the "traditionally" statement. A sub can return many values as a function can also do but both do these indirectly (for lack of a better way to word it...)

For example...

Private Sub Command1_Click()
Dim MyInputString As String, MyOutputString As String
MyInputString = "This is a test."
MySub MyInputString, MyOutputString
MsgBox MyOutputString
End Sub

Private Sub MySub(InStr As String, OutStr As String)
OutStr = InStr
End Sub

So how/why does this work? Well in VB6.0 and vba (if I remember correctly about vba), arguements are passed by ref by default and as such, the called procedure can change those values. However, if the procedure declares the arguements ByVal then VB makes a copy of that value before the called procedure recieves it.

Now you can do the same thing with the arguements of a function if you so wish or you can leverage the power of the function to return a UDT (User Defined Type)...

Private Type MyType
  A As Integer
  B As Long
  C As Byte
End Type

Private Sub Command1_Click()
Dim T As MyType
T = ReturnMyType
End Sub

Private Function ReturnMyType() As MyType
Dim T As MyType
T.A = 1
T.B = 2
T.C = 3
ReturnMyType = T
End Function

So combining the power of the UDT Type declaration, which by the way, if you can declare it normally like Dim A As Interger, the type can hold it, and the power of a function, you can return a whole lot of information.

Now, lets talk about your large procedure...

First things to break out are those things that repeat themselves, meaning code you have that is the same in several place within your procedure. Next up would be those pieces of code that do something to find something and then return that something/value.

Good Luck

Those repeated code are all arrays...which 1 located in the Excel Worksheet while the other placed in the other form. So how to create of module of it?

By putting the retrieval and insertion of those excel cells in a procedure and pass to the procedure where you want the loop to start and end as its arguements...

Good Luck

Allright!now everything is solved.Thank you for your help vb5prgrmr.

May God bless you

Hi
In VB6, I have a Combo Command, and I made meny steps iside it, it is about 48,000 characters, and I need more !! but I got this msg: "Proceduer is too large" !!
so, what can I do to complete my steps !?
Thanks..
Sarwat.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.