For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic Syntax > February 2005 > Object Required when using set









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Object Required when using set
Luis Feliz

2005-02-08, 4:01 am

Guys -

I keep getting "object required" when running this code.

All the variables are defined, cant understand why the set command would
fail.

Thanks in advance,

Luis Feliz

-------------------------- Start Code ---------------------
'This is Form1
Dim MyMsgs as MsgArr

Private Sub Command2_Click()

GetMessages MyMsgs

End Sub

---------------------------------------------

'This is on module1.bas

Option Explicit

'Definitions

Type EmailMsg
sTo As String
StoName As String
sFrom As String
sFromName As String
sSubject As String
sMessage As String
sHeaders As String
sSource As String
End Type

Public Type MsgArr
Email(0 To 100) As EmailMsg
Count As Integer
End Type

Dim Msgs As MsgArr

Public Sub GetMessages(ByRef em As MsgArr)

Set Msgs = em <--------Error Happens here
(Object Required)
msgs.count = 0

End Sub


Greg Teets

2005-02-08, 4:01 am

On Tue, 08 Feb 2005 05:30:45 GMT, "Luis Feliz" <luisfeliz@verizon.net>
wrote:

>Guys -
>
>I keep getting "object required" when running this code.
>
>All the variables are defined, cant understand why the set command would
>fail.
>
>Thanks in advance,
>
>Luis Feliz
>
>-------------------------- Start Code ---------------------
>'This is Form1
>Dim MyMsgs as MsgArr
>
>Private Sub Command2_Click()
>
> GetMessages MyMsgs
>
>End Sub
>
>---------------------------------------------
>
>'This is on module1.bas
>
>Option Explicit
>
>'Definitions
>
>Type EmailMsg
> sTo As String
> StoName As String
> sFrom As String
> sFromName As String
> sSubject As String
> sMessage As String
> sHeaders As String
> sSource As String
>End Type
>
>Public Type MsgArr
> Email(0 To 100) As EmailMsg
> Count As Integer
>End Type
>
>Dim Msgs As MsgArr
>
>Public Sub GetMessages(ByRef em As MsgArr)
>
> Set Msgs = em <--------Error Happens here
>(Object Required)
> msgs.count = 0
>
>End Sub
>



You forgot to declare your variable 'em'.

Set is only used with objects. Otherwise, you can just use "=".


Greg Teets
Cincinnati Ohio USA
Jeff Johnson [MVP:VB]

2005-02-08, 4:01 am


"Luis Feliz" <luisfeliz@verizon.net> wrote in message
news:98YNd.10979$ya6.5014@trndny01...

> I keep getting "object required" when running this code.


> Dim Msgs As MsgArr
>
> Public Sub GetMessages(ByRef em As MsgArr)
>
> Set Msgs = em <--------Error Happens here
> (Object Required)


Arrays aren't objects; you can't use Set on them.


Bob O`Bob

2005-02-09, 9:00 pm

Luis Feliz wrote:

> Guys -
>
> I keep getting "object required" when running this code.
>
> All the variables are defined, cant understand why the set command would
> fail.
>
> Thanks in advance,
>
> Luis Feliz
>
> -------------------------- Start Code ---------------------
> 'This is Form1
> Dim MyMsgs as MsgArr
>
> Private Sub Command2_Click()
>
> GetMessages MyMsgs
>
> End Sub
>
> ---------------------------------------------
>
> 'This is on module1.bas
>
> Option Explicit
>
> 'Definitions
>
> Type EmailMsg
> sTo As String
> StoName As String
> sFrom As String
> sFromName As String
> sSubject As String
> sMessage As String
> sHeaders As String
> sSource As String
> End Type
>
> Public Type MsgArr
> Email(0 To 100) As EmailMsg
> Count As Integer
> End Type
>
> Dim Msgs As MsgArr
>
> Public Sub GetMessages(ByRef em As MsgArr)
>
> Set Msgs = em <--------Error Happens here
> (Object Required)
> msgs.count = 0
>
> End Sub
>
>



I'm not sure I follow quite what you're trying to do,
but it looks like maybe what you really want is LSet.



Bob
ssta

2005-02-13, 9:01 pm

You don't need to use Set to with a UDT (Type ... End Type)

Luis Feliz wrote:
> Guys -
>
> I keep getting "object required" when running this code.
>
> All the variables are defined, cant understand why the set command would
> fail.
>
> Thanks in advance,
>
> Luis Feliz
>
> -------------------------- Start Code ---------------------
> 'This is Form1
> Dim MyMsgs as MsgArr
>
> Private Sub Command2_Click()
>
> GetMessages MyMsgs
>
> End Sub
>
> ---------------------------------------------
>
> 'This is on module1.bas
>
> Option Explicit
>
> 'Definitions
>
> Type EmailMsg
> sTo As String
> StoName As String
> sFrom As String
> sFromName As String
> sSubject As String
> sMessage As String
> sHeaders As String
> sSource As String
> End Type
>
> Public Type MsgArr
> Email(0 To 100) As EmailMsg
> Count As Integer
> End Type
>
> Dim Msgs As MsgArr
>
> Public Sub GetMessages(ByRef em As MsgArr)
>
> Set Msgs = em <--------Error Happens here
> (Object Required)
> msgs.count = 0
>
> End Sub
>
>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com