Welcome to Foxite.COM Community Weblog Sign in | Join | Help



Fully Justify an RTF



A question has been raised before whether we can fully justify in an RTF control but I am currently busy with enhancing my classes plus creating new ones I can think of to add beauty to a form’s appearance that I simply tuck this question away at the back of my mind for later retrieval and playing.

So after the 8 classes is posted, I opened up my RTF control here and much to my dismay, I believe it really is impossible to do that as even copy-pasting a fully justified document from word into the RTF control automatically converts fully-justified paragraphs into a left justified one.  Even importing from a doc or docx (please see my previous posts on how this can be done) have the same result.  So I gave up finding out how in an RTF control.

 

Nevertheless, if we cannot do that in an RTF control on a form, at least we can do that when we export the RTF control’s contents (TextRTF property) into a doc file or simply saves it as an outside RTF from a memo field.  In that way, our document is presented better.

 

The trick to make it proper is to only apply full justifications on left-justified paragraphs.  We should not touch Right and Center justified paragraphs, I will show you later how to do that.  What this trick will do is save content of an RTF control into a physical file, turns left justified into a right justified one, then utilizes ShellExecute() to open the file via its default program like MSWord. 

 

We will presume that you have an RTF control named OleRTF in a form (if you don’t have one yet, you can download any of the previous samples I gave last time regarding RTF), then add a command button and in its click event paste these:


#Define wdAlignParagraphLeft     0
#Define wdAlignParagraphJustify  3
#Define wdParagraph              4
#Define wdLine                   5

Local loWord As Word.Application, lnloop As Integer, lcTempRTF as Character
loWord = Createobject("word.application")

* Crate a filename reference in the local user’s temp folder, to be used for saving.  Saving can be done via STRTOFILE() but an RTF ActiveX control has a built-in method for that so we will use that instead

lcTempRTF = Addbs(Getenv("TMP"))+Sys(3)+".rtf"
Thisform.oleRTF.SaveFile(lcTempRTF)

* Open it up via automation
loWord.Documents.Open(lcTempRTF)

* Now we will check from top to bottom its justification settings and replace only the left justified ones
For lnloop = 1 To loWord.ActiveDocument.Paragraphs.Count
    If loWord.Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
        loWord.Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify
    Endif
    loWord.Selection.MoveDown(wdParagraph,1)
Endfor

* Save the changes made, close it, and quit Word
loWord.ActiveDocument.SaveAs(lcTempRTF,6)
loWord.ActiveDocument.Close
loWord.Quit

* Open it in its default program to see outright the result
DECLARE INTEGER ShellExecute IN shell32.dll ;
    INTEGER hndWin, ;
    STRING cAction, ;
    STRING cFileName, ;
    STRING cParams, ;
    STRING cDir, ;
    INTEGER nShowWin

ShellExecute(0,"open",lcTempRTF,"","",1)


And there you have it, a very simple trick yet an effective one.  To test this properly, you can change justifications of some paragraphs into center or right in an RTF control before performing the above trick.  You will see that those settings will be retained in the final output.

The only problem I can see with the above is it will be applied to the entire document, i.e., all left justified paragraphs will be fully justified.

And here are the other two constants that we don’t need in the above trick but maybe will be useful on your playings as well:


#Define wdAlignParagraphCenter    1
#Define wdAlignParagraphRight     2


I hope this simple trick will be useful to you. 

In fully justifying of the contents of a memo field containing an RTF format in the Native VFP Report, I will take the liberty to refer you to Mike Gagnon’s wonderful article: http://www.atoutfox.org/articles.asp?ACTION=FCONSULTER&ID=0000000131


Enjoy!



posted by sandstorm36 | 1 Comments
Filed Under: ,

My 8 classes, A new everything….



Those who have read my latest blogs on my SS Classes are now familiar with what I am toying with these days.  I really found it good myself in terms of making it possible to turn my form’s appearance into a web-like look and so I continued working on those.  In this write up, you will see later some styles or looks that I really think you haven’t seen before because I have tried my best to be “original” this time.  So you will be seeing original appearances of most objects, AFAIK, not shown yet in a web page by other artists.

 

But first, allow me to briefly run you with what is new with my classes:

 

Previously Published:

 

SSTBNextGen       56 new different appearances.  I discarded the Ubuntu Series on my end which is part of the free edition as I wanted to create a totally new look for the bar.

 

SSButton             49 new different appearances.  I likewise discarded the series I included in the free edition on my side.

 

SSCal                   new versions 2.0 & 2.01, a total of 32 different appearances (combining both versions and inner and front cover).  Added a 3rd parameter so SSCAL can start on cover or inner calendar (like MonthView).

 

SSDTPicker          new versions 2.0 &  2.01, also total of 32 different looks.  Added 3rd parameter for autohide, meaning when it is set to .T. popup calendar will autohide when focus is given to another object on the form.  I made .T. the default value.

 

Switchbox           Still only have 5 themes but I have replaced themes 1 to 3 on my end with another.

 

 

Unpublished (new classes):

 

SSConfiner          created after SSButton is posted, is designed to make objects appear “confined”.  SSConfiner is designed to use the button themes so it has 49 possible looks as well.

 

SSPage                is actually the latest among my classes as I have done this only on the 4th day of January this year.  This class is designed to replace the pageframe tabs.  With 7 colors.

 

SSSupport          followed after SSConfiner, can be considered as the library of the 7 classes as this handles all the image requirements of the 7 classes.

 

Whereas before there is the need to add the images that come along with my classes to the project itself, with SSSupport class you don’t need to do it anymore.   If you are using some or most of my classes and is attaching the images in the project itself, using this class will reduce your exe size by 64% (tested on my end) when all images essential to my classes are removed.

 

In addition to that, this class will now also enable you to see the images even when forms are run inside the VFP environment as opposed to not having SSSupport class which makes it impossible for you to see the proper images until you compiled your project into exe.

 

 

Versions?

 

There are now two versions of my classes: 

 

1.       Free Version - the previously released classes which I emailed straight to the requestee and later posted in Foxite Download section and in CoderIsland VFP Forum.   Those remain to be free and are available without whatsoever constraint from me.  Meaning, use it, enhance it, or do whatever you please with it if you think it will help beautify further your apps.

 

2.       Per Subscription – These enhanced classes with new themes and designs is on a per subscription scheme of USD 25.   

 

 

Really, What is New?

 

Sleeker, cleaner and prettier designs than before.  I have spent a lot of time perfecting a certain image to my taste; which some of you say is good.  Please see for yourselves, here are 2 images of simple skinned forms: meaning all buttons using the same theme, title bars using another, etc; but all on a certain color.






And here are two images I made for foxite forum, I decided to show it likewise here so you can see some more possible appearances:







These images are not in their actual appearances yet as I used jpeg format to favor uploading and display speed for those images.

 

Above images are likewise resized so it can fit this screen properly.  I have shown above how a themed forms and objects may look like using my classes because in my testing of the color combinations plus various themes here, I have employed skinning (using OptionSwitch) for me to be able to see outright the harmony between my classes’ appearance.  In that way I can readily make adjustments on the images if needed (which I have done every now and then).

 

But that does not necessarily mean you have to do it also on your end when you have my latest classes’ versions.  You will find out that combining different colors and themes will likewise produce a very nice output, showing various themes and color variations in a single form (actual size):

 




Keep in mind that I have at most 7 colors and 7 themes.  That alone is 49 possible different appearances which you have complete control.  And since I am giving complete control on fonts like colors, bolding, font name, sizes, italic, and underline; a single object like ssbutton can have different appearances on a single color on a single theme.   And having said, showing all those other variations is not possible as this blog will not be sufficient to accommodate those. 

 

 

3 New Classes Brief Explanation:

 

 

Because I have not introduced properly SSConfiner, I will briefly point out the differences above which might not be that evident as you are taking in a lot of new images right now:

1.       On Calendars - have double lines, inner border has a color, plain border

2.       On Buttons – single 3D lines, no inside color

3.       On Pageframes – single plain lines, inside color

4.       On Switchboxes – single plain lines, inside color, with shadow

 

Of course, colors and themes used by SSConfiner’s title bar background can vary, font settings likewise can vary.  Here is how to use it:

 

Whereas:



* RGB(236,233,216) is the default backcolor of a form

 

 

For whatever reason you don’t want to use a theme for SSConfiner’s Title Bar, then simply change nTheme into 0 or leave it empty.







SSPage
is easier, it accepts only 3 settings:




 

Whereas:


Like most of the SS Classes, you can drag the width and height of SSPage and it will be resized properly. 

 

There is nothing to learn on SSSupport.  All you need to do is drag that into your main form and that is it.

 

 

Subscription Fee:

 

