Calvin Hsia's WebLog

thoughts from a professional developer

Browse by Tags

Tagged Content List
  • Blog Post: Cartoon animation works great on Surface Pro

    I showed my 9 year old son a cool drawing program called Physamajig , in which users can draw objects, which behave like real physical objects, including reacting to gravity, friction, and bounce. He was having fun with it on my Surface RT and it reminded me of another program. Years ago (around 1981...
  • Blog Post: Create multiple threads to see if work is done simultaneously

    When you hear about threads and threading, you hear that they allow concurrent execution of code, which is supposed to lead to better performance. Most computers nowadays have more than one CPU, meaning that each CPU can be executing code at the same time. Hit Ctrl-Shift-Escape to bring up Task Manager...
  • Blog Post: Returning data from a recursive method

    Sometimes you need to write a method that requires recursion to be elegant. Often that method needs to accumulate data between recursion levels There are many ways to do so, and some are more elegant than others. I like the Optional Parameter method: it requires no additional class or static (shared...
  • Blog Post: Comment/Uncomment code to switch versions quickly without using macros

    In a typical day, I write or debug programs in several languages: typically Foxpro, C#, VB, C++ and 32 bit assembly, with an occasional MSIL, IDL and 64 bit ASM thrown in. Sometimes, I like to switch between one version of code and another. This is useful if I want to do side by side comparisons...
  • Blog Post: Make your code more maintainable: The evils of the Return statement

    What does it mean to make code more maintainable? Certainly obfuscated code is hard to understand, by definition. A big part of maintainability is making it easier for others to read and understand what the code is doing. Your code may have been working for years, but then somebody comes along...
  • Blog Post: Use a dictionary to help create a mnemonic

    I was using a program that was yet another TLA and I wanted to create a mnemonic to help me remember what it was. One of the letters was “k”, so I wanted to find a word that starts with “k” Simple: load a dictionary, search for words starting with “k” and browse through them: “Killer” sounded fine...
  • Blog Post: How to interrupt your code

    I received a question: Simply, is there a way of interrupting a vfp sql query once it has started short of closing down the process ? I am running some complex queries on very large datasets which can sometimes take many minutes to complete. Typically, a program that runs on your...
  • Blog Post: Examine .Net Memory Leaks

    Writing programs using .Net is very productive. One reason is because much of memory management is “managed” for you. In C, C++ and other “native” languages, if you allocate memory, you’re responsible for freeing it. There were stopgap measures, like destructors, SmartPointers and reference counting...
  • Blog Post: Is this a Vista bug?

    A customer reported a crash of a VFP application while running under the new version of Windows: Vista. The customer code attempted to automate the configuration of the web server (See Automating Web Site Administration Using IIS ). Specifically, there was a scenario under which the user code calling...
  • Blog Post: Write your own hangman game

    Many years ago (1985) I wrote a C program to play Hangman. I had decoded a word processor spelling dictionary for my word source. More recently, I have encoded 2 spelling dictionaries for general purpose use: 1 with 171201 words, the other with 53869. There’s some pretty serious compression to...
  • Blog Post: Windows Security and how it affects running generated code

    Here I described how VFP generates executable code and runs it for early and late binding COM clients and implementing COM interfaces. However, there is an important issue with generating and running executable code in the same process. A computer has a processor (or a few) that fetches instructions...
  • Blog Post: Do you know everything about Factorials?

    When I was in 7 th grade at Amity Junior High School in Orange Connecticut , I gave a presentation on Factorial numbers. Here’s some interesting code: FOR i = 1 TO 80 ?i,Factorial(i), SQRT ( 2 * PI ()*i)*(i/ EXP ( 1 ))^i ENDFOR PROCEDURE Factorial(n) IF n= 1 RETURN n...
  • Blog Post: What is taking up the space on your hard disk? TreeMap it!

    Several years ago, I saw a presentation from Microsoft Research about online communication in communities . In particular, a group was studying online communities based on NewsGroup message traffic volume. One of the results was a graphical view of the newsgroups called Netscan . I didn’t think much...
  • Blog Post: Binding to Internet Explorer events: bug in Typelibrary

    I was using the web browser control and getting some errors when binding to its events. This can be duplicated with the code below. To generate the event class, open the object browser (Tools->Object Browser) and select the Microsoft Web Browser Control. Navigate to the DWebBrowserEvents2 interface...
  • Blog Post: Third Party application does work as a COM+ application

    A few months ago, I reported a problem that a customer was having with a particular 3 rd party product that seemed not to work with Visual FoxPro. It was a COM object that could be instantiated via CreateObject. I was quite surprised that Windows guru Raymond Chen (author of the great blog: The...
  • Blog Post: Very Old Program

    I was doing some spring cleaning and came across a computer printout of a program I wrote in August 1974, or about 31 years ago! That brings back a lot of memories. Coincidentally, a couple coworkers were discussing the CaSing of computer languages. What languages were in UPPER case, lower case, MiXed...
  • Blog Post: Floating Point calculations: comparing with zero

    I was asked about floating point calculations. In particular, I can write code like this: x= 3.4 y= 10 Result=x*y ?Result,Result= 34 IF Result= 34 ?"This code will execute if result = 34" ENDIF *Output is 34.0 .T. If you add 3 zeros to x (change x to 3.4000)...
  • Blog Post: Calling the Windows APIs for Large Files

    A customer was trying to use FoxPro to handle large files. The files that Fox handles natively (like tables, indexes) are limited to using 32 bit addressing, (2^32 = 4 gigs). Back in the old days (not that long ago), there were no hard disks > 2 gigs. Who would ever need more?<g> I’ve been using...
  • Blog Post: Relaxen und watchen das blinkenlights. What lights?

    In the old days, computers had blinking lights. Indeed, old movies used to show computers working with blinking lights and tape reels moving back and forth. My school computer was a PDP-8/L with a whopping memory of 4K 12 bit words back in 1971. (Here’s a picture of similar machines. Mine was like one...
  • Blog Post: Undocumented APIs and 16 bit DLLs

    As a long time software company, Microsoft has certain procedures to follow when releasing software to the public. A change to the policy was instituted at Microsoft last year. A brand new tool would scan all released software to see if any “undocumented” APIs were called. Apparently as a result of all...
  • Blog Post: Heartbeat: Garbage collection in VFP and .NET are similar

    VFP stores user defined names such as variable, field, property, class and procedure names in a table. When the name table runs out of space, the GC begins. All the entries are marked as unused. Then all the various name table clients are sent a message to flag their names as used. These clients include...
  • Blog Post: Permutations

    I saw this post which shows some VFP code to permute a string. For example, there are 6 permutations of “abc”: abc, acb, bac, bca, cab, cba There are n! permutations of a string of length n. I dug up some old code that did the same thing in fewer lines. nn=0 permute("abcd",0) PROCEDURE permute(cstr,nLev...
  • Blog Post: Wite your own RSS News/Blog aggregator in <100 lines of code

    The internet is a great way for people/entities to publish information. An RSS reader is a tool to help funnel only the information that you think is important to you. You can subscribe to RSS sources (Blogs, news sites, businesses, authors) by choosing a button that says Syndication, RSS, or XML button...
  • Blog Post: Do you like reading a blog author? Retrieve all blog entries locally for reading/searching using XML, XSLT, XPATH

    If you like reading a particular blog and want to read more from the same author, you can subscribe to the blog using RSS and any number of blog readers, such as newsgator , intravnews . This will get a few current entries (RSS is limited to 15 entries ) and any subsequent ones, but how do you retrieve...
  • Blog Post: Use a simple XSLT to read the RSS feed from a blog

    On most Blogs, there is a link called “Syndication”,”RSS”, or “XML” that is the RSS feed. Click on that, and you see an XML document that contains some recent blog posts. This simple code reads the RSS feed for my blog, does an XSLT transform of the XML to a simple HTML file, and opens the HTML in IE...
Page 1 of 2 (49 items) 12