Jump to content
Developer Wiki and Function Reference Links ×

Create classes from worksheet


tca

Recommended Posts

Hi,

I'm looking for a way to create classes from a worksheet.

We have an extensive program for a large hospital project. We've created a list of classes we would like to use to structure that program in VW.

The list is currently in excel but could easily be pasted in a VW worksheet were a script could pick it up and generate classes with the names from the worksheet.

Unfortunately I'm not able to script this myself.

I've attached the VW worksheet.

any ideas?

Link to comment

This should do it.

Open the worksheet. Select the range of cells you want to use to create classes. Run the script.

I'll also attach the file in 2015 and 2016.

hth

mk

Procedure CreateClasssesFromWorksheet;
{Badly scripted by Michael Klaers}
{Open a worksheet.  Select a cell or range of cells.  Run this script.}
{This script will create a class using the contents of the cells as names.}

VAR

WSHand		: Handle; 				{Handle to Worksheet}

topRow,leftColumn,bottomRow,rightColumn  :INTEGER;

currentCellRow,currentCellColumn,topRangeRow,leftRangeColumn,topRangeSubrow,bottomRangeRow,rightRangeColumn,bottomRangeSubrow   :INTEGER;

LoopColumn,LoopRow	:INTEGER;

ClassNameinWorksheet  :STRING;

BEGIN
WSHand:=GetTopVisibleWS;

GetWSSelection(WSHand,currentCellRow,currentCellColumn,topRangeRow,leftRangeColumn,topRangeSubrow,bottomRangeRow,rightRangeColumn,bottomRangeSubrow);


For    LoopColumn := leftRangeColumn TO rightRangeColumn
DO	BEGIN

		FOR LoopRow :=	topRangeRow TO bottomRangeRow
		DO	BEGIN


			GetWSCellString(WSHand,LoopRow,LoopColumn,ClassNameinWorksheet);
			If ClassNameinWorksheet <> ''
			THEN
			NameClass(ClassNameinWorksheet);

			END;
	END;

END;


RUN(CreateClasssesFromWorksheet);

 

classes_v2015.vwx

classes_v2016.vwx

  • Like 2
Link to comment

It was mostly luck :-)

I'm a pretty bad scripter, but I already had a script that queried every selected cell in a worksheet. From there it only takes 2 lines of script to get the text from the cell and create a class.

Wish they were all that easy.

I'm glad it works for what you need.

mk

Link to comment
  • 11 months later...

This script should do it.

 

Put the class names you want in column A.  Put the descriptions in column B.  

 

Leave the worksheet open.  Run the script.

 

PROCEDURE CreateClasssesFromWorksheet;
{Badly scripted by Michael Klaers}
{Open a worksheet.  Run this script.}
{This script will create a class using the contents of the cells in Column A as names.}
{The contents of Column B will be the desciption for the class in Column A of the same row.}


VAR
	
	WSHand,ClassHandle									:HANDLE; 				

	LoopRow												:INTEGER;

	ClassNameinWorksheet,ClassDescriptioninWorksheet	:STRING;
	
	BResult, IsThisACell								:BOOLEAN;

BEGIN
	WSHand:=GetTopVisibleWS;
		
		IsThisACell := TRUE;
		LoopRow := 1;
            
			WHILE (IsThisACell) 
			DO	BEGIN
				
				
				GetWSCellString(WSHand,LoopRow,1,ClassNameinWorksheet);
				GetWSCellString(WSHand,LoopRow,2,ClassDescriptioninWorksheet);
				If ClassNameinWorksheet <> ''
					THEN
					NameClass(ClassNameinWorksheet);
					ClassHandle := GetObject(ClassNameinWorksheet);
					BResult := SetDescriptionText(ClassHandle, ClassDescriptioninWorksheet);
					IsThisACell:=IsValidWSCell(WSHand,LoopRow + 1,1);
					LoopRow := LoopRow + 1;
				
				END;
		
	
END;


RUN(CreateClasssesFromWorksheet);

 

 

Link to comment
  • 2 years later...

I haven't tried it, but I wonder if it would be possible to make the worksheet entries for the class attributes human readable.  Perhaps.

 

Check out this thread:  

 

 

At the end of the thread is a script that uses the graphic attributes of a selected object to create a class with the objects attributes and one to edit the graphic attributes of a class.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...