Hi
i have been working on a project for my younger brother. A simple VB6 and MS Access/SQL server based client-server database. For that i recently started working on VB6 as i previously had only worked on Java and C++. I have been consulting the book "Using Visual Basic 6" by Brian Siler and Jeff Spotts. Problem is embarassing enough in my first programe. When i try to compile it, it shows me an error "Compile error: Method or Data member not found". Program is very basic (Loan calculator) with four text fields, four labels(Principal, Annual Interest Rate, Term Year and Monthly payment) and two command buttons(Calculate Payment & Exit). I am sure that there is nothing wrong with the declaration or the syntax as it is absolutely according to the book still i am getting this error and i cant find anything about this error online or in the book. So i am stuck and need help.Can anyone please take a look into this. I would be much obliged.

Private Sub cmdCalculate_Click()
    Dim cPrincipal As Currency
    Dim fIntRate As Single
    Dim nTerm As Integer
    Dim cPayment As Currency
        
    cPrincipal = Val(txtPrincipal.Text)
    
    fIntRate = Val(txtIntRate.Text) / 100
    
    fIntRate = fIntRate / 12
    
    nTerm = Val(txtTerm.Text) * 12
    
    cPayment = cPrincipal * (fIntRate / (1 - (1 + fIntRate) ^ -nTerm))
    txtPayment.Text = Format(cPayment, “Fixed”)
End Sub

Private Sub cmdExit_Click()
    End
    
End Sub

Check that you spelt the control name exactly the same in the code and the properties

At the top of the code window, above all other code, do you see the words "Option Explicit"? If not, add these words and press F8. Your error, when you compile, should now be highlighted. Now, in the future so that this appears automatically, goto VB's menu Tools>Options and when the dialog appears, place a check next to where it says "Require Variable Declaration". Click OK.

Good Luck

At the top of the code window, above all other code, do you see the words "Option Explicit"? If not, add these words and press F8. Your error, when you compile, should now be highlighted. Now, in the future so that this appears automatically, goto VB's menu Tools>Options and when the dialog appears, place a check next to where it says "Require Variable Declaration". Click OK.

Good Luck

Hi again,
Sorry for the delayed reply. The problem is still there. Though i have checked that Tools>Options>"Require Variable Declaration" still the problem remains the same. When i compile it same error comes up. i am attaching a printscreen of what it highlights when i break the compiling procedure, probably then you can see the problem. Thanks for your help and time. I really appreciate it.
X.

Attachments VBerror.jpg 113.76 KB

Check that you spelt the control name exactly the same in the code and the properties

Hi
I have double checked the controls again but same problem again.. Dont know what to do. Thanks for your help and time.


X

First, if Option Explicit is not at the top of the code window, type it in.
Second, delete the .text and type in the dot (.). If textPrincipal is an actual control you should see the list of properties come up.

Now, it could be that you may have accidently renamed the control or perhaps misspelled the controls name in code so here is what I want you to do...

Go to the form view and select the textbox in question. Look in the properties window at the name property.

If it looks like the correct name then go back to the code window and remove everything after the open paren of the val function (val(....). Type in textp and hold down the CTRL key and press the space bar. Your textbox name should appear in the drop down list and if so just hit the tab key. Then type in the dot (.) and text should appear in the list BUT if you see caption then you have a label named as a text box.

Good Luck

Hi,

What I guess, is txtPrincipal has been created as a Part of the Control Array.
If so, you will find some Numeric value in the "Index" property. Just Clear that, your code should work fine. Also Check the same for other controls as well..

Regards
Veena

This article has been dead for over six months. Start a new discussion instead.