Wednesday, August 29, 2012

ListBox Trick # 1 - Files with Filtering

This again is based on a query inside Foxite. The question goes:

I need to get tables only have or start names as month1,month2.....
thisform.text1.value=getfile("month.dbf")

While GetFile() is yet another easy way to get a fullpath(), it is not flexible on the filename part; only on the extension part where you can use wild characters.  You cannot do this:

thisform.text1.value=getfile("month*.dbf")

As the asterisk there will be construed by VFP as part of the filename, and not as a wildcard.  Same goes with LOCFILE() and  PUTFILE()  where you cannot also use a wild character  on the filename.

Ordinarilly, the immediate thinking goes to these steps:

  • Use ADIR() to gather filenames starting with the word "Month" and with extension "dbf": 
 ADIR(laMyFiles,'Month*.dbf')
  • Create a cursor to hold the result and perform INSERT INTO .. FROM ARRAY laMyFiles
  • Create a grid to show the result, then put some more codes either on AfterRowColChange or Click events to transfer the result into the textbox


However, while that is one of the best ways to do those,  there is yet simpler way which is using the highly unutilized feature of listbox known as RowSourceType = 7.  It involves less coding and actually is very easy to use.  For the sake of this example, I will simply filter the list of files with all dbf:

Saturday, August 25, 2012

Combobox Tricks - Part I


I actually posted this or some of this in the defunct www.junblogs.com and has intentionally did not forwarded it in this blog  thinking it is already read before by most of my followers, so they know this now.  But several times I am still seeing some quires regarding comboboxes that I decided to revive this plus add some more tutorials in the near future.

So let us start again on combobox tutorials with this trick, hiding columns and some other things.

The way some developers do to hide let us say the 2nd column from view is to change that 2nd column's width to zero.  While it is good, there will still be a space alloted and shown for that zero-width column:


loTest = Createobject("frmCombo")
loTest.Show(1)

Define Class frmCombo As Form
      AutoCenter = .T.

      Add Object combo1 As ComboBox With ;
            RowSourceType= 6,;
            RowSource = 'junkcbo',;
            Value = 0,;
            BoundColumn = 2,;
            BoundTo =.T.,;
            Style = 2,;
            top = 50,;
            left = 10,;
            Width = 200,;
            ListIndex = 1,;
            ColumnCount = 2,;
            ColumnWidths = '200,0'

      Procedure Load
            Create Cursor junkcbo (xName c(30), xCurrency c(3))
            Insert Into junkcbo Values ('Philippines','PHP')
            Insert Into junkcbo Values ('Papua New Guinea','PGK')
            Insert Into junkcbo Values ('Australia','AUD')
            Insert Into junkcbo Values ('United States','USD')
            Insert Into junkcbo Values ('Indonesia','IDR')
            Insert Into junkcbo Values ('India','INR')
      Endproc

Enddefine


So to fix that problem, you have to hide the column lines to make it appear that column1 and column2 are just one.  Under combo1 settings, you have to add this line:

Friday, August 17, 2012

Spell Checking & Correcting Form Captions

Here is a little something that is asked just now inside foxite forum, i.e., how to get the captions of each objects inside a form, use Word's Spell Checking feature to correct those, and then update the object's captions with the corrected one.

While I do not know why this is needed, well we try to give what they request.  So here is a sample of how to do exactly just that via word automation:

Tuesday, August 14, 2012

Drag & Drop III - Moving Borderless Forms

I know there are already lots of samples shown by experts on how to drag a borderless form.  But just in case you wanted to see another simple way, here it is.  If you will be simply allowing dragging via the form's surface itself, then you can simply do this as shown in my codes below.  If there are lots of objects where you need to bind the dragging, like a fake title bar, the caption on that fake title bar, etc.;  then you need to use BindEvent().

The reason why I am sharing this is because my earlier approach is to use MouseDown() first to perform validation whether left mouse button is clicked, then call another user defined method like MoveMe().  What I wanted to show here is a more direct usage of an object's MouseMove() event.  You drag (move) things via the left mouse button, so use MouseMove.

Here are the codes:

ssClose3

Update August 16, 2012

Added the ability to pin form(disallow dragging) or not on-the-ply.  This is made possible by adding an ssSwitch inside the class.  You can set up the default whether form is pinned or not via lNoMove parameter and interactively thereafter it can be changed any time.  Here is how it looks like:


==============

I was not suppose to create a new ssClose class but MK Sharma, my first and among my most supportive subscribers, has requested a new ability for ssClose and ssClose2 classes which is to be able to be placed on the right side of the form instead of the left.  Said request/need has risen just because he is using a Menu and his users are accidentally closing his forms instead of clicking the Menu.

However, after receiving said request, I encounter a major problem, i.e., I forget where I saved (if ever I saved) the source PSD file I used for ssClose images.  Darn!  And I cannot simply flip those final images because the word close will be flipped as well.  Drat!

Anyway, also just because of that lapse on my side, I was forced to design a new button.  And since some may have found my ssClose designs appealing on their end, I decided to create this new class instead of replacing the old ones.  Here is the new class:



Aside from this being prettier (my taste) than its ancestor, I decided to add more features for this one.  Here are the new parameters:

LPARAMETERS nPosition, nBorderColor, nBackColor, lTransparent, cHotKey, nBorderWidth, lNoMove, lFixedBorder, nSpecialEffect

Thursday, August 9, 2012

2012 Southwest Fox - Looking Forward

October is fast approaching and every passing day I am starting to look forward into this year's SouthWest Fox DevCon.  Most especially after I looked into the available seminars.  Here are the list of Sessions:

    There are 7 conference tracks at Southwest Fox. "Level" shows the expected level for attendees for a session.

    Pre-Conference: These half-day sessions are offered on Thursday, October 18, and are available for an additional cost

    Extending VFP: The sessions in this track look at ways to extend VFP's reach, by using it together with other products or by taking advantage of native extension capabilities.

    Solidifying VFP Development: This track appeals to all VFP developers. Sessions cover either VFP fundamentals, aimed at those newer to VFP, whether moving up from FP2.x or coming to VFP from other languages; VFP best practices, aimed at helping all VFP developers improve; or in-depth looks at aspects of VFP that some developers may not have mastered yet.

    Taking Advantage of VFPX: The sessions in this track showcase the projects in VFPX, providing attendees with enough information to put those projects to work for them. These sessions are deep dives into specific VFPX projects.

    Technology for VFP Developers: This track looks at tools, technologies and techniques to make life as a developer easier and more productive.

    Moving VFP Applications Forward: This track covers topics related to taking VFP applications beyond the desktop, such as with web applications or mobile technology, as well as alternatives for new platforms and future application development.

    Post-Conference: These sessions are offered on the afternoon of Sunday, October 21; see the Workshops page for details. 

Please visit http://www.swfox.net/sessionsswfox.aspx for a more detailed info on courses available, speakers, and a lot more things.

To make things a lot easier, an online registration is now available here: http://geekgatherings.com/Registration


I would like to thank the late Ceil Silver, Doug Hennig, Tamar Granor and Rick Schummer; and the rest of the Committee involved in Ceil Silver Fund for giving some of us, developers who cannot easily attend on our own, the opportunity to  be part of the SouthWest Fox Devcon.   Plus to all of you who nominated me to be this year's ambassador. Believe me, the cost they have to shoulder plus the efforts they have to pour out in bringing a developer like me into the DevCon is huge.

I hope I will be seeing some of you whom I have known by names over the years  inside and outside of Foxite there. See you in October!

Jun Tangunan (sandstorm)