Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Trying to create a class
Message
From
27/11/2001 14:42:03
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Title:
Trying to create a class
Miscellaneous
Thread ID:
00586547
Message ID:
00586547
Views:
47
This is my first foray into creating a class. I have done some reading but I am still confused. The outcome of this is that I want to be able to creat a .com object. I got the following code from a VFP 6 book, it was labelled as "Source Code for the Timesheet Program Exported from the Class Browser". My question is this: How do I create a class to begin with...and how do I add the following code to it? I tried simply running this code to create a class with no success. Any help would be greatly appreciated.
DEFINE CLASS timetrans AS line

	Height = 17
	Width = 100
	cclient = ("")
	cdescription = ("")
	*--Service Code
	cservice = ("")
	*--Billing Amount
	namount = 0.00
	nrate = 0.00
	*--The employee who did the work
	cemployee = ("")
	*--Date of service
	ddate = {}
	*--Hours worked
	nhours = 0.00
	Name = "timetrans"

	PROTECTED PROCEDURE CDESCRIPTION_ASSIGN
		LPARAMETERS vNewVal

	*--Our billing program only prints up to 600 characters for the description

		IF LEN(vNewVal) > 600
			vNewVal = LEFT(vNewVal, 600)
		ENDIF
		this.cdescription = m.vNewVal
	ENDPROC

	*--sAVES A TRANSACTION TO THE TABLE
	PROCEDURE save
	LOCAL lnSelect
	lnSelect = Select()

	IF !USED("tsTrans")
		USE tstrans
	ENDIF

	SELECT tstrans
	APPEND BLANK

	WITH this
		REPLACE ;
			cemployee WITH .cemployee, ;
			ddate WITH .ddate, ;
			cclient with .cclient, ;
			cservice WITH .cservice, ;
			mDesc WITH .cdescription, ;
			nhours with .nhours, ;
			nrate WITH .nrate, ;
			namount WITH .namount
	ENDWITH

	SELECT (lnSelect)
ENDPROC

	*--Clears out everything for a new record to be defined
	PROCEDURE add
	WITH this
		.ddate = {}
		.cclient = ""
		.cservice = ""
		.cdescription = ""
		.nhours = 0.00
		.nrate = 0
		.namount = 0
		.cemployee = ""
	ENDWITH
ENDPROC

	PROTECTED PROCEDURE cservice_assign
		LPARAMETERS vNewVal

	*--When we get a service in, we need to get the rate so we can do the math on it and then
	*--save it to the table.

		LOCAL lnSelect, lcOldExact
		lsSelect = SELECT()

		this.cservice = vNewVal

	*--Check that we got a character value

		IF TYPE("vNewVal") # "C"
			IF INLIST(_vfp.startmode, 1,2,3)
				this.cStatus = "cService Error"
			ELSE
				MESSAGEBOX("cService expects a CHARACTER type value.", 16)
			ENDIF
			RETURN
		ENDIF

		IF !USED("services")
			USE services
		ENDIF

		SELECT services
		SET ORDER TO service

		lcOldExact = SET("exact")
		SET EXACT ON
		SEEK UPPER(ALLTRIM(vNewVal))

		IF !FOUND() OR EMPTY(vNewVal)
			this.nrate = services.nrate
		ENDIF

		SET EXACT &lcOldExact
		SELECT (lnSelect)
	ENDPROC

	PROTECTED PROCEDURE nrate_asign
		LPARAMETERS vNewVal

	*--Calculate the billing amount for this number

		this.nrate = vNewVal

		IF TYPE("vNewVal") # "N"
			IF INLIST(_vfp.startmode, 1,2,3)
				this.cStatus = "Rate Error"
			ELSE
				MESSAGEBOX("nRate expects a NUMERIC type value.", 16)
			ENDIF
		ELSE
			this.namount = this.nrate * this.nhours
		ENDIF
	ENDPROC

	PROTECTED PROCEDURE nhours_assign
		LPARAMETERS vNewVal

	*--Calculate the billing amount for this number

		this.nhours = vNewVal

		IF TYPE("vNewVal") # "N"
			IF INLIST(_vfp.startmode, 1,2,3)
				this.cStatus = "Hours Error"
			ELSE
				MESSAGEBOX("nHours expects a NUMERIC type value.", 16)
			ENDIF
		ELSE
			this.namount = this.nrate * this.nhours
		ENDIF
	ENDPROC

ENDDEFINE
*
*--EndDefine: timetrans
Here's to alcohol...the cause of ... and solution to ... all of life's problems - - Homer J. Simpson
Next
Reply
Map
View

Click here to load this message in the networking platform