Is a subscription fee of USD 25 that much?  I honestly don’t believe so considering I am giving everything here and not on a per-class subscription.  I am not giving just one, two, ten, twenty designs; I am giving an average of 49 designs. 

 

In order for me to arrive at even just a single theme and color, it took me a lot of hard work, both as an artist and a developer.  Not to mention that I spent most of my “holiday” period working on those to give interested users the power of enhancing their project’s looks.   Let us take into example SSCal v2.01 front cover.  For me to arrive at this beautiful skin:

 




Would you believe that that single image alone took me 26 layers of various objects with different effects, styles and combinations?  That does not include the fonts you are seeing on its face.  That also does not include other layers I have made before, modified and discarded later on that single image.  That goes as well with the inner calendar and on a lot of themes for every object I made before and eventually totally discarded later in favor of better ones.  Believe me; I have created a lot of styles for SSButton and SSTBNextGen alone where later I unhesitatingly discarded those in favor of replacing it with better ones.   

 

After I am satisfied with a combination for a single image; I still have to create 6 more colors for that to complement the color schemes I have made for the classes. 

 

Mixing colors I thought before is just easy, which is true, if you will be making a new single design.  But creating 7 color variances of a single design while retaining the balances of a theme, I found out, is not so.  From the base color of blue, turning it into let us say yellow will produce a very dark or light yellow which hurts the eyes and does not go well in harmony with other classes’ themes.  In addition to designs I made and discarded, I have to remix colors every now and then as the appearance of what my LCD monitor gives me is slightly but noticeably different when seen on my notebook.  When I tested those on a CRT monitor, it likewise shows shadings and mixes on a different level.  So as I have said, I have done color remixing and applied different tricks over and over again until I got satisfied.

 

Modifications and designing may be easier if I am an expert with Photoshop, but no I am just a fairly novice in using it.  All I have, as some of you say, is a good eye for beauty plus patience in doing it.

 

I have been struggling on my decision to give those for free again or to ask for that subscription fee but finally I decided for the latter.  Any proceeds out of that, I plan to use anyway in supporting me on learning new languages like .Net or Web Developing.  And so I would like to think of that USD 25 subscription fee as a support to me, not payment.  If I will have enough, I plan to purchase a server so I can host my own site in the future.  Why, if I can do that on VFP, what is keeping me later from doing that also in .Net or other languages I maybe will be into in the near future as well?  And maybe by that time I can make better ones, not just in terms of GUI but on how my classes work and interact.

 

Package:

 

So to anyone interested in subscribing these enhanced classes plus the new ones, just email me at ss.classes.jun@gmail.com.  The package will include the following:

 

1.       Switchbox enhanced

2.       SSCal ver 2.0 and 2.01

3.       SSDTPicker ver 2.0 and 2.01

4.       SSTBNextGen enhanced

5.       SSButton enhanced

6.       SSPage (new)

7.       SSConfiner (new)

8.       SSSupport (new)

9.       A sample small project showing the use of those and how skinning can be implemented on your end, and some more tricks I do.

 

ALL using 100% Native VFP commands and functions, meaning it will not require any registration like what ActiveX needs and will not need any other files aside from those 8 classes (actually all will be in a single main class named _SSClasses).

 

Afterword:

 

Although it seems I am selling my classes, in reality what I am selling here are the designs I made myself on my end.  The classes are just instrumental in bringing those to life because without those my images are half useless.  Problem though is I cannot give the 3 new classes (SSConfiner, SSPage and SSSupport) as they are tied with the latest designs.  Also, the whole 8 classes now complement each other.

 

Right now they are tested running on WindowsXP without a problem.  I will have to test later how it will fare with Vista and Windows7 but I am not expecting any problem on those as I tried to confine everything to reduce compatibility issues.  Plus since it is 100% native VFP and I have used common commands and functions, then I really don’t expect any problem with OS and VFP versions.  Here again is the combination form, now running under VFP 7:




As you can see, it does not affect the images of my classes.  What it affects though is the appearance of the native objects like the optiongroup and the pageframe.

 

If you will be subscribing for these new classes, I am saying in advance….  Say hello to a revolutionized ala Web-Like look for your projects.


Update January 16, 2010:

 I got a better connection today so I will be showing here a real sized image of the forms and SS objects.

 

posted by sandstorm36 | 3 Comments
Filed Under: , , ,

Presenting SSButton Class



Actually after creating the SSDTPicker, I already moved on working with the SSTBNextGen class.  I finished the initial class with 7 themes after a few hours as I believe you knew now how fast I work when I feel doing a thing with of course no distraction.  On the same date I also started playing with the GUI for the SSButton which I also have in mind to complete the much needed makeup of a plain VFP exe. The GUI and the class were finished the day after.  

Normally I would have stopped right there and then to immediately create a post for sharing purposes not minding to enhance it further.   My reason?  Those are just samples that can still be enhanced by interested users.  In reality, mostly what I am giving are just ideas and guides with the exception of some tools like Live Backup.

But since I received very positive responses on my last 3 classes, I decided and promised to give you better ones, not just mere ideas or guides.  And so I kept both SSTBNextGen and SSButton classes still with me for further testings and enhancements.  I completed enhancements on those two as of December 14 and actually created both SSTBNextGen and this blog on the 15th.

However, I postponed posting these two blogs as I decided to give SSTBNextGen as my pre-Christmas gift to interested users and this one as a pre-New Year’s present.  Plus I have to post the promised “filler” which is OptionSwitch.

As seen on my SSTBNextGen, it is better now.  You'll be still surprised though what this single button class can do as I have exerted a lot of effort to make this very flexible.  Not in the codings though as I can find ways to use only a couple of those yet achieve what I want; but in "thinking" what more can be done.

Those previous 3 classes can still be enhanced as I actually did not put much efforts on those as I am not sure then what would be the responses considering I will be doing the who's who. So wait next year and I will again work on those. 

Actually, Anil Sharma is already working on enhancing the SSDTPicker as last time I sought his help to find out if that will run on VFP6 as I don't have one.  It runs well (except you need to remove an extra "k" on an object's name in one method inside the class which is what will be activated when using versions below 7).  In addition, he thought of some more enhancements that can be done so I requested him to apply those himself then just send me back the enhanced version. I will post that next year though as I have also some more things in mind that can further enhance the already enhanced version.

Back to this class, I claimed this as the best so far among my classes. So is your level of curiosity getting higher on what this simple, insignificant, good for nothing, single button class can do as compared to SSDTPicker or on my other classes or ideas?  What could have possibly, a very simple puny button class like this can really do?  Will this really give impact to your end as I believe it would be?  Let us see.

Here we go!

  • I included 3 themes here I called simple, fancy, and artistic.  They are to be activated as 1, 2, and 3.  But wait!  I think I have said 4 themes before, so where is the 4th?  
The 4th theme is actually numbered 0.  When you turn the theme into 0, you will have a transparent bar instead.  A lazy move on my part but I believe an ingenious one, LOL!  It has an impact especially with the hottracking feature, believe me.
  • Speaking of the hottracking feature, what the heck is that?  
When the mouse pointer enters the button area, the caption will turn into white (default).  When mouse pointer leaves, it will turn back to its previous color.
  • Hottracking color’s default is white?  Does that mean you can change color?  
Yes, you can change color of the hottracking feature using an RGB() combination.

Seems not that impressive?  Then read further:

  • Why did I said when mouse pointer leaves, it will turn back to its previous color?  Why not simply say it will turn back to black?  
Because you can likewise change the color of the caption.
  • In addition, you can also change the font of the caption
  • As well as font size
  • Or make the caption Bold
  • Or make the caption Italic
Wait a minute, this button uses a font
Yes it does.  That is one of my few surprises with this SSButton class, I used plain font for caption to give it further flexibility.  Default is Arial, 9.
  • And since it uses font, I also gave the ability to set its alignment. Default is 0 (left aligned) and can be changed into 1 (right aligned) or 2 (Center Aligned).

Not yet Satisfied?  There is more:

  • You can resize this button and it will do its own repainting.  The caption, the icon, and the borderline will likewise be resized.  When you change the font size, it will likewise do its own calculation to keep it vertically centered as possibly as the new size can permit vs the current height of the button.
  • Speaking of the icon, you can reposition it anywhere within the button boundary, and a little bit outside of the boundary (lower portion) which gives it a cool impact.  I provided a little space for that effect to happen.



Hmmm, starting to like the features now huh?  Wait, we are not done yet!

  • Speaking of borderline, what do I mean by that? Why did I still use one?
