Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default 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" wrote in message
ups.com...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default Class Module Question

"Andrew Yates" wrote in message
oups.com...
"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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default Class Module Question

"Andrew Yates" wrote in message
ups.com...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
CLASS MODULE & SIMPLE MODULE FARAZ QURESHI Excel Discussion (Misc queries) 1 September 7th 07 09:32 AM
Chart Class Module/follow on question to hyperlink post earlier. Rominall Charts and Charting in Excel 2 March 7th 07 02:43 AM
class module? sybmathics Excel Programming 17 February 25th 06 02:29 PM
Class module question David Excel Programming 4 September 8th 05 04:51 PM
Variable from a sheet module in a class module in XL XP hglamy[_2_] Excel Programming 2 October 14th 03 05:48 PM


All times are GMT +1. The time now is 11:33 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"