+ Reply to Thread
Results 1 to 9 of 9

Class Module Question

  1. #1
    Andrew Yates
    Guest

    Class Module Question

    Hi there,

    I've received some software that I am trying to automate and by the
    looks of it, I need to use Class Modules.

    So after reading up about what Class modules are, I finally have come
    to a point where I have a very slight understanding what is happening.

    Anyway, I've got to a point where the code looks like it is almost
    working (I think). Could somebody please have a look at the below code
    and let me know what the logic flaw is.

    ===============
    Module code
    ===============
    Public Class1 As New classmodule1

    sub TransferFile()


    With Class1
    .send
    End With
    End Sub

    ===============================================
    Class Module code - the class is called classmodule1
    ===============================================
    Dim WithEvents mSession As BS.Session
    Dim mCancelCommand As Boolean
    Dim mFileName As String

    Public Sub send()
    mCancelCommand = False
    mFileName = "file1234"

    mSession.SENDFROMFILE mFileName ' this is where it is crashing

    End Sub

    I am receiving the following error:
    "Object variable or With block variable not set" and it is crashing at
    the " mSession.SENDFROMFILE mFileName" line. The value of mSession =
    nothing which I assume is the problem but as would be quite apparent to
    anybody reading this far, I don't have a clue.



    Any assistance is much appreciated.

    Regards,
    Andrew


  2. #2
    John Gunther
    Guest

    Re: Class Module Question

    Try replacing your line:

    Dim WithEvents mSession As BS.Session

    With the line:

    Dim WithEvents mSession As New BS.Session

    John


  3. #3
    Rob Bovey
    Guest

    Re: Class Module Question

    Hi Andrew,

    If the code you've shown is complete, the error is being caused because
    you never assign an instance of the BS.Session class to your mSession
    variable. Try adding the following event procedure to your class module.

    Private Sub Class_Initialize()
    Set mSession = New BS.Session
    ''' If the above gives an error, try this instead:
    'Set mSession = CreateObject("BS.Session")
    End Sub

    This will run automatically as soon as an instance of the class is created.
    If there are any other things you need to do to your mSession object in
    order to get it into shape for using in your code, add them to this event.

    --
    Rob Bovey, Excel MVP
    Application Professionals
    http://www.appspro.com/

    * Take your Excel development skills to the next level.
    * Professional Excel Development
    http://www.appspro.com/Books/Books.htm

    "Andrew Yates" <[email protected]> wrote in message
    news:[email protected]...
    > Hi there,
    >
    > I've received some software that I am trying to automate and by the
    > looks of it, I need to use Class Modules.
    >
    > So after reading up about what Class modules are, I finally have come
    > to a point where I have a very slight understanding what is happening.
    >
    > Anyway, I've got to a point where the code looks like it is almost
    > working (I think). Could somebody please have a look at the below code
    > and let me know what the logic flaw is.
    >
    > ===============
    > Module code
    > ===============
    > Public Class1 As New classmodule1
    >
    > sub TransferFile()
    >
    >
    > With Class1
    > .send
    > End With
    > End Sub
    >
    > ===============================================
    > Class Module code - the class is called classmodule1
    > ===============================================
    > Dim WithEvents mSession As BS.Session
    > Dim mCancelCommand As Boolean
    > Dim mFileName As String
    >
    > Public Sub send()
    > mCancelCommand = False
    > mFileName = "file1234"
    >
    > mSession.SENDFROMFILE mFileName ' this is where it is crashing
    >
    > End Sub
    >
    > I am receiving the following error:
    > "Object variable or With block variable not set" and it is crashing at
    > the " mSession.SENDFROMFILE mFileName" line. The value of mSession =
    > nothing which I assume is the problem but as would be quite apparent to
    > anybody reading this far, I don't have a clue.
    >
    >
    >
    > Any assistance is much appreciated.
    >
    > Regards,
    > Andrew
    >




  4. #4
    Andrew Yates
    Guest

    Re: Class Module Question

    Hi John,

    When I try this, I receive an error "invalid use of new keyword".
    Thanks for your suggestion though.

    Regards,
    Andrew


  5. #5
    Andrew Yates
    Guest

    Re: Class Module Question

    Hi Rob,

    "Set mSession = New BS.Session " caused an invalid use of new keyword
    error.
    "Set mSession = CreateObject("BS.Session") " causes an "automation
    error, unspecified error".

    Your suggestions are very much appreciated.

    Regards,
    Andrew


  6. #6
    Rob Bovey
    Guest

    Re: Class Module Question

    "Andrew Yates" <[email protected]> wrote in message
    news:[email protected]...
    > "Set mSession = New BS.Session " caused an invalid use of new keyword
    > error.
    > "Set mSession = CreateObject("BS.Session") " causes an "automation
    > error, unspecified error".


    Hi Andrew,

    Are you sure this BS.Session object is designed to be used from VBA? Are
    you able to reference the BS object library (or whatever its friendly name
    is) using the Tools/References menu?

    I don't know anything about what the BS.Session object is, but if it is
    designed to work with VBA then either it doesn't expose events that you can
    trap using the WithEvents keyword in your variable declaration or it's not a
    creatable class, which means you need to go through some other object in the
    BS object library in order to get a reference to it.

    --
    Rob Bovey, Excel MVP
    Application Professionals
    http://www.appspro.com/

    * Take your Excel development skills to the next level.
    * Professional Excel Development
    http://www.appspro.com/Books/Books.htm



  7. #7
    Andrew Yates
    Guest

    Re: Class Module Question

    Rob,

    I am able to reference the BS object library and am pretty sure that it
    is designed to used from VBA but could be wrong. In the manual, they
    make the comment "The BSAPI is exposed as a set of Component Object
    Model (COM) objects that are accessible from other COM compatible
    applications".
    By the looks of it, bs.ession object is not a createable class and I
    will need to go to the BS object library in order to reference it some
    other way. Is there a way that I can tell via the object library
    whether something is a creatable class.

    Regards,
    Andrew


  8. #8
    Andrew Yates
    Guest

    Re: Class Module Question


    Andrew Yates wrote:
    > Rob,
    >
    > I am able to reference the BS object library and am pretty sure that it
    > is designed to used from VBA but could be wrong. In the manual, they
    > make the comment "The BSAPI is exposed as a set of Component Object
    > Model (COM) objects that are accessible from other COM compatible
    > applications".
    > By the looks of it, bs.ession object is not a createable class and I
    > will need to go to the BS object library in order to reference it some
    > other way. Is there a way that I can tell via the object library
    > whether something is a creatable class.
    >
    > Regards,
    > Andrew


    Rob (or anybody else who may be able to point an amateur in the right
    direction),

    Through trial an error and interpreting your comments, I was able to
    get through the previous error point:

    Dim mSession As BS.Session ' changed this in line with your prior
    comments

    Public Sub send()
    Set mSession = CreateObject("BS.Session")
    mFileName = "12345"
    mCancelCommand = False
    mSession.SendFromFile mFileName ' it is now crashing here
    End Sub

    So the script is now crashing at the "mSession.SendFromFile mFileName"
    line with the error being java.lang.NullPointerException. I did a bit
    of research on this error but it seems to be java related. I didn't
    even know I was doing anything relating to Java. Is there a simple
    answer to the above or is it too specific to the application that I'm
    trying to work with.

    Regards,
    Andrew


  9. #9
    Rob Bovey
    Guest

    Re: Class Module Question

    "Andrew Yates" <[email protected]> wrote in message
    news:[email protected]...
    > Public Sub send()
    > Set mSession = CreateObject("BS.Session")
    > mFileName = "12345"
    > mCancelCommand = False
    > mSession.SendFromFile mFileName ' it is now crashing here
    > End Sub
    >
    > So the script is now crashing at the "mSession.SendFromFile mFileName"
    > line with the error being java.lang.NullPointerException. I did a bit
    > of research on this error but it seems to be java related. I didn't
    > even know I was doing anything relating to Java. Is there a simple
    > answer to the above or is it too specific to the application that I'm
    > trying to work with.


    Hi Andrew,

    The error message indicates the component you're working with was
    written in Java. Without knowing anything about this component, my first
    guess is that mFileName must contain a valid file name, probably including
    the full path to where that file is located.

    --
    Rob Bovey, Excel MVP
    Application Professionals
    http://www.appspro.com/

    * Take your Excel development skills to the next level.
    * Professional Excel Development
    http://www.appspro.com/Books/Books.htm



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1