SendKeys

Team Fly 

Page 53

For i = 0 To a.Length - 1     Debug.WriteLine(i.ToString + '' . + " a(i).ToString) Next 

WARNING Neither the old Rnd function nor the new Random object uses algorithms that are sufficiently sophisticated to be of direct use in most kinds of cryptology.

SendKeys

You can still use the Shell command to run an application, such as Notepad. Shell works much as it did in VB6. An associated command, SendKeys, imitates the user typing on the keyboard. SendKeys works differently in VB.NET. This code will run an instance of Windows's Notepad, and then "type" This message into Notepad:

 Dim X As Object X = Shell("notepad.exe" , AppWinStyle.NormalFocus) System.Windows.Forms.SendKeys.Send("This Message") 

WARNING If you put this code in a Form_Load event, it will only send the T into otepad (there are timing problems involved). So, put it into a different event, such as Button1_Click, and VB.NET will have enough time to get itself together and send the full message.

Serializing

It's easy enough to store a text file. You just save it as Unicode characters, byte-pairs, or whatever. Simple, consistent variables are easily handled by the streaming techniques described earlier in this chapter.

When storing a simple integer or string variable, for example, there are only three things to worry about: the variable's name, its type, and its value. Such simple entities can just be directly streamed.

However, other kinds of data need to be stored or retrieved. More complicated constructions, such as arrays or objects, require that you also store an internal organization (the hierarchy, or other metadata). Such objects are sometimes fairly elaborate. What's more, there's no known pattern. Classes are defined by programmers. So how can VB.NET know in advance what to store or retrieve, the way it knows all about storing integers and strings?

The answer to streaming more complicated or unique data constructions is serialization. Serialization deconstructs a complicated construction into data and metadata that can be streamed. This deconstruction preserves the internal order of the construction, data types, scope, assemblies, and other details that must all enter a stream and be saved (or be retrieved). Serialization can handle objects, arrays, rectangles, and pretty much any other complex data construction. (I'm using the term construction rather than structure so you won't be puzzled by the other use of structure inVB.NET.)

VB.NET includes considerable serialization facilities. You can, for example, pick and choose which fields in a class you want serialized. To exclude a particular field from serialization, use the following syntax:

 <NonSerialized()> Public Secrets As String 
Team Fly 


Visual Basic  .NET Power Tools
Visual Basic .NET Power Tools
ISBN: 0782142427
EAN: 2147483647
Year: 2003
Pages: 178

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net