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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Object does not support propperty o method"

Status
Not open for further replies.

elibb

Programmer
Oct 22, 2001
335
MX
hi, i have a vb 6.0 applications, and i have module with a function where i send an array of textboxes as a parameter:

Code:
Public Function someFunc(txt as Variant) as Integer

txt.text="this is an example"

end Function
[code]

but when i get to the line "txt.Text" i get this error: 
"Object does not support Method"

i only get the error at my clients computer, i have never gotten it myself, and its only sometimes, sometimes they just restart the application and the error is gone, does anybody have any idea of what it is? 
i tried to send it byRef but it didnt work.. 

thank you very much
Eli
 
In the example that you provided 'txt' is a variable of type variant. 'txt' does not have any properties for you to access or reference.

Try this instead,

Public Function someFunc(txt as textbox) as Integer
txt.text="this is an example"
end Function


Thanks and Good Luck!

zemp
 
well actually i posted it wrong, i meant

Code:
txt(1).text="hi"

because txt is an array of text objects... how do i declare that?

thank you very much.
 
Try this declaration, add the array brakets,

Public Function someFunc(txt() as textbox) as Integer


Thanks and Good Luck!

zemp
 
Well, actually it depends on how he is passing the value to the function. Most likely he is not passing an object ( textbox ), but something else.

Public Function someFunc(txt as Variant) as Integer
txt.text="this is an example"
End Function

This will work fine, if you call the function correctly.

someFunc txtMyTextBox

with txtMyTextBox being the name of the textbox control you want to effect.

Declaring the arguement as a textbox is a better programming practice, if that's all that you will be passing to the function.

Robert
 
i did what you told me, and declared it like this:

Code:
Public Function someFunc(txt as Variant) as Integer
    txt.text="this is an example"
End Function

but i got a compiling error saying an array was expected, and i am sending the name of the array.

thats why i was using Variant, but i still get the error of "Object does not support this property or method", but as i said i only get it sometimes, i havent been able to discover the pattern, sometimes i just have to close the application and start it again and it works fine.

thank you very much

Eli
 
I did some research, this is what I found. Create a control array of text boxes (named 'TextArray' in this example). Set up your function like this,

Public Function someFunc(txt As Object) As Integer
txt(1).text = "this is an example"
'or
'txt(txt.ubound).text = "this is an example"
End Function

Call the function using the control array as a prameter like this,

someFunc TextArray()

You can also use a for-each statement to loop through the array and/or it's lbound and ubound properties.

Thanks and Good Luck!

zemp
 
"thats why i was using Variant, but i still get the error of "Object does not support this property or method", but as i said i only get it sometimes, i havent been able to discover the pattern, sometimes i just have to close the application and start it again and it works fine."

Which just reinforces what I stated. It's not the function itself that's causing the problem, it's the data he is passing to it. On occasion, it's not getting a textbox passed to it, but something else ( since the arguement being declared as variant will accept anything ). He needs to direct his debugging efforts towards this.

Robert
 
thank you very much for all your answers, but i couldnt solve the problem.. i keep getting the same error.

ill keep trying..

new ideas accepted..

thank you very much

Eli
 
elibb, while I was testing I did get all the errors that you mentioned. Until I found the code in my last post. It works. The differences are that the parameter is of type 'Object' and not variant, and when you call the procedure you need to include the brakets with the control array name. It should work for you as well.

Thanks and Good Luck!

zemp
 
thank you zemp, i tried what you told me again (i dont know what i did wrong last time) and it seems to work.. i wont know for sure until i test it in my clients computer, as i said i only get the error there. But i hope it works fine now...

thank you very much.

Eli
 
Glad to hear that you got it working.

Thanks and Good Luck!

zemp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top