During my initial creation of colored themes, the images are actually surrounded by a black line as that is what buttons supposed to have.  However, during the initial testings, when I resized/stretched a button image, the borders became too thick or too thin much to my disliking depending on the percentage of stretching I have done.  And it appears ugly.  Solution?  Create a separate line to act as a border which thick/thinness will not be affected by resizing, and so the borderline.
In addition, with this separate borderline, you can do these things to add further effect to the button itself: Make it plain or with 3D effect. 
Getting better and better?
  • You can change the button image into any of the 7 colors which are: Red, Green, Yellow (Gold), Orange, Blue, Brown and Pink (for the ladies, I never forget you).
  • And as I have said, we have 4 themes, well actually 3 that work with the color variations plus theme 0.  So that is a possible 22 different looks! But wait, since this button can be resized as well as the caption, then it goes beyond that count as can be seen in this image:


Not to mention that by providing you control over the font name, size, color, etc.; it really goes beyond those combinations.  As you now am realizing, retaining font usage for caption gives greater resizing flexibility as well.
The white captioned button is actually hottracked before I captured this image to show you what it looks like.  The bigger one’s hottrack is not bolded while small one is.
  • And speaking again of the hottracking feature, when mouse enters the button area, the button will appear to have been pressed down to the right.  And along with that movement goes all the button contents: the button image, the line boundary if it is shown, the caption, and the icon (if any). It appears as a whole so I designed it to be treated as a whole during hot tracking.  When it looses focus or the mouse pointer moves away, it will appear depressed.
  • As shown in SSTBNextGen, I changed tactic to avoid cluttering the class instance in a form with a lot of this and that, err… this and this!  It is parameterized now.  If your VFP version already has an Intellisense feature, the class can take advantage of that like shown below:


With the help of intellisense, you will know exactly where you are and what is needed on that portion.  With intellisense working, your current position is shown in bold as can be seen on the image above.


Err... that looks monstrous!  It seems very hard to use it!!!  Really intimidating!


Not so!  All parameters have default values, meaning you can leave those untouched and just simply put comma in its place to reach your target settings. All parameters are optional, except that you have to place any one of those settings to activate the class _settings method.  You can simply say:

this._Settings("My Caption and I am done!")


And that is it!  It will show the button with all the default settings (dragging the width a little longer to fit caption):



Here are the parameters in order:



Like what I have said with icons, you can position it anywhere as you will be the one controlling the left and top positions of it. If you haven’t put any icon name, then you can simply ignore top and left positions as well.

A few more last surprises:

  • Unlike a plain image used as a button, this class can accept tab order.  Not just simply accept tab order but retains focus as well.  Not only that, it will do the hottracking as well like what will happen when you move the mouse onto it.
  • Since I have given it the ability to receive focus as reflected by becoming hottracked, you can use the keyboard as well to move back and forth to several objects including this button class of mine, based on the tab order; very much like the native VFP command button.

Very Important (a repitition of what I said in SSTBNextGen blog):

With my goal of lifting some weight off the end-user’s shoulder, there is one thing you need to do.  Add the images I used into your project.  To do that, in Project Manager, go to Other Tab, then Others, then click the Add button and choose all the images I used for my classes.  You will not see the images during the development phase as those will appear on the final exe.


Afterword:

All I have used here are 100% VFP commands and I have tried my best to make this run on lower versions as well.  Except with the images needed for the button, all objects in this class are 100% Native VFP objects.

Note:  Since I decided to post SSTBNextGen earlier than intended to to give myself ample time to reply to possible requests, I am likewise posting this now especially since I have given this as well to all who already participated so some of them I believe needs a guide on how to use this as this one has a lot of parameters.

Advance Happy New Year to all!  I hope that this new class provides the intended BOOM to give impact on your VFP exes.  Play with the possible combinations and Enjoy!

PS.  I forgot to mention that you need to use ClickAction Click Event for your commands (Similar to CommandButton Click Event).

Updates December 19, 2009 at 2:30PM:


Additional features:

1.  Just now I have added a hotkey ability to the SSButton class.  So you can now make the caption of the button something like this:

This._settings("\<Fuel Voucher Encoding Module"). 

And the letter F will be the hotkey for that SSButton instance. 

2.  Additional keyboard functionality.   You can now use Enter when it has the focus and it will perform whatever it is inside its ClickAction click event. 

3.  When the instance of the class in the form is disabled (Enabled = .F.), the hottrack color will be duller now instead of the default white or your chosen hottrack color so you can visually differentiate the difference between an enabled instance vs a disabled one.  In addition, since the command to be performed is outside of the class in ClickAction click event, you have to trap the status of Enabled property like this:

ClickAction, Click Event:
IF this.parent.Enabled
   * put your commands here
endif


In that way, when it is disabled, it will still hottrack but now with duller color and clicking it won't perform the commands it is supposed to do.


Update: December 26, 2009

I already have submitted the classes for free and easy download to Eric for the download section of foxite, so you will see those pending the decision of Eric.  In addition, I have created a thread in coderisland to have the same available for download.  Please click on the link below:

http://www.coderisland.com/forum/viewtopic.php?f=10&t=254

posted by sandstorm36 | 3 Comments
Filed Under: ,

Sandstorm’s SSTBNextGen Class


I have been silent these last few days inside the forum as my interest currently lies with providing interested users better tools.  And since I recently provided classes with different themes and since the responses with those are very positive; I decided to continue creating new classes that might help others who have problem with visual design.

But sometimes creating new classes doesn’t necessarily mean that it is entirely new as can be seen with what I am going to share to you now.  This is about my title bar class which I worked on enhancing to provide different colors and added more features.  

Unlike what I have done before which is giving one style per class, e.g., SSVista series, AikonXP, Chrome, etc.; I decided to finally include a skinning ability with this next generation.  Mike Yearwood has advised me long before to turn my title bar class into something like this but I don't have the mood yet that time.  Now I have.

Like my previous 3 classes, this one can be modified on the init event of the instance of the class in a form.  In addition, I have replaced the formerly 3-segmented parts of the bar in favor of  2 segments.  Also, I contained a lot of objects inside so you won't accidentally move those around plus it reduces the codings and location manipulations I have to do inside.

I formerly named this Ubuntu series being the base image is my ubuntu green I shared last time with the Enhanced RTF revealed blog.  But that ubuntu green still needs a few retouches.  Being a part of my first generation of 3-segmented Title Bar class, sometimes the parts are sort of misaligned.  Anyway, fixed that problem.  And since this is my next generation of title bar class being it has theme capability, I renamed it SSTBNextGen.  Shown below is the class while I still called it Ubuntu Series:


Like my first generation of title bar classes, this repositions itself properly in the form, then hides the form’s title bar, enables tooltip, and resizes itself along with the form’s width.  All you need to do is drop it anywhere in your form and let it do the rest. Plus of course, you can change Caption.

What then are the added features?   Now, in addition to the above, this one can also do the following:
  • As can be seen above, you can change the color into any of the above 7 variations, i.e., blue, brown, green, orange, pink, red and yellow.
  • You can change the Caption’s Font as well
  • And also Caption’s Font Size
  • As well as Caption’s Forecolor
  • You can also make it Bold
  • Or Italic.  Sounds better eh?  But wait,
  • Now you can change Caption’s Alignment as well.  You can now make the title bar’s caption Centered. 
  • Also added the ability to place an icon image
  • Maximize and Restore will show proper images now
  • It will likewise show the proper tooltip on both maximized or normal state
  • Double clicking the bar will toggle it into maximize and restore
  • And you can move around the form by clicking on the bar and pressing the left mouse button down
Below is what SSTBNextGen can look:



In addition, I have played with a different approach with this and the SSButton class to make commands one-lined as compared to the last 3 classes with lots of this declarations in the init event of the class’ instance on a form.  Whereas before, we do it like:

This._color = “orange” 
This._Caption = “Fuel Consumption Monitoring System”
This._boldcaption = .T. 
Etc…

Now we can simply do it like:


this._settings("Fuel Consumption Monitoring System","Tahoma",;
     10,,.T.,,2,"orange","exicon.bmp")


That is actually the commands I used to generate the above image.  Sounds easier huh? 

Moreover, if your VFP version already has an Intellisense, we can make use of it to know exactly where we are in the _settings:




Can’t I make it simpler where all I need to do is place the caption like this?

This._Settings(“Fuel Consumption Monitoring System”)


Yes of course.  Here is what will appear with the simple command above,  the rest utilizing their  default values:



That will work as all parameters have default values as shown below:



However, you still need to assign at least one of the settings to activate the class _settings method.

Very Important:

With my goal of lifting some weight off the end-user’s shoulder, there is one thing you need to do.  Add the images I used into your project.  To do that, in Project Manager, go to Other Tab, then Others, then click the Add button and choose all the images I used for my classes.  You will not see the images during the development phase as those will appear on the final exe. 


Update: December 26, 2009

I already have submitted the classes for free and easy download to Eric for the download section of foxite, so you will see those pending the decision of Eric.  In addition, I have created a thread in coderisland to have the same available for download.  Please click on the link below:

