/Home /Archive /Syndicate /Blog /Support /About /Contact  
All Visual Basic Feeds in one place!





Channel: Calvin Hsia

How do you find out why your computer or a running program is so slow? Here’s one way.   Let’s attach the VS debugger to VS itself. The main executable for VS is devenv.exe.   Start Visual Studio 2008. This will be the “debugger”   Choose File->Open Project     C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe   (You can also choose Debug->Attach to process to debug ano ... [ read more ]


In the last post, Area fill algorithm: crayons and coloring book , I showed a program that emulates a kid drawing in a coloring book.   However, the algorithm wasn’t very efficient, and would explode even if you had a simple drawing: it was using the stack to store where to go.   The heart of the routine:                 void AreaFill( Point ptcell) ... [ read more ]


Kids know how to use crayons and a   coloring book. How do you write such a program?   In my last post ( Which pixels do you turn on when you draw a line? ) I showed how to draw a line. Now suppose you have some lines or shapes already drawn. How would you write code to fill in an area bounded by the drawn pixels?   IOW, imagine you’ve drawn a circle. You want to fill the circle with a color. Right click inside. What code should run? Wha ... [ read more ]


When I wrote my cartoon animation program almost 30 years ago (see Cartoon animation program ) I needed to know how to draw a line.   Of course, nowadays, we just call a library function that will draw a line given two points.   If you think about it, the problem is quite complex. Imagine a rectangular array of pixels. Which ones do you paint in order to “see” a straight line?   If the desired line is horizontal, or vert ... [ read more ]


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 of behavior.   One way to do this is with preprocessor macros, like this:   #If   SomeValue      &nb ... [ read more ]


A cartoon can be thought of as a series of drawings. To simulate movement, the drawings can be slightly different from each other.   Remember drawing simple cartoons using a pad of paper? Simply flipping through the pages made the drawings come to life.   This was tedious work: a computer can help.   Just after first IBM PC came out in Aug 81, I wrote a cartoon animation program in C++ and assembly code. The concept was very simple: ju ... [ read more ]


Much of my time is spent using the Visual Studio debugger examining code to figure out how it works and how to fix it. When stepping through a function, the values the function uses are very useful for code understanding. The debugger shows these values in the Watch/Locals/Auto/Callstack windows.   For example, the Locals window shows the Local variables used by the current code while at a breakpoint. Each variable might be a structure or class with many members. You can click to expand ... [ read more ]


  Suppose you have some old code lying around that creates a Win32 window with an HWnd (perhaps ATL , MFC , or just C/ C++). For example, if you type some erroneous code into a VB application in Visual Studio:           Dim x=4: catch ex As Exception     The “Exception” will be squiggled and the end of the squiggle will have a red underline, indicating the presence of a Smart Tag. ... [ read more ]


When running VB.Net or C# code, often it’s useful to call native code. One way is using PInvoke. (for other ways, see How fast is interop code? )   For example, you can call GetWindowText to get the title of a window. To get it’s managed signature, you can use this code from http://www.pinvoke.net/default.aspx/user32/GetWindowText.html       <DllImport( "User32.dll" , SetLastError:= True , CharSet:=CharSet.Auto)> ... [ read more ]


I have a collection of almost 30,000 pictures and videos. When I add new pictures to the collection, I had been running a script file to synchronize the collection across various machines.     for %%s in (\\calvinh6\e$ \\calvinh3\e$ \\calvinh4\e$) do (                 robocopy   /s /fp %2 %1 %%s\pictures\%1         &n ... [ read more ]


Today’s digital cameras take pictures with much higher resolution than many computer screens. My Canon PowerShot SD800 IS camera takes pictures at 3072 x 2204 resolution.   One of my laptops died recently, and I noticed that local laptop retailers have machines with 1280 X 1024 resolution. I much prefer a higher resolution display, so I ordered a customizable Dell Inspiron 1525 with 1680 x 1050. (I’ve been ordering computers from Dell for over 20 years, back in ... [ read more ]


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 and wants to add a feature, which might break your code.   Sometimes the behavior of code isn’t quite right, so you might need to investigate somebody else ... [ read more ]


In my prior post I show a Windows Form version of the typing tutor game.   Here is a WPF version. Start Visual Studio 2008. Choose File->New->Project->VB->WPF Application. Dbl-Click the form in the designer to open the code window. Paste in the code below.   Notice how the logic differs from the WinForm version. In that version, the position of the letter object is changed by manipulating the Top and Left properties of that obj ... [ read more ]


In this post, Create your own typing tutor! is code to create a game for learning the letters of the keyboard by typing the letters that fly across the screen. As times goes by, they fly faster.   Below is a VB version of the game. Can you score higher than 3000?   Start Visual Studio (most versions will work). Choose File->New->Project->VB->Windows Forms Application. Paste in the code below.   In this link: ... [ read more ]


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!   The Dictionary dll (that you can download from the link below) actually contains 2 separate dictionaries in 679k bytes! The big one (Dictnum=1) h ... [ read more ]


How fast is interop code? If you’re in one kind of code and your calling another, what is the cost of the interop?   For example, .Net code can call native C++ code (like Windows APIs) and vice versa. Similarly with Foxpro and C++ code. .Net code is often referred to as Managed code because much is managed for the programmer, such as memory allocation. That leaves  C++ code to be called “Unmanaged”. An easy way to interop with C++ code is to use COM (Component Object ... [ read more ]


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 computer has a main thread of execution. On this thread, the processor is fetching instructions from memory a ... [ read more ]


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, which helped, but were still cumbersome.   Foxpro manages memory for you, and has used garbage collection for decades: Heartbeat: Garbage collection in ... [ read more ]


My prior post ( Create your own Test Host using XAML to run your unit tests ) shows how to create a form and present it to the user. The user can resize and reposition the form, even on a 2 nd monitor.   When the user exits the form, we can persist or remember the form size and location, so the next time the user form starts up, it will be positioned/sized as before.   The happens to be a XAML form, but it could be a WinForm for this to work. (The My.Se ... [ read more ]


A few days ago, somebody came into my office and plopped down a box. It seemed very light. He said that it was a new PC. I thought hmmm…. The box seems empty…Why am I getting a new PC?. Apparently an inventory was made and my current hardware was at the lower end of the list.   So I started up the Dell Optiplex 755 with 4 gigs of RAM, and it was running Vista 64. Super: I hadn’t done much with 64 bit code yet.   Sure enough, debugging ... [ read more ]


Often I want to write the SAME code that will display the name of the currently executing method or function. That way I can just copy/paste the same code into multiple methods.   For example, in sub Form1_Load I could put this line:         System.Diagnostics.Debug.WriteLine( "in Form1_Load" )   In Button1_Click I’d have to out a different line:         Syste ... [ read more ]


While writing software over a period of weeks or months, various components of the software get completed at various times. You’ve tested and you’re satisfied they work, and you move on to develop another feature. Or you might check in the source code and somebody else on your team might break your code accidentally with another checkin. This break might not be discovered for days or months.   Checking in test code for the feature alongside the feature code can help prev ... [ read more ]


Visual studio creates project files for you for the   various languages, such as C++, C#, VB. These files are XML format, and can thus be queried.   Try this: open any non-temporary Visual Studio project (see Use temporary projects in Visual Studio ) , right click on it in solution explorer, choose unload, then right click again, then choose edit. This opens the Proj file (.vbproj,.csproj) in the XML editor   I wanted a way to get just the Refer ... [ read more ]


I was running out of disk space on one of my machines, so I used my TreeMap program to see where I could delete files to save space.   I saw that I still had VB6 on the machine, and I didn’t need it on that machine any more, so I uninstalled it.   It's amazing how little disk space VB6 occupied, compared to VB.Net! I remember when FoxPro came on floppy disks, and Turbo Pascal came on a single (360k ?) floppy disk!   The next year (actual ... [ read more ]


My prior post showed how to create XAML WPF and put it on your Winform App. We can go one step further: add XAML to a UserControl, which could then be made into an ActiveX control, which could be hosted by Fox, VB6, or Excel.     Start Visual Studio 2008 ( as admin on Vista !! : (to register for COM interop, you need admin privileges)) Choose File->New Project->Visual Basic->Windows->Class Library. Call it WPFClass &nbs ... [ read more ]
Many of you already have a Window Forms application. You can add WPF to your existing application quite easily using the ElementHost class , which can be added as a control to your form.   (You can also go the other way: host a Windows Forms control in a WPF element with the WindowsFormsHost , which can be added to your XAML)   This will bring you the ability to animate or scale parts of the UI for your applications. Notice how the Winform button rescale ... [ read more ]


Here's a sample of creating dynamic XAML to display arbitrary XML   You can use the XML DataProvider to supply XML data to XAML, a web service, or you can use a Query.   Each way, you can generate XAML dynamically to display the XML. (echoes of XSLT)   I took the prior sample ( Create your own media browser: Display your pictures, music, movies in a XAML tooltip ) and changed the query to generate XML:     ... [ read more ]


In the last post Create your own media browser: Display your pictures, music, movies in a XAML tooltip , we created a query of your local media and displayed it.     Today, we'll make a query to my Foxpro picture database of 28,000 pictures/movies. We'll make the query result structure to be similar to the prior post, so the same code will show the picture or movie in a tooltip. The query is for "wheel", which includes pictures of cartwheels, Ferris Wheels, wh ... [ read more ]


In my prior post , I showed how to use XAML and XAMLReader to create inline XAML to display the results of a query.   Today, let's take it a step further: let's create a query of all the media (pictures, movies, music) in your "My Documents" folder and display the names and sizes in a ListView. As you navigate the list, a tooltip appears showing the media.   You can click on the tip and move it around the screen, or you can mousewheel to zoom in ... [ read more ]


Using WPF, it’s great to use declarative XAML , but it’s also great to use dynamic code. With VB’s new XML Features , you can do either.   Below is a sample showing how to use XAMLReader to take XML generated in code and use it to create XAML to present as UI.   The XAMLPanel demonstrates some of the ease of defining UI via XAML, as well as hooking up events. You might want to use the XAML designer in Visual Studio 2008 to get the intellisense fo ... [ read more ]


We can subclass the prior Windows Presentation Foundation (WPF) class called Browse that displays the results of a query. This subclass will add a WPF Popup to it.   The popup can easily be added to either a ListView or the ListBox sample I posted earlier ( Use LINQ with WPF : Styles and DataTemplates in code )   The code sample below is exactly the same code as the prior Browse post except that it uses a subclass of the Browse class ... [ read more ]


In my last post, Use LINQ with WPF : Styles and DataTemplates in code , I showed how to use DataTemplates in code to show the results of a query in a ListBox.   Let's make a reusable class called Browse which creates WPF content as a ListView from a LINQ query and generates columns and headers. It also uses DataTemplates to databind   The headers will sort the columns when clicked. Also, you can resize and change the order of columns by clicki ... [ read more ]


© 2005 Serge Baranovsky. All rights reserved.
All feed content is property of original publisher. Designated trademarks and brands are the property of their respective owners.

This site is maintained by SubMain(), a division of vbCity.com, LLC