Results for "Author: james vincent carnicelli"
Read an entire text file into a string in one call.
Data entry control for U.S. postal addresses in a single text box with automatic parsing and assembly. If your application has to allow users to enter and view snail-mail U.S. postal addresses, your usual choices are separate text boxes for the parts of the address or one big text box for the whole thing. Usually, which it is depends on how you store it. This control gives your users the ease of having a single text box and your program the power to pick out the two street address lines, city, state, zip code, and 4-digit zip code extension as separate parts. Does format validation, state abbreviation validation, state name conversion to abbreviations, data parsing and assembly to and from the same plain-text representation seen by users. Provides simple explanations for why a given address is invalid, if so. Also provides many of the most commonly-used properties and events of a typical text box. As easy to use in your project as an ordinary text box. Extensive documentation provided in the code. Also includes an extensive HTML help file and demo project. Recent Updates: 5/18/2000: Added .Populate() method 5/22/2000: Vastly improved parser to accommodate odd an incomplete addresses and added public array of error codes / messages. Please vote for this code if you like it.
Nifty little utility (with source project) to help you use Windows system colors (e.g., "Button Face" or "Window Text") in your code. For each color, shows a preview, the name you see in IDE property window's drop-down list for colors, the VB constant, and the hex value. Tiny, easy to use, and fast. Please vote for this entry if you like it.
I use arrays all the time, so I thought I'd put the functions I commonly use together into a library. Easy to read code. Routines include: - ArrayCopy(List, ListToCopyFrom, [StartAt], [Length]) - ArrayAppend(List, Item) - ArrayRemove(List, Index) - ArrayInsert(List, Index, Item) - ArrayConcatenate(List, ListToCopyFrom) - ArrayTrim(List, [TrimFromBeginning], [TrimFromEnd]) - ArraySplice(List, StartAt, Length, [ListToCopy]) - ArrayToString(List, [Separator]) Clean code with lots of comments in reusable module. Also includes an extensive reference in HTML. Tested with VB6, but should be compatible with all modern versions and VBScript (with minor modifications). Please vote for this code if you like it.
Library of routines for typical string processing, including parsing, translation, and validation. Routines include: - StrReplace(Text, SearchFor, ReplaceWith, [Compare]) As String - StrSplit(Text, SplitOn, [Compare]) As Variant - FromHex(HexNumber) As Long - LeftPad(Value, Size, [PadCharacter]) As String - RightPad(Value, Size, [PadCharacter]) As String - AreLetters(Text) As Boolean - AreDigits(Text) As Boolean - AreLettersOrDigits(Text) As Boolean - AreInSet(Text, CharacterSet, [CaseSensitive]) As Boolean - ParseN(Text, StartAt, PatternArray, ValueArray, [PosPastEnd], [StopAt], [Compare]) As Boolean Clean code with lots of comments in reusable module. Also includes an extensive reference in HTML. Tested with VB6, but should be compatible with all modern versions and VBScript (with minor modifications). Please vote for this code if you like it.
How to keep your VB application from being a CPU hog using DoEvents.
Conceptually, non-volatile RAM is any RAM (random access memory) that is not lost because the memory device loses (external) power. The NvRam class implements this in a primitive but powerful way: by writing to and reading from a data file in real time. In principle, your code need only identify the location in this "memory" (as in an array) that a given variable is stored in and the class does the rest. Here's a simple example of how it works: Dim MyVar As Long Set Nvr = New NvRam Nvr.Connect "C:\MyData.dat" 'Read in value, 'do something with it, 'and write it back out. Nvr.ReadVar MyVar, 20 MyVar = MyVar + 1 Nvr.WriteVar MyVar, 20 Nvr.Disconnect Here are some good applications for this class: - Protecting in-"memory" data from power failures. - Maintaining large amounts of data with almost no memory overhead. - Maintaining program state across run-time sessions. - Sharing data among multiple processes. While it does not yet have built-in support for storing user-defined data types or objects, all primitive data types (e.g., Long and String) are supported. (Variants are allowed, so long as they are late-bound to one of the primitive data types.) Also missing is a way to shrink the size of the data file, the equivalent of ReDim Preserve. Feel free to make suggestions or add support for such features, so long as credit is given for the original code. While tested with VB6/NT4, this should be compatible with any version of Windows that supports the CopyMemory() API call and which has data types with the same sizes as with Win32 systems like NT. Your comments and vote are welcome.
Simple ways to create data structures on the fly without creating classes, user-defined types, etc., and how such structures can be more flexible, data-driven, and even self-defining.
This article introduces you to the basic concepts behind Visual Basic's run-time error handling methodology. You'll learn what causes run-time errors, how to deal with them, and how to generate them yourself. A good understanding of run-time errors is critical to becoming a seasoned VB programmer. Arm yourself now.
This is an old utility I made a few years ago in VB 5. It can display the main project files in a .VBP and display the contents and a summary of what's in its code modules, color-coded. It was designed to let any VB project be a reference for itself. To that end, it picks out any comments that appear immediately before a subroutine or function. And since its output is a RichEdit control, you can copy and paste anything it outputs into Word or some other editor for instant documentation. While it's probably lacking a few reserved keywords and might be a little out of date, it's got a valuable core of logic to parse VB code and an algorithm to color-code VB stuff for a RichEdit control. I welcome comments and improvements, so long as you give credit where it's due. Please vote for this code if you find it useful.
VB (version 6 and earlier) doesn't offer any decent way to create a new class that inherits public members from an existing one. Here's an easy, if inelegant, way to simulate inheritance.
This is a set of controls designed to make creating TCP/IP client/server applications very easy. There's a single-connection client control and a server socket bank that automatically manages connections from clients. There are even discrete listener and server sockets, if you want to implement your own socket bank. This is all in an OCX and delivered with a tiny chat client/server program to demonstrate how easy it is to use. (The OCX source is included.) While the client adds only a little functionality (and a lot of stability) to the basic Winsock control's methodology, the server socket bank offers the huge advantage of dealing with listening for incomming connections and managing them for you, a notoriously tedious and sometimes hazardous task. These sockets controls even make dealing with sending and receiving binary data easier than with the Winsock control. They have their own internal receive buffers, which you can pick apart at your own pace as plain text or byte arrays. You can switch back and forth in mid-stream, too. ASP/VBScript programmers should find these components useful, since you don't have to trap the events from the client socket to use it. Perhaps the best thing about this package is that it includes extensive documentation in HTML files, which includes an introduction, explanation about how to apply them including code samples, and a complete reference for each control. This OCX is a culmination of many years of work trying to create a suite of controls more stable and easy to use than MS's Winsock control. It's been tested out for a while by many users here. A few have recommended changes I've implemented. Otherwise, the requests I'm getting now are for minor feature changes. The package seems to be working well for those using it. I welcome your further comments and suggestions. Please vote for my hard work if you like these components. ---- Recent Updates ---- 21 June 2000: Added documentation and new features. 26 June 2000: Bug fixes and added tutorial to help. 30 October 2000: You asked for it. ZIP now includes the OCX's source. 16 November 2000: Changed Port properties from Integer to Long.
Here's a VB programmer's introduction to developing Internet (TCP/IP) applications. We'll build a trivial web browser to start with Then we'll look at some of the issues you should consider when building client/server applications. We'll even build a simple one.
The XML Engine is a set of classes designed to make it easy for your programs to parse and construct XML. The parser can be used either to automatically construct an easy-to-use data structure (like I.E.'s document object model) or direct your program (through events) to do what it needs to on the fly. This latter mode facilitates work on the data even as the XML is being incrementally received, as from a long file download. This means your program won't have to wait to start work and can avoid memory overruns associated with "passively" parsing huge XML files. This approach could even be used with an endless stream of XML, which would be great for quickly implementing a simple client/server communication protocol (search for my "Socket Controls" package here at PSC). The XmlElement class, which represents a node in an XML tree, can be used independently of the engine. Your program can easily clone an XML tree, insert new branches anywhere, remove whole branches, and export it to raw XML or plain text (stripped of XML tags). The plain-text export can be given an array telling it what to replace certain tags with, too. An element node can be either a representation of a named tag (e.g., "TABLE") with named attributes or a text block (anything that would appear in-between tags). A demo program is included with simple demonstrations of a number of basic techniques. This engine does not deal with every last idiosyncracy of XML and assumes any XML it parses is well-formed. DTD's are not supported (not that they really relevant, here). But the basics of XML are supported. It can even be used as an HTML generator and parser, provided the HTML is XML-formatted (all start tags must have end tags or be single-tag formatted like "<SOMETAG/>"). Unfortunately, there is currently no documentation, but the code is straightforward and easy to read. Further, the demos should provide enough explanation for how to use the engine. Your comments and votes are welcome.
The WebBrowser control is at the heart of the Internet Explorer web browser. You can use it to navigate to and display a web page or even pipe in raw HTML from your program. This program is a short demonstration of a number of basic capabilities: Opening a blank page (or any) Piping in raw HTML to build a page Scanning the document object model's (DOM's) elements Altering elements' properties (e.g., color) Altering elements' inner HTML (e.g., inserting text) Automatically scrolling
One of the most common types of a focus-only popup window is the menu. A drop-down list is another example. Both disappear when they lose focus. Here's a demonstration of how to do that. It doesn't rely on the LostFocus event, which only works within that form's scope. Switch to a different application and your popup would still be visible. Instead, it uses a timer and an API call to check to see if the popup still has global focus. If not, it self-unloads. While it does act essentially like menu-style popup windows, it's not exactly the same. To do that, I think it's necessary to use an API call to hook into some Windows event that detects a change in overall focus. This technique relies on constantly polling the OS. It also means the form that uses the popup will technically lose focus (big deal). It's generally a little klunky. Still, it works very well. Thanks go out to MrGTI (www.Pharfruminsain.com) for advice on the basic technique. I encourage anyone who knows the "right" way of doing this to let me know. Please vote for this code if you like it.
Here's an easy-to-use utility that can take a chunk of plain text and generate a summary with up to a number of words you specify (e.g., 1000). This code demonstrates an exceedingly cool algorithm I recently read about that basically works like this. Count all the occurrances of each word in the text. Score each sentence based mainly on how many of the most frequent words are in it (with a few other biases and ignoring dull words like "the"). Pick enough of the highest scoring sentences to meet the maximum word limit for the summary. Assemble these sentences into a summary. Unbelievably simple, in theory. Not bad in practice, despite the fact that the engine doesn't really "understand" what it's summarizing. All it's doing is picking out the most "representative" sentences. Included with this demo is an article from Seasoned Cooking magazine (seasoned.com). Try setting the maximum number of words to 100, 200, 300, and so on and see what you get. You can paste any text in you want. Be sure, though, that you help the engine out by putting one or more blank lines between any paragraphs, bullet points, etc. Also, be aware that all periods are assumed to be end-of-sentence markers, even in abbreviations like "i.e.". This and a few other limitations make this algorithm imperfect, but still very illustrative of one kind of linguistic analysis engine. I suspect this sort of code is unique on Planet Source Code, so I welcome and encourage your comments. Your vote is also appreciated. ---------------- Recent Updates: 8 November 2000: Engine improvement - Added a list of "hot words" to bias in favor of sentences with words like "key" and "important" 9 July 2000: Engine improvements - Ignores words with few characters - Ignores topmost frequent words - Ignores lower half of infrequent words - Better bias towards beginning and end paragraphs
I created this because I needed to be able to adjust how many child processes my batch processing app created so that it didn't I created this demo because I needed to be able to adjust how many child processes my batch processing app created so that it didn't overutilize the CPU. To duplicate this, create a form with one text box (Text1) and one timer (Timer1) in the configuration you see in the screen shot. Then paste the code seen here. The main key is the windows idle process (PID = 0), which eats up whatever CPU cycles are not used by other apps. Every so often, this code takes a sample of how much CPU time, in seconds, that process has taken up since it started. Then it takes the delta to calculate its own CPU utilization. Subtract it from 100% and you get the CPU utlization. In this case, we're using the Windows Management Interface (WMI) to get this information -- mainly because the API calls to get process times won't work for the idle process for security reasons. This should work for Windows 2000 and XP, but probably not for NT 4.0- or Windows 3.x, 9x, or ME. You can morph this sample a lot of ways. For example, increase the SampleRate variable to get a smoother variation curve over time or decrease to get more immediate values. You can use additional parameters in Locator.ConnectServer() to connect to a remote machine, as another example. See here for more about the WMI objects: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/wmi_reference.asp You could also easily modify this to track some other process' CPU utilization by its PID. Or you could also use it to track memory or other resource utilization. - Cheers, Jim Carnicelli
PKZIP, ARJ, ARC, JPEG, and a host of other programs and compressed file formats all use the Huffman coding algorithm (or similar redundancy-minimization methods) for compressing strings. With this small VB module, you can do your own compression in code -- compressing strings down to as small as 13%. Here's how easy it is: Compressed = HuffmanEncode(Text1) Text2 = HuffmanDecode(Compressed) This simple code can be used to compress big text fields in databases, keep your data files small, or speed up transfers of data across the Internet. It can also be used as a form of encryption. The HuffmanCoding.bas module has plenty of extra information and some in-code documentation (in case you're wondering out how it works.) Please comment on this code and vote for my hard work if you like this code. _____________________________________ Updates: 1 August 2000: Rebuilt from scratch Compression takes 28% of the time it did before Decompression takes 19% of the time it did before There's only one file, now (no extra class) Much better error checking and reporting Uses a stored checksum upon decompression to check for corruption The code is only 455 lines, including comments! Thanks to optimization, the code is even more convoluted :-)
Want anyone with a common web browser to be able to upload files to your ASP application? Here's a great little component to help you do it. This component builds on the standard mechanism web browsers provide for uploading files. Since IIS doesn't provide any simple built-in way to deal with this, this component fills the void. Here's how simple your ASP code can be: Set Upload = Server.CreateObject("Carnicelli.FileUpload") Upload.Save "C:\Temp" Response.Write "<LI>" & Upload.Form("Email") Response.Write "<LI>" & Upload.File(1).FileName I crammed a number of useful features for manipulating the resulting files, generating unique file names, and more. This code teaches many programming lessons. It demonstrates MIME processing, array and string manipulation (includes powerful array and string manipulation libraries), generating unique file names, real-time stream processing, interfacing with IIS' built-in objects (e.g., "Request" and "Session") without help from the ASP code, binary file manipulation, processing with a finite-state-machine model, MTX (Transaction Server) components, and more. Please comment on this code and vote for my hard work if you like this code. -------------------------------------------------- Now there's a commercial version of this product available. It's been rebuilt from the ground up, correcting all the issues you've reported here and including new features. And it comes complete with extensive documentation and good service. Check it out!