http://www.coderisland.com/forum/viewtopic.php?f=10&t=254

posted by sandstorm36 | 21 Comments
Filed Under: ,

Transmorphing SwitchBox into an OptionSwitch


This tutorial is for the current or future switchbox’ users.  Still on the who’s who stage, you will not find any attachment here.  What you will find here is the way how to transform the switchbox into an OptionSwitch.  Let us take a look first at a couple of images below:



“Coincidentally”, the selection itself shows one difference of OptionSwitch as against OptoinGroup.  It  is more colorful.  In addition, it doesn’t have the ugly lines around the caption.



Like the optiongroup, OptionSwitch can only retain one ON state.  So when you click on another switch, the previously ON switch will be turned OFF to give way to the currently clicked switch.  Again, without the ugly lines surrounding the caption in the case of an OptionGroup.

There is really nothing that much to tell about an OptionGroup or OptionSwitch as they both can do the same.  SwitchBox, on the other hand, has one advantage over it in that unlike an OptionGroup it can return a value of 0 (all switches are on the OFF status).  While it is true that it can only have one ON, I decided to allow it to return a 0 value.  Who knows, someone may find some use for it?



So how then can we turn a couple of switchboxes into an OptionSwitch?  Here goes:

1.    Drag a switchbox into your form, change the various settings on its Init Event
2.    Copy Paste to create several instances
3.    Change every copies’ settings as well
4.    Select all then Cut (Ctrl+X)
5.    Now create a container object, name it as ContOBox then press Ctrl button then click on it or Right-Click on the container then choose Edit
6.    Press Ctrl+V to paste all previously switchboxes that we cut inside that container
7.    You can optionally change the bordercolor like what I have shown above to make it appear better
8.    Double-Click Container object and in its Init Event, paste these:

Local swobject As Character
For lnloop = 1 To This.Objects.Count
    swobject = "switchbox"+Transform(lnloop)
    This.&swobject.._type = 5  && or whatever type of your choosing
Next
thisform.AddProperty("switchbox",0)


9.    Now create a method which will control the toggling to ensure that there will only one will remain in the ON status.  Click Form – New Method, type oToggle as Name, and add a description to remind you of what that is.  Go to that method and paste these:

Lparameters lcswname
Local swobject As Character
For lnloop = 1 To Thisform.contobox.Objects.Count
    swobject = "switchbox"+Transform(lnloop)
    If UPPER(swobject) # UPPER(lcswname)
        Thisform.contobox.&swobject.._value = .F.
    Else
        Thisform.switchbox = m.lnloop
    Endif
Next


10.    Finally, on every switchbox instance’s Shape1 Click Event, paste these:

thisform.otoggle(this.parent.name)
DODEFAULT()

And there you have it.  An OptionSwitch. 

Getting the current OptionSwitch value is as easy as this:

MESSAGEBOX(thisform.switchbox)

Getting the Caption of the currently selected (in the ON state) switchbox is like this:

Local lswitchboxCaption
lswitchboxCaption = "switchbox"+Transform(Thisform.switchbox)
Messagebox(Iif(Thisform.switchbox=0,"All are on the OFF status!",;
    thisform.contobox.&lswitchboxCaption..lblCaption.Caption))


I hope that this simple tutorial on turning the SwitchBox class into an OptionSwitch will do you good.  Next posting will be my pre-Christmas gift to interested users.  Enjoy!


Update: December 26, 2009

I already have submitted the classes for free and easy download to Eric for the download section of foxite, so you will see those pending the decision of Eric.  In addition, I have created a thread in coderisland to have the same available for download.  Please click on the link below:

http://www.coderisland.com/forum/viewtopic.php?f=10&t=254

posted by sandstorm36 | 1 Comments
Filed Under: ,

Why?



Recently I changed style which is from previously attaching a sample, the tool itself, or the class itself; into a per request basis.  Is it easier for me?  No, it is harder as I have to manually answer requests and manually send the requested files.  Not to mention that I have a very slow connection most of the time (53.6kbps) and I am paying for prepaid loads for an internet connection just to give those classes to anybody who requested from me.

So why then do those unnecessary steps?  Below are a very good comment, observation and suggestion from Cesar in my SSDTPicker Class which I originally planned to answer as well there but this will be long so..…

Hi Jun,

You said in this post:
>>... "to avoid having that ugly feeling again, in my end, I decided to “know” who is really interested in any of my new ideas ..."

Please don't do that !!!
Look, it took me about almost a week till I decided to ask you directly to send me the ssCalendar class from a previous post. Just because I did not want to publish my email in a blog comment. When you take that attitude, believe me, you are limiting the quantity of people that will appreciate your work.

Another thing is that people do always recommend some links, and doing that people will share those files directly.

I suggest that you can upload your files to a separate server, that will allow you to have a downloads counter.

Please understand that these files need to be very easy to be accessed, and tested. You have great ideas, and a very nice eye for design.

FYI: I've adapted the ssCal class and it's already in my app.

It's really fantastic to have feedback, but sometimes it does not happen, for many reasons, and believe me, zero feedback does not mean that people did not apreciate your work. Suddenly you'll find references to some posts of you on the web !!!


I am not an expert nor did I claim to be one.  The reason I am doing blogs, aside from sharing and trying to teach others how certain things can be done is I want to influence others like me to do the same, that they can do it too.  The reason why my blogs are sort of informal is those are actually geared mostly towards the newbies or to those in need, not only to those who are already experts or who consider themselves as one.  

Lately, I decided to conduct this little experiment called who's who?  Who has the guts to openly request from me, a non-expert, those classes and not be ashamed of doing it and who despite having an interest finds it hard to do it.

Sure, there are several reasons why someone will hesitate to post an open request like Cesar's consideration about his email address which is very understandable, but anybody can likewise put a message that instructs me to delete the email link before I finally approve for the comment/request to appear on my blogs.  Or they can email me straight which, despite my notes here, some still do anyway; and honestly it is just fine with me also.  

To those who cannot request from me because they are ashamed to do so, then as I have said it is their losses not mine.  What is so hard about posting a request here or in my emails?  Is it harder than us preparing things for you to simply use? What is so shameful in asking?  I myself have been doing it.

I will tell you why it can be hard, pride!  It is very hard if a person thinks high of him/herself because doing that is a sort of admission to one's self that he/she is not that better in some aspect to some whom  he/she considers less of his/her stature.  It is very hard to swallow pride if you have one and that is what I am likewise trying to teach here.  Not swallowing in a sense but admitting that sometimes we really need something even from some whom arguably is less skilled than us.  I have been doing that as well, listening to guys with lesser experiences than me or is younger than me.

That thing about seeing the number of downloads is my first phase in knowing how many initially take interest in my ideas, when it is free to download anytime they choose.  The 2nd and final phase is this, knowing who has the guts to admit to him/herself that they can request from me openly or through my email.

Do I loose respect on those who request from me?  Absolutely not!  On the contrary I admire them more because I am just like them.  I can't see anything wrong in doing it!  Unless if a person has an ego that whispers, it is shameful to request from someone whom they feel is lesser than them.  There are people like that, believe me.  

Cesar is among the people who have been contributing a lot without asking for anything in return.  He is among the people I respect and in fact he is the one who showed faith in me before by suggesting I blog to share further my ideas.  Yet he requested for the class openly after a bit of hesitation due to a very valid reason which everyone can understand.  And that put my level of respect to him higher.  Actually it comes as a no surprise to me because I have known him to be a highly skilled yet good and a humble guy.  But that is him.  I want to see though how many more will/can be like him, a highly skilled and experienced guy yet who never let pride get in the way.   A very commendable action in my eyes and I believe in the eyes of many as well.

I am not saying though that if you don’t request, you are automatically among those I am saying that pride is getting in the way.  Of course it can be simply because it really never appealed to you.  The person who will know the real reason is that person him/herself.

Upcoming:

I will share two more classes I am currently working that can hugely affect the GUI of a VFP exe.  I will post those next week or after that.  I will create first a tutorial on how to transmorph switchbox into an OptionSwitch.  

Those 2 upcoming class combined with the last 3 class I have shared will really help beautify the appearances of VFP apps whether under version 9 or lower.  Here is a normal VFP appearance taking into account Theme is already supported:



And here is what we can do by using only 3 of my classes, i.e., SSTitleBar NextGen (upcoming), SSCal (already shared), and SSButton (upcoming): 
 






These 5 classes (including the upcoming 2 new ones) will not tie you up with a single design which software like WindowBlinds and similar others do which is tying your GUI with a single theme.  I made those very flexible that you can come up with your own unique styles and combinations out of those 5 classes very fast and easy and still create something unique and cool. 

