• Welcome to Theos PowerBasic Museum 2017.

I created a sample class, but its full of errors - so here are questions:

Started by Murray Ruggiero, January 03, 2011, 05:27:18 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Murray Ruggiero

Here is a fragment of some code I wrote.  It is full of errors.  If anyone can explains some or all of them, that would be great:

#COMPILE EXE
#DIM ALL

#INCLUDE ONCE "WIN32API.INC"  ' include windows api calls
MACRO BOOLEAN = INTEGER
MACRO TRUE = -1
MACRO FALSE = 0

$MyClassGuid = "{2e4ff4cf-776c-4bb4-bef5-1daad3362511}"
$MyInterfaceGuid = "{243c8ee5-35ae-4c17-a4d8-a2952cdcac3c}"

CLASS c_ClassTryTranslatingThis $MyClassGuid as COM
  INTERFACE i_ClassTryTranslatingThis $MyInterfaceGuid
  INHERIT AUTOMATION

LETS STOP HERE, I ALREADY GET AN ERROR: WHICH IS:
' CLASS c_ClassTryTranslatingThis $MyClassGuid AS COM  - invalid string length !
APPARENTLY THERE IS SOMETHING WRONG WITH THE GUID STRING

NOW LETS CONTINUE:
Private Type myStructTypeWithString
   strfield As String
   intField As Integer
End Type
THE ABOVE IS REJECTED.
SO I GET RID OF THE 'PRIVATE' PREFIX AND GET ANOTHER ERROR: 'ERROR 476 :  Block/scanned statements NOT allowed here

ALSO: CONSTANTS CANNOT BE DECLARED WITHIN THE CLASS - I GET AN ERROR FOR THAT.

ALSO, THE FOLLOWING LINE IS REJECTED: 
METHOD getCurrency() PRIVATE  As Currency
AS IS THIS ONE:
  MsgBox EXE & Str$(59.7) 
   
Basically, I want to create a class that can be used as a com object from other classes, and I want the other classes to be able to pass UDTs (user-defined-types) to the METHOD, and the logical place to define those UDTs seems to be in the class, and I want some methods to be PRIVATE (but the private keyword above did not work) and others EXPORT.   
Any advice is appreciated.


Edwin Knoppert

I am sure the help can, seems you totally avoided the help to learn some syntax and dumped some vb code in your editor?

José Roca

Yes, it looks VB-like code.

Quote
LETS STOP HERE, I ALREADY GET AN ERROR: WHICH IS:
' CLASS c_ClassTryTranslatingThis $MyClassGuid AS COM  - invalid string length !
APPARENTLY THERE IS SOMETHING WRONG WITH THE GUID STRING

They must defined as:

$MyClassGuid = GUID$("{2e4ff4cf-776c-4bb4-bef5-1daad3362511}")
$MyInterfaceGuid = GUID$("{243c8ee5-35ae-4c17-a4d8-a2952cdcac3c}")

Quote
SO I GET RID OF THE 'PRIVATE' PREFIX AND GET ANOTHER ERROR: 'ERROR 476 :  Block/scanned statements NOT allowed here

You can't use dynamic strings in an structure. You have to change strfield As String to strfield As String * number of characters.

Quote
ALSO, THE FOLLOWING LINE IS REJECTED:
METHOD getCurrency() PRIVATE  As Currency

Remove PRIVATE.

Quote
AS IS THIS ONE:
  MsgBox EXE & Str$(59.7) 

Change it to MsgBox EXE.PATH$ & Str$(59.7)

Peter Weis

Hi Murray,
Look at the power basic assistance. It may help you further. You wanted a private method. A CLASS method is private

Quote
What is a Class Method?
A CLASS METHOD is one which is private to the class in which it is located.  That is, it may only be called from a METHOD or PROPERTY in the same class.  It is invisible elsewhere.  The CLASS METHOD must be located within a CLASS block, but outside of any INTERFACE blocks. This shows it is a direct member of the class, rather than a member of an interface.

CLASS MyClass
 INSTANCE MyVar AS LONG

 CLASS METHOD MyClassMethod(BYVAL param AS LONG) AS STRING
   METHOD = "My" + STR$(param + MyVar)
 END METHOD

 INTERFACE MyInterface
   INHERIT IUNKNOWN
   METHOD MyMethod()
     Result$ = ME.MyClassMethod(66)
   END METHOD
 END INTERFACE
END CLASS


Regards Peter

Edwin Knoppert

Don't forget the hidden feature to hide a whole interface.
ActiveX allows you to have multiple interfaces in a single class.