?
Solved

Call a Function Procedure

Posted on 2003-03-13
17
Medium Priority
?
292 Views
Last Modified: 2010-08-05
Hello

im am using vb6 i have written a function and have tried to call it but i receie a function not defined error. Can someone please have a look and let me know what im doing wrong

This is my function

Private Function LoadRecordSetIntoGrid(flexgrid As MSFlexGrid, rsOrders As ADODB.Recordset) As Boolean

Dim sTmp As String
Dim vArr As Variant
Dim i As Integer

On Error GoTo HandleError
    'first we have to clear the grid from previous query results
    '**** remove existing grid rows
    flexgrid.Rows = 2
    flexgrid.AddItem ""
    flexgrid.RemoveItem 1
   
    If Not rsOrders.EOF And Not rsOrders.BOF Then
        'get the recordset into a string delimiting the fields
        'with a tab character and the records with a semicolon
        'replace nulls with a space
        sTmp = rsOrders.GetString(adClipString, , Chr(9), ";", " ")
 
        'split the string into an array of individual records
        vArr = Split(sTmp, ";")
       
        'now add the records to the grid
        For i = 0 To UBound(vArr) - 1
            flexgrid.AddItem vArr(i)
        Next
        'set the return value
        LoadRecordSetIntoGrid = True
    Else
        LoadRecordSetIntoGrid = False
        Exit Function
    End If
    'remove empty rows
    If flexgrid.Rows > 2 Then
        On Error Resume Next
        For i = 1 To flexgrid.Rows - 1
            If flexgrid.TextMatrix(i, 1) = "" Then
                flexgrid.RemoveItem i
                flexgrid.RemoveItem i
            Else
                Exit For
            End If
        Next
    End If
 
    Exit Function
   
ErrorHandler:   
    LoadRecordSetIntoGrid = False
End Function
 

This is how I have called it
  Call LoadRecordSetIntoGrid(flxCustomerOrders, rsOrder)

Thank You Im hoping someone can help
0
Comment
Question by:newToVB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
  • +4
17 Comments
 
LVL 101

Accepted Solution

by:
mlmcc earned 120 total points
ID: 8132850
First where did you define the function?  If it was in a module or on a form other than the form you are calling it from it must be Public

Public Function LoadRecordSetIntoGrid(flexgrid As MSFlexGrid, rsOrders As ADODB.Recordset) As Boolean

the other problem might be you built it as a function but are calling it as a procedure.
Dim boolGridLoaded as Boolean
boolGridLoaded = LoadRecordSetIntoGrid(flxCustomerOrders, rsOrder)

mlmcc
0
 

Expert Comment

by:WHalphen
ID: 8132932
If you don't need the boolean results, you can call it without the parenthesis, as follows:

LoadRecordSetIntoGrid flxCustomerOrders, rsOrder


0
 

Author Comment

by:newToVB
ID: 8133054
I have defined the function within the form itself. I have tried declaring the boolean value but still no luck, getting the same error sub or function not defined.
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 8133142
since it is a Function, it will return a VALUE, of type Boolean, so you would probably want to declare a Variable to receive the returned value:

Dim blnMyValue as Boolean

blnMyValu = LoadRecordSetIntoGrid(flxCustomerOrders, rsOrder)

or you can use it like this:

If LoadRecordSetIntoGrid(flxCustomerOrders, rsOrder) then
    'do one thing if True
Else
    'do another thing if false
End If

and the point about the Private in the declaraion is quite correct.  If the Function is defined within the SAME module where your code resides, then you can access it.  But if the Function is defined in ANOTHER module, then it is COMPLETELY inaccessible from any code OUTSIDE that other module---That is what PRIVATE means.

If you want to be able to use the code from outside the Moduel where the code is defined, then you must use the Qualified Public as mlmcc pointed out, above.



0
 

Author Comment

by:newToVB
ID: 8133182
If have added the variable and made it equal to the function as you said but i still get the error, i cannot see anything wrong with it. It stops at the function header line. This seems really weird?

I checked the function call and it does get the data from the flexgrid but wont go into the function for some reason.. Any other ideas?

Private Function LoadRecordSetIntoGrid(flexgrid As MSFlexGrid, rsOrders As ADODB.Recordset) As Boolean
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 8133205
when you Run the code, What line is highlighted when the error message appears?

AW
0
 

Expert Comment

by:errorx666
ID: 8133221
Try declaring the function as Public instead of Private.
0
 

Author Comment

by:newToVB
ID: 8133529
If have added the variable and made it equal to the function as you said but i still get the error, i cannot see anything wrong with it. It stops at the function header line. This seems really weird?

I checked the function call and it does get the data from the flexgrid but wont go into the function for some reason.. Any other ideas?

Private Function LoadRecordSetIntoGrid(flexgrid As MSFlexGrid, rsOrders As ADODB.Recordset) As Boolean
0
 

Expert Comment

by:WHalphen
ID: 8133756
Try removing all the content from your function and see if it works like this:

Private Function LoadRecordSetIntoGrid(flexgrid As MSFlexGrid, rsOrders As ADODB.Recordset) As Boolean
   LoadRecordSetIntoGrid = True
End Function

If not, then there is a problem with the function declaration.  Try using a different name, or make it Public, or ???

If it does work, then try adding back the content bit by bit until you get the error again.

Another idea: Check the parameter declarations by changing it to:

Private Function LoadRecordSetIntoGrid(flexgrid As Object, rsOrders As Object) As Boolean

Hope this helps...
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 8133849
Try it without the parameters

Private Function LoadRecordSetIntoGrid() As Boolean
  LoadRecordSetIntoGrid = True
End Function

mlmcc
0
 

Expert Comment

by:errorx666
ID: 8134029
' Old Code :
' Private Function LoadRecordSetIntoGrid(flexgrid As MSFlexGrid, rsOrders As ADODB.Recordset) As Boolean
'
' New Code :
' Public Function LoadRecordSetIntoGrid(flexgrid As MSFlexGrid, rsOrders As ADODB.Recordset) As Boolean
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8134380
The LoadRecordSetIntoGrid () function has no default return-value, which it must have. I mean, you're assigning a return-value to it only in if-else statements, and so, the compiler doesn't know whether actually, that function will return a defined value or not. Try chaging all the:

LoadRecordSetIntoGrid = True

and

LoadRecordSetIntoGrid = False

statements into:

temp = True

and

temp = False

where temp is a boolean local variable, initially assigned to say, False.

Then, at the end of the function (just before the 'End Function' statement), write:

LoadRecordSetIntoGrid = temp (not inside any if-else).


It must run!!

Mayank.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 8135893
the fact that "It stops at the function header line. ", indicates that there is a line IN THAT FUNCTION, that the compiler THINKS is an UNDEFINED function, not the function itself, as you are clearly getting to THAT line.

Try RUNING with a FULL COMPILE, (ctrl-F5, not simply F5), and see if that helps to identify where the error line exists?

AW
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 8136407
You are deleting rows twice.

   If flexgrid.Rows > 2 Then
       On Error Resume Next
       For i = 1 To flexgrid.Rows - 1
           If flexgrid.TextMatrix(i, 1) = "" Then
               flexgrid.RemoveItem i
               flexgrid.RemoveItem i
           Else
               Exit For
           End If
       Next
   End If

delete the second flexgrid.RemoveItem i

mlmcc
0
 

Expert Comment

by:CleanupPing
ID: 9447154
newToVB:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 9472022
Split: mlmcc, Arthur_Wood and mayankeagle
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question