Those are just samples of what can be.  These last few days, I made SSTitleBar NextGen with 7 colors and SSButton class with 4 themes and 7 colors, not to mention some other more features I will not mention here yet. But I have thought more things to do on those two and unlike before where I say to myself “this is enough to get them going”, now I am trying my best to give you better ones.  So I will be releasing those when I have implemented those other more things I still have in mind.

With those you will be an instant GUI expert in the eyes of your clients, in absolutely no time at all! 

To anyone who will show an immediate interest in any or all of those, just request here in weblogs or direct on my email, preferably on my gmail and not on the yahoo one.  

For those who cannot request due to the reasons I have said here, out of respect to Cesar, I will be posting all 5 classes as attachment in CoderIsland and Foxite Download Section later next year.  But I will not do it early.  So either you can wait until that time for you to have those or.... you can request from me immediately after I post.  It is your choice. 

The experiment will soon stop but for now allow me to continue doing it still with the next 2 classes.  Cheers!

Update: December 26, 2009

I already have submitted the classes for free and easy download to Eric for the download section of foxite, so you will see those pending the decision of Eric.  In addition, I have created a thread in coderisland to have the same available for download.  Please click on the link below:

http://www.coderisland.com/forum/viewtopic.php?f=10&t=254


posted by sandstorm36 | 9 Comments
Filed Under: , ,

SandStorm’s Date Time Picker


I made the other day the SSCal class and I thought to myself, who or what is keeping me from creating a datetime picker?  And the answer is no one and nothing.  And so you are seeing now the newly created SSDTPicker class.

Brief Introduction to some Features:

1.  Well of course, first and foremost would be, it is 100% Native VFP.

2.  It comes with a variety of 5 colors again.  On normal stage (when calendar is not visible), the current color will be reflected by the button in the right side.




To hide it back, click again the button.  That button toggles between showing and hiding the popup calendar.

3. Unlike the ActiveX DTPicker’s popup which cannot stay open when you click on another object, this one can




4. It auto-adjusts itself (and auto-resizes as well)  to follow whatever the current SET DATE setting is:




 
5.  Working with the class value is as simple as these:

x = thisform.ssdtpicker1._value
INSERT INTO MyTable (flddate) VALUES (thisform.ssdtpicker1._value)
REPLACE flddate WITH thisform.ssdtpicker2._value IN MyTable
Messagebox(thisform.ssdtpicker1._value)



Declaring the initial values is easier, in the Init Event of that class’ instance in a form:
This._Value = date()
This._Color = “blue”

6.  In the tradition of a DTPicker, clicking “Today” will bring you back to the current date.  The calendar will likewise be repainted back to current date.

7.  Like any other DTPicker, you can manually encode the date on the date box.

8.  No graphics used whatsoever which lessens additional weight to a project.  The whole class is composed of labels, containers, etc.  But not a single image is used.

9.  And since it is 100% VFP, it will not introduce problems to your project which sometimes an ActiveX do.



Shift of Style:

Some people are maybe wondering why I suddenly changed attitude from simply attaching whatever it is I am trying to share into doing it on a request basis which means more further work on my side.  But lately I felt some of my contributions are not that appreciated, I don’t know exactly why that feeling and what has fired it.  But it happened. I actually thought before of stopping contributing further but the feeling has subsided.

I believe I am not alone in that appreciation thing so I will be so bold in saying I will be speaking in behalf of some if not most of the contributors of Weblogs.  We need feedback of how things work out on your ends.

So to avoid having that ugly feeling again, in my end, I decided to “know” who is really interested in any of my new ideas (except when it is pure tutorial).  And being the author of whatever it is I am sharing or will share more in the future, I am entitled to this decision.

I think you can see from the above what this class can do to enhance your project.  If you like it, all you need to do is request; if you don’t like or don’t feel like requesting for the class from me, then it is you loss not mine!

However if you can wait for me to change mind again in the future, then you can simply wait for that to happen.  Who knows?  Out of a whim, I may suddenly place the attachment here again one time?

Enjoy!

Update December 8, 2009:


The old one can not cater versions lower than 9, this one does.  There are some more changes inside:

a.  Removed declaration of Zorder(1) in the init which brings the class in the back of other objects (a bug).  Only the zorder declaration in toggling visibility of popup calendar is needed, thus, retained.

b.  Added the ability to show or not show "today" section.  Depending on the taste of the user, sometimes without the today section looks better.  By default it is shown, to remove it add this in the init event of the class' instance in a form:
this._notoday = .T.

c.  Enlarges a little bit the days and weekdays objects to make things more readable.  Adjusted the popup calendar size as well.




d.  Added a shape in replacement of the commandgroup for month navigation which will err in versions lower than 9 as it uses command button's backcolor property which do not exists yet in the older versions.  So when you are running below 9, shape object will take control of showing the colors of the calendars plus toggling its visibility ON and OFF.

e.  For versions lower than 7, I remove the Themes capability. 

There are some more minor adjustments as I am trying to make this run on versions lower than 9 as well like the SpecialEffect properties.  I created this class in 9 and I really don't know if somebody will take an interest in this one before so I never minded preparing this for other versions.  Now I believe I have done that. 

So to those who already have this who might experience some problems with this class, please inform me via email so I can attend to it.   To those who still only have the first version, I will update you via email later today.  You have my email address now so if something needs bringing into my attention, please bring it to me.  Cheers!


Update: December 26, 2009

I already have submitted the classes for free and easy download to Eric for the download section of foxite, so you will see those pending the decision of Eric.  In addition, I have created a thread in coderisland to have the same available for download.  Please click on the link below:

http://www.coderisland.com/forum/viewtopic.php?f=10&t=254

posted by sandstorm36 | 35 Comments
Filed Under: , ,

Presenting Sandstorm’s Calendar (sscal) Class


The other day, I started playing with one of my old programs to implement the switchbox class I recently created as I wanted to see how it will look in an actual application that is being utilized.  So I opened my ErgoX and started toying with the GUI.  In the process though, it looks like that my old GUI on the main form itself is not that satisfying anymore to me.  So I moved objects around ("Really?  It is VFP?") and then later as I really cannot find the "feel" of it, I decided to remove some objects and add others I recently toyed with like an RTF control.  Then my eyes fell on the monthview activex and then my "spider sense" begins to tingle.

What if, I mused to myself, I replace that with something like the calendar of a side bar now famous in XP, Vista and Seven?  And so I begin to toy with the GUI for a calendar.  And that is a pure image with just the labels for the dates I slapped on top of it.  Satisfied, I again said to myself, what if I put skinning ability into it?  So I created 4 more skins for that.  Again loving what I am seeing and done so far, I thought, "Whatdaheck?  Let's make this a class so others can benefit from this too!"  And so the initial sscal class is born with the ability of the user to choose color.




Yesterday afternoon though, after a long talk with a friend, I again thought since I am satisfied with the sscal class appearance, why not also add an inner calendar like the sidebar style?  Pooop there goes the inner calendar!  Sounds easy eh? LOL!  It is not but it is done.  Needless to say, the very simple need of an image for a calendar became the class I am sharing now because of a lots of why nots!
 


Like the switchbox class, choosing the color is done in the init event of the class' instance like this:
this._color = "blue"

Colors are blue, orange, yellow, green and red. So if you want to change the calendar into a red one in your form just put in its init:
this._color = "red"

And that is it!  Drag into your form, assign a color and smile.

Interaction:

When you double-click the cover, the inner one will be revealed where you can then change a date by clicking on a number or moving forward or backward months via clicking the arrows.  Double clicking it again returns to the cover with your latest date selection.  The calendar (inner and the cover) will be repainted properly to your current date selection.





Getting current sscal date value is easy as this:
?thisform.sscal1._dclicked

Bonus:  A running clock is everpresent in the cover.  Two birds in one stone eh?

Additional Bonus:  It does not need ANYTHING outside of the VFP box.  This is 100% native VFP.

Last final bonus:  It is my habit to hardcode path as I like to see what is happening in any of my classes even in the development stage.  But that habit would require some more work on the part of the recipient of my class.  Anyway, the reason why I am providing open sources is basically I just wanted to share my ideas to anybody interested and for them to learn additional ways how certain things can be done.  Also with the source codes included, others can extend any of those based on what they desire.

From this moment however, I am removing the hardcoded path so the class can be easily used on your end without the need of path alteration anymore.  Just include this class in your project and use it without any change. 

Caveat:  you will not see the images though on the development stage as those will appear only on the exe (plus you need to manually add the images I used, in your own project).



Update: December 26, 2009

I already have submitted the classes for free and easy download to Eric for the download section of foxite, so you will see those pending the decision of Eric.  In addition, I have created a thread in coderisland to have the same available for download.  Please click on the link below:

http://www.coderisland.com/forum/viewtopic.php?f=10&t=254


posted by sandstorm36 | 24 Comments
Filed Under: ,

New Switchbox Class (Revised & Enhanced)



I have made further enhancements (2 new themes) and modifications (like renaming _type to _theme, removing _ivalue, allowing _value to accept either a logical or integer value then return the same, and some more) inside the class so I decided to rewrite this blog instead of cluttering the bottom part with lots of updates/notes; here which will make it longer.  So here is the revised blog:

As I have said before, I love simple things as sometimes those simple things are what's contributing to the bigger picture. My intention for this class is to replace the checkbox with something unique/unusual.  Although for simple needs of toggling a return value of .T. or .F. or 1 or 0 checkbox is the best thing to turn to, It does not hurt to replace it with something a little bit unique which may add "appeal" to our form.   Presenting switchbox:



Q: So how can we use this new class?
A: As usual with classes you just need to drag it inside your form.  Then in the init event of the instance of the class is where you need to assign the switchbox' different properties like theme and caption. In the image shown above, I used something like this:

Switchbox1 Init:
this._theme = 5
this._value = .T.
Note:  Default settings follow:

_value = .F.
_theme = 1
_caption = None

Q:  What does None in the default caption means?
A:  In the tradition of VFP, in an absence of assigned caption, it will get the name of the of the object.  So when you don't touch the _caption property you will be seeing something like Switchbox1, Switchbox2....

Q:  For whatever reason, I don't want to put any caption on the switchbox.  Can I simply show the switchbox without any caption?
A:  Yes!  Just place in the init event of the instance of the class: 
This._caption = ''

Q:  A checkbox class has a Click Event where we can  place commands.  Can we do the same with switchbox?
A:  Yes, but you need to use SwitchBox' Shape1 Click Event for that and combine it with DODEFAULT(), something like this:

SwitchBox Shape1's Click Event:
DODEFAULT()
* Do something here

Q:  What are the possible return value of this class?
A:  Like the checkbox class, this class will return an integer value of  1 (ON state) or 0 (OFF state) or .T. (ON state) or .F. (OFF state) depending on the declaration used via _value property.  By default as mentioned though, it is set to a logical value of .F..

?thisform.SwitchBox1._value  && will return either .T., .F., 1 or 0 depending on the initial value we assign
Q:  How about if we want the switchbox to start in an ON state?
A:  Just add any of these in the init event of the instance of the switchbox object inside the form:
this._value = 1    && sets it to ON state initially, _value to be returned is either 1 or 0
this._value = .T&& sets it to ON state initially, _value to be returned is either .T. or .F.
this._value = 0    && sets it to OFF state initially, _value to be returned is either 1 or 0

Q:  Checkbox can be toggled via clicking on its caption.  Does this one have that attitude too?
A:  Yes it does.


Q:  The images seem to be tied up in C:\Switchbox, how to make it work regardless of the path?
A.  On all the samples I gave, I do that to insure that interested users will properly see the images on the development stage.  However, if you want to remove that binding on specific folder location, do these:

Remove the hardcoding of path I made inside the class on all occurrences; then add the images into your own project (other, other files, add).  One problem with that as I have said is you won't see those images while still in the developing stage.  Those will be reflected properly only in the exe:

Search all harcoding of path instances within the class, from:
This.Parent.Image1.Picture = "c:\switchbox\swbox"+Iif(This.Parent._value = .F.,"on","off")+ transform(This.Parent._theme)+".bmp"

Into:
This.Parent.Image1.Picture = "swbox"+Iif(This.Parent._value = .F.,"on","off")+transform(This.Parent._theme)+".bmp"

The class I will give you includes 2 samples, the one shown above and this other one, replacing checkbox in a grid with something like this:



Cool?


I have been a little bit intrigued by Emerson's message that interested party may request a beta of his very cool new project instead of simply attaching a sample in that blog but thinking about it, yeah I love his new way, maybe not for the same reason that in mine is I would love to know who will be interested in this class for I was not able to know who had shown an interest on some of my previous ideas except for those who notify me by way of comments or email.

So for the first time, I will not be providing a link where you can download an attachment of this one.  If you are interested in this, post a comment below with your email address and I will be sending it to you.  Post the request here under the comment section, not inside the forum.

Sounds fair?  Then I will say in advance to those who will be interested in using this class, Enjoy!

P.S.  I would like to thank some guys in pointing to me some misrepresentation in the original blog content like Woody and Mike Podjer whom without their comments I will simply fail to see such.


Update: December 26, 2009

I already have submitted the classes for free and easy download to Eric for the download section of foxite, so you will see those pending the decision of Eric.  In addition, I have created a thread in coderisland to have the same available for download.  Please click on the link below:

http://www.coderisland.com/forum/viewtopic.php?f=10&t=254


posted by sandstorm36 | 23 Comments
Filed Under: ,

Confining cell contents of a table from word to RTF


I have shown easy ways of importing and exporting from Word to RTF and vice versa in my past few blogs regarding RTF and Automation.  What I have not mentioned is what will happen when a  Word document has a table inside.

What will happen is the RTF control will not respect the boundaries of both cells and the tables itself.  See the image below (standard way):



Mike Gagnon told me yesterday that he is interested to see if I can come up with something regarding that table problem so I said I will try.  And so immediately after I logged out of foxite (plus my prepaid load ran up, darn it is annoying but I have no choice since I love frequenting the forum and sharing some of the newfound tricks I am able to implement on my side), I started on working on it immediately.

I spent a long time with the idea of stripping the tables of boundaries via "Convert Table to Text" method especially in playing with the delimiters but in the end I junked the whole concept as any result from that really does not appeal to me.

Pursuing another line of thoughts is when I came up with this good solution.  However, this is where I got stuck longer as even the macro recordings did not help me.  So I started playing around with combinations of word automation syntax; until my nephew and wife arrived from the field trip past 12 pm so we went to bed.  But some are already there so I said to myself, let's continue this tomorrow.  This morning I got exactly what I wanted.  See the images below:






As you can see, I also have added here the ability to change table appearance prior to importing.  Those are not the complete list, you can add more if you want.  Like with some of the tricks I have shown, you'll be in for a big surprise that we only needed few commands to attain what we need.  Confining cell contents, applying table format, importing into RTF and cleaning up the mess is just 22 lines of codes.  I am a simple man and I like my codes also simple. 

P.S.  Like some of my latest postings, these tricks are done without prolonged testings as I am too darn lazy for things like that.  So if you will find something wrong or has any additional ideas for further enhancements, please post it as comment here.  Thank you!

Get your attachment here.  Attachment should contain 3 files (ssrtf4.scx, ssrtf4.sct and Tables.doc).  Extract to c:\ssrtf4.  Enjoy!



posted by sandstorm36 | 1 Comments
Filed Under: ,

Spell and Grammar Checking in an RTF



I woke up very early today at 2:30 am because I have to drop my nephew and my wife on my nephew's school for their field trip in Mall of Asia and Enchanted Kingdom.  I was back at our house after 45 minutes and then I realize I can no longer go back to sleep.  Worse is I am not in the mood to watch cable fearing I will wake up my mom due to the TV sound and I don't want to do that as she is dead tired preparing last night things for her grandson.  I am likewise not in the mood to play any games or read paperbacks.  So I decided instead to open up those small notes I still haven't transferred to my cataloging software which I have also not yet read.  And I opened up one that seems interesting, i.e., "Putting Foxspell Checker to work" by Mike Lewis.  Sadly unlike most of his notes, this one did not show the hows.

Intrigued, I performed a search in my mass storage to see if I have saved more something relating to spelling and I found another by SlightHaze posted in TekTips with this note: "Special thanks and credit to http://www.foxite.com/archives/0000020310.htm.  His sample uses:

    .documents(1).CheckSpelling()

So that made me wonder since I have been playing these days with an RTF control and automation, why not see if I can implement it there too?  That would be nice!  And so I worked on it instead and with the help of Macro recordings, spell checking seems to be a piece of cake.  But I decided to work on it another way than what is shown in the sample which is very good to say the least.  However, this is an RTF format and so we needed another approach.  

What I have decided to do, to preserve everything, is to save the contents of the RTF control (textRTF property) somewhere inside my harddisk, in the user's temp folder and open it via automation.  So here we go:

    lcFileRTF = Addbs(Getenv("TMP"))+Sys(3)+".rtf"
    thisform.oleRTF.SaveFile(lcFileRTF)
    loword = Createobject("word.application")
    loword.Documents.Open(lcFileRTF)

So far so good.  To activate spell checking utilizing Word inside VFP and per the sample I have read, it is as simple as this:  

    loWord.ActiveDocument.CheckSpelling()

But then why be satisfied with simple spell checking when we can also check the grammar?  By studying the recorded macros, we can achieve both in VFP by this single command instead:

    loWord.ActiveDocument.CheckGrammar()

And we are on the go!  My advice, forget about CheckSpelling() from this day onwards!  Needles to say, use CheckGrammar() instead.

To update the content of the RTF control, all we need to do now is:

a.  Select the entire corrected document inside word:  
    loword.Selection.WholeStory()

b.  Copy into clipboard the selection:
    loword.Selection.Copy()

c.  Bring back the focus to the oleRTF:  
    Thisform.oleRTF.SetFocus()

d.  Select the entire original RTF via SendKeys():  
    loShell=Createobject("wscript.shell")
    loShell.SendKeys("^{a}")

e.  Finally paste the corrected ones:  
    loShell.SendKeys("^{v}")

Now what surprises me is it did not work! LOL!  It worked with the image insertion (Enhanced RTF Tool Revealed) but it does not in this case. I am not convinced though that the clipboard is empty so I changed tactic by replacing steps c to e with a simple:

    Thisform.oleRTF.textRTF = _cliptext

And viola!  RTF contents is replaced with what is in the clipboard which is the spell and grammatically corrected texts.

Gotcha!  But that's it!  Only pure texts.  Replacing contents of an editbox with corrected text is easy because editbox uses only pure text.  But the reason why we use an RTF control is so we can preserve the text formatting and the images. So above is totally unacceptable!

Back to the planning board, an easy solution pops in my mind again and that is, forget also about the whole copy-pasting scenario.  Make a complete turn around and do it again another way.  Intrigued?  Download sample to see how!






Get the attachment here.  Enjoy!


posted by sandstorm36 | 0 Comments
Filed Under: ,

RTF memo combined with other fields of a Table - into Word Report


RTF is a very useful tool in saving and preserving of formatting on images and text inside a memo field as I have shown in my Enhanced RTF tool.  Also speaking of that tool, I have used there commands I learned inside Foxite Archive in the printing of the current content of the RTF control.  However, a new question has been raised just last night on how to print said RTF content from the memo field together with with data from other more fields; using a VFP or Crystal Report engine.  For that, I will simply refer you to this link: http://fox.wikis.com/wc.dll?Wiki~MicrosoftRTFControl

Although what I will be showing now is how to preview or print the same (memo field + all other selected fields of a table), I chose automation in the process of generating report as that is what I am experimenting with these days.  

Here is the appearance of the sample attachment here:




Here is the preview of an output:





And creating a report using Microsoft Word is made possible by something like this:

*********************
oGenerateReport Method
*********************

LPARAMETERS lcAction
#DEFINE Enter loWord.Selection.TypeParagraph
#DEFINE PasteClipBoard loWord.Selection.Paste(_ClipText)
#DEFINE SelectLine loWord.Selection.EndKey()
#DEFINE ChangeFont loWord.Selection.Font.Name
#DEFINE ChangeFontSize loWord.Selection.Font.Size
#DEFINE BoldTrue loWord.Selection.Font.Bold = .T.
#DEFINE BoldFalse loWord.Selection.Font.Bold = .F.
#DEFINE UnderlineTrue loWord.Selection.Font.Underline = 1
#DEFINE UnderlineFalse loWord.Selection.Font.Underline = 0
#DEFINE wdFormatDocument 0


LOCAL lcFileRTF, lcRepDoc, lcFileDoc, loWord

* First save the content of the memo field to an rtf document

lcFileRTF = ADDBS(GETENV("TMP"))+SYS(3)+".rtf"
STRTOFILE(test.findings,lcFileRTF)


* Second, Save it into .doc format (temp doc)

lcFileDoc = ADDBS(GETENV("TMP"))+SYS(3)+".doc"
loWord = CREATEOBJECT("word.application")
loWord.Documents.Open(lcFileRTF)
loWord.ActiveDocument.Saveas(lcFileDoc,wdFormatDocument)
loWord.Quit(.T.)


* Then work on the other fields via automation, create a raw file for the temp report

lcRepDoc = ADDBS(GETENV("TMP"))+SYS(3)+".doc"

* Create an empty file

STRTOFILE('',lcRepDoc)
loWord = CREATEOBJECT("word.application")
loWord.Documents.Open(lcRepDoc)

* Immediately change its format into .doc

loWord.ActiveDocument.Saveas(lcRepDoc,wdFormatDocument)


* Change formatting

BoldTrue
ChangeFont = "Courier New"
ChangeFontSize = 12
_cliptext = PADR("Patient ID",20)+": "+ALLTRIM(patientid)
PasteClipBoard
Enter
_cliptext = PADR("Name of patient",20)+": "+ALLTRIM(patient)
PasteClipBoard
Enter
_ClipText = PADR("Age of patient",20)+": "+ALLTRIM(STR(age))
PasteClipBoard
Enter
_ClipText = PADR("Sex",20)+": "+IIF(sex=1,"MALE","FEMALE")
PasteClipBoard
Enter
Enter
UnderlineTrue
_ClipText = "Clinical Findings:"
PasteClipBoard
Enter
BoldFalse
UnderlineFalse


* Now get the content of temp doc where the RTF memo contents is and insert it here

loWord.Documents.Open(lcFileDoc)
loWord.Selection.WholeStory
loWord.Selection.Copy
loWord.ActiveDocument.Close
PasteClipBoard
Enter


* And insert the last field just for fun and to show that you really can place it anywhere

ChangeFontSize = 10
BoldTrue
loWord.Selection.ParagraphFormat.Alignment = 2  && wdAlignParagraphRight
_ClipText = "Date: "+DTOC(xdate)
PasteClipBoard


* Save it again for changes to take effect

loWord.ActiveDocument.Save()
loWord.Quit(.T.)


* Open or print it now

ShellExecute(0,lcAction,lcRepDoc,"","",1)


 

I hope that this sample will be useful to you as a guide on achieving the same on your end.  To further learn on how my sample works, get the sample here

Note:  You should extract the sample to c:\ssrtf2 for it to work outright.  If you will save it on another folder location, you should change the SET DEFAULT TO settings I placed in the load event of the sample form. 

Enjoy!


posted by sandstorm36 | 0 Comments
Filed Under: ,

Enhanced RTF Tool Revealed

I have finished isolating the RTF control from my project so I am now giving it to you as a basis or for whatever you may want to do with it.

Some more features I have not mentioned earlier is "hot tracking" inside RTF.  It means that when you clicked on a text inside the RTF control, it will show you the formatting it currently has like Bold, Italic, Underline, Alignment (Justification), Font Name, and Font Size; by changing the appearances of the respective buttons above the RTF control.  In addition, the color bar will also show the current color of a selected text inside the RTF.

I also have removed the conversion to PDF format of the RTF contents as this is dependent on the pdf printer which may or may not be installed on your unit.  To see how it can be done in my preference, please read "Am I being too persistent?" blog (lower part).


There are many things we can do more with this tool but I will leave the rest of other enhancements with your own imaginations.

Notes:

1.  This tool needs Richtx32.ocx (RTF Control)  which is part of VFP installation.  So I expect that you have that installed on your machines (under \windows\system32).  If you don't have that one, you can surf the web and place it in the folder where the exe is.  Then register it on your unit via this command:  regsvr32 richtx32.ocx

2.  This tool also uses ToClipboard() function which I have used in the image insertion.  That function utilizes "System.App" which can be sourced on the VFPX website so if you don't have it yet, that image insertion feature will not work.  Better get it on the abovementioned site if you still haven't have that one.  You should also place that in the folder where your exe is.

3.  I employed anchoring on objects here so if you are using a VFP without that feature yet, just remove those (if it is not autoremoved for you) for it to function properly.





And as promised, since this is an open source, you will also have the cool bitmap images I have pieced together.  Again, attachment is redirected  due to the same reason that I wanted to know how many downloads it will have.  So get it from  here.  Enjoy!

Added Notes (November 22, 2009):
  • Backspace is using KeyAscii of 8 which is the same value of Ctrl+H which I used in image insertion on the sample.  So pressing Backspace anytime activates that Image Insertion button.  To fix it, you can either disable the shortcut in the Keypress Event of the RTF object (look for IF keyascii = 8 && Ctrl+H) or you can try using another key combination for the image insertion button.
  • The property of the RTF HideSelected should be .F. so that the selection does not disappear when you lose focus by clicking on a button.
Thanks to Bernard Bout for these useful tips and findings.





posted by sandstorm36 | 1 Comments
Filed Under: , ,

Appending/Importing from Excel 2007's xlsx via automation

Most people don't realize that the SaveAs() event of office automation has a 2nd parameter, where you can select the format of the file you are saving.  And so I will be showing how this 2nd parameter can become very useful to most of us especially in importing and exporting of office files.  You will also see later how it has been instrumental to my enhanced RTF tool which I will soon share as well here.

With the change in the format of Excel 2007's xlsx, we are finding it now a little bit harder to APPEND or IMPORT data from it via the regular way since Office 2003.  So I will show you some tricks in achieving that, via automation. 

First, create something like this inside Excel 2007, then save it (do not Save As):




Next create these commands:

CREATE CURSOR junk (name c(10), age i, address c(20))
LOCAL lcFile
lcFile = GETFILE("xlsx") && Get the file you created and saved using Excel 2007 format (xslx)
loExcel = CREATEOBJECT("excel.application")
loExcel.Workbooks.Open(lcFile)
loExcel.ActiveWorkbook.SaveAs("c:\test.xls",6) && output will be comma delimited
loExcel.ActiveWindow.Close(.T.)
loExcel.Quit
APPEND FROM c:\test.xls DELIMITED
BROWSE NORMAL
CLOSE DATABASES all

Or this:

CREATE CURSOR junk (name c(10), age i, address c(20))
LOCAL lcFile
lcFile = GETFILE("xlsx")
loExcel = CREATEOBJECT("excel.application")
loExcel.Workbooks.Open(lcFile)
loExcel.ActiveWorkbook.SaveAs("c:\test.xls",39)
loExcel.ActiveWindow.Close(.T.)
loExcel.Quit
APPEND FROM c:\test.xls TYPE XLS && or XL5
BROWSE NORMAL
CLOSE DATABASES all


In case of IMPORTING data, you can do this:

LOCAL lcFile
lcFile = GETFILE("xlsx")
loExcel = CREATEOBJECT("excel.application")
loExcel.Workbooks.Open(lcFile)
loExcel.ActiveWorkbook.SaveAs("c:\test.xls",39)
loExcel.ActiveWindow.Close(.T.)
loExcel.Quit
IMPORT FROM c:\test.xls TYPE XLS && or XL5
BROWSE NORMAL
CLOSE DATABASES ALL

To make it more generic, you can do this:
LOCAL lcFile, lcTemp 
lcFile =
GETFILE("xlsx")
lcTemp = ADDBS(GETENV("TEMP"))+SYS(3)+".xls"
loExcel =
CREATEOBJECT("excel.application")
loExcel.Workbooks.
Open(lcFile)
loExcel.ActiveWorkbook.
SaveAs(lcTemp,39) && Place it in the temp folder
loExcel.ActiveWindow.Close(.T.)
loExcel.
Quit
IMPORT FROM (lcTemp) TYPE XLS && or XL5
BROWSE NORMAL
CLOSE DATABASES ALL
* Delete Temporary file used
DELETE FILE (lcTemp)


In that way, you are cleaning your harddisk immediately of the temporary file  used for above importing.

And there you are, easy ways of appending/ importing data from an xlsx format without the need of going inside that excel file and saving it into another format manually.

And here are the possible formats you can save your excel xlsx file into (thanks to Cetin Basoz for sharing this)

*** Constant Group: XlFileFormat
xlAddIn                                           18
xlCSV                                             6
xlCSVMac                                          22
xlCSVMSDOS                                        24
xlCSVWindows                                      23
xlDBF2                                            7
xlDBF3                                            8
xlDBF4                                            11
xlDIF                                             9
xlExcel2                                          16
xlExcel2FarEast                                   27
xlExcel3                                          29
xlExcel4                                          33
xlExcel5                                          39
xlExcel7                                          39
xlExcel9795                                       43
xlExcel4Workbook                                  35
xlIntlAddIn                                       26
xlIntlMacro                                       25
xlWorkbookNormal                                  -4143
xlSYLK                                            2
xlTemplate                                        17
xlCurrentPlatformText                             -4158
xlTextMac                                         19
xlTextMSDOS                                       21
xlTextPrinter                                     36
xlTextWindows                                     20
xlWJ2WD1                                          14
xlWK1                                             5
xlWK1ALL                                          31
xlWK1FMT                                          30
xlWK3                                             15
xlWK4                                             38
xlWK3FM3                                          32
xlWKS                                             4
xlWorks2FarEast                                   28
xlWQ1                                             34
xlWJ3                                             40
xlWJ3FJ3                                          41
xlUnicodeText                                     42
xlHtml                                            44
xlWebArchive                                      45
xlXMLSpreadsheet                                  46



Enjoy!


posted by sandstorm36 | 2 Comments
Filed Under:

Going Beyond Copy and Paste Part II

In connection with my "Going Beyond.." blog, I claimed that my app can open a word document aside from an rtf file.  Excerpt follows:



Also in Figure 3, you will see the action buttons I have included for the RTF control.  From left to right:

b.   Open a Word document (Ctrl + W).  Now this needs a very simple manipulations using VFP functions, see how later

e.   Export to Word (Ctrl + D)

 

Commands I used follows:

 

  1. Opening of Word Documents:
Local lcFile
lcFile = Getfile("doc,docx")
thisform.contRTF.oleRTF.textRTF = FILETOSTR(lcFile)

And the above commands are successful during my several attempts.  However, I failed to see that the reason why I was able to “open” my samples is because I open those I export to word (letter e above) with these codes:

 

  1. Exporting to Word:
Local lcFile
lcFile = Putfile("","","doc")
If !Empty(lcFile)
      Thisform.contRTF.oleRTF.saveFile(m.lcFile,0)
      If Messagebox("Data has been exported to Word Document!  Do you want to open it now?",4+32,"Exporting Successful!") = 6
            ShellExecute(0,"open",lcFile,"","",1)
      Endif
Endif

So when I open those “exported/converted” .doc files during testing phase, it works because in reality it is still an RTF file having .doc only as an extension.

 

I woke up this morning feeling a little refreshed and during retesting is when I realized this mistake.  Now the problem is how to “really” open a document file into an RTF control.  There are two things that came into my mind:

 

  1. Open word via automation, select all contents and copy in clipboard.  From clipboard I can programmatically paste it into the RTF via SendKeys() scripting.
  2. Open word via automation, and save it as an RTF format into a temporary file and then open that converted RTF file.  

Sounds good!

 

I post my question on letter a above and logged out of foxite then started playing with letter b on my end.  I have seen and known people using automation before but I can’t find any use for me yet so I never paid attention to it.  I play when I need, that is always my way.

 

Ok, opening and saving into an RTF extension seems to be easy with these codes:


LOCAL lcFile, lcRTF
lcRTF = ADDBS(GETENV("TEMP"))+SYS(3)+".rtf"
lcFile = GETFILE("doc,docx")
loWord = CREATEOBJECT("word.application")
loWord.Documents.Open(lcFile)
loWord.ActiveDocument.SaveAs(lcRTF)
loWord.Quit(.T.)
thisform.contRTF.oleRTF.textRTF = FILETOSTR(lcRTF)


But, I found out that I am doing the same as before which is saving a document with an RTF extension but in reality is really a .doc file.  Being relatively new with automation, all I can do is record a macro then check what happens inside:

 

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 11/19/2009 by jun
'
    Documents.Open FileName:="""This is a simple test.doc""", _
        ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
        PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
        WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
        wdOpenFormatAuto, XMLTransform:=""
    ChangeFileOpenDirectory "C:\"
    ActiveDocument.SaveAs FileName:="This is a simple test.rtf", FileFormat:= _
        wdFormatRTF
, LockComments:=False, Password:="", AddToRecentFiles:=True, _
        WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
         SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
        False
    ActiveWindow.Close
End Sub

 

Looking at above, it seems we need to save into wdFormatRTF.  So I did a couple of runs:


loWord.ActiveDocument.FileFormat(“wdFormatRTF”)
loWord.ActiveDocument.SaveAs(lcRTF)
***
loWord.ActiveDocument.SaveAs(lcRTF,”wdFormatRTF”)
loWord.ActiveDocument.SaveAs(lcRTF,”FormatRTF”)
loWord.ActiveDocument.SaveAs(lcRTF,”RTF”)


and some more variations all with error generated.  Finally I decided to read the error on the last test, LOL!  And it says “OLE error code 0x80020005: Type Mismatch” so a thought hit me and I changed the 2nd parameter into integer like this:

loWord.ActiveDocument.SaveAs(lcRTF,1)  

 Still saves .doc into the same type.  So I started moving up and finally I hit the mark with this:

loWord.ActiveDocument.SaveAs(lcRTF,6)

So there you go.  A very easy way of converting a word document into an RTF format (or any other supported formats) via automation (tested using Microsoft Word 2003 and 2007).

 

Hope this will be useful to you!  I will release the whole project of the RTF control pending more tests on my side.  Right now, that is the only thing that seems to need modification.  Enjoy!


posted by sandstorm36 | 2 Comments
Filed Under: ,
More Posts Next page »