November 2003 - Posts
...well, they haven't exactly been good. Well, lemme start at the start.
I have an MSDN subscription and I thought I'd install Windows XP Media Center Edition on a PC I'm not using and hook it up to my TV/cable to get the full experience. I realize that most people would buy a Media Center PC with all the trimmings, so I thought I'd be different and install it on a box from scratch. Here's what you need above and beyond “normal” hardware:
So, I made the discs from images on the MSDN download site and began my install. Apparently there was a problem reading the disc. This took me two installs to figure out. The biggest problem was that the installer didn't do a good job of telling me it couldn't read the disc. It gave me a prompt to put in the Windows XP SP1 disc (which is not required) when it was really asking for the disc that was already in the drive. Aaarrrrrgh!
Finally installed, I go to run the Media Center application (a shell for all the related software) and I get an unhandled exception in EHShell.exe (the main program). Thinking that it might be a .NET Framework compatibility issue (because the error comes from “Common Language Runtime Debugging Services”) I re-installed both versions of the .NET Framework. No help.
This is where I am now. I pulled an all-nighter over this and it doesn't work. Now I'm off to scour the forums and such to figure this mess out. I'll keep you posted.
Patrick Hynds is a Microsoft Regional Director, MCSD, MCSE+I, MCDBA, MCP+Site Builder and MCT, and the Chief Technology Officer for CriticalSites. Named by Microsoft as the Regional Director for Boston, he has been recognized as a leader in the technology field. He is one of the few certified trainers in New England for Site Server. An expert on Microsoft technology and experienced with other technologies as well (Websphere, Sybase, Perl, Java, Unix, Netware, C++, etc.), Patrick previously taught freelance software development and Network Architecture. He has been a successful contractor who enjoyed mastering difficult troubleshooting assignments. A graduate of West Point and a Gulf War veteran, Patrick brings an uncommon level of dedication to his leadership role at CriticalSites. He has experience in addressing business challenges with blended IT solutions involving leading-edge database, web and hardware systems. In spite of the demands of his management role at CriticalSites, Patrick stays technical and in the trenches acting as Project Manager and/or developer/engineer on selected projects throughout the year.
Carl talks with pat about Security, from the general concepts to the practical tips and in between. Pat draws on his millitary background to render a keen understanding of how to secure today's complex systems. You will pick up some great tips, and hopefully start thinking of security issues in your everyday development efforts after listening to this show. Pat Rocks!
71 Minutes
http://www.franklins.net/dotnetrocks.asp
Hope you have a great Thanksgiving Holiday!
Carl
I wanted to share this code with my readers. I recently answered a post on vbcity.net where Cindi asked:
I have a class called HardDate that will include 70 different functions.
Each function is a symbol that will match the data that I will be iterating through..
For example.. SP, HO & HU are the symbols.
So I will be able to call the following 3 functions
Code:
Dim Value1, Value2, Value3 as int16
Dim HD as HardDate
Value1=HD.SP
Value2=HD.HO
Value3=HD.HU
Is there a way for me to pass a variable as the function name?
Code:
Dim Value1 as int16
Dim HD as HardDate
Dim iSym as string = “SP”
Value1=HD.iSym 'which will simply call HD.SP
Or am I going to have to find another way around this that will need to list out all 70 functions as in a "Select Case" or "ElseIF"?
Can I create an object array that holds all 70 functions can call it by its index number??
I don't know what my options are.. but there must be a better way of doing it then listing out all 70 functions..
My Response:
You need a delegate. Think of a Delegate as an object that represents a method call and can be passed around like any other variable.
Create a form and put two buttons on it. Here is some sample code:
Public Class Form1
Inherits System.Windows.Forms.Form
'#Region " Windows Form Designer generated code " REMOVED
'-- This is really a data type that represents a function call having a single string argument.
' Create others for subs that have different argument lists (or signatures)
Private Delegate Sub dlgSingleString(ByVal Arg As String)
'-- Create a new object that has the methods you want to call
Dim tc As New TestClass
'-- These variables represent the function calls
Dim dlg1 As dlgSingleString
Dim dlg2 As dlgSingleString
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'-- The dlgSingleString objects are created with the address of a method (could be local, global, or in any object)
dlg1 = New dlgSingleString(AddressOf tc.Sub1)
dlg2 = New dlgSingleString(AddressOf tc.Sub2)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'-- Call the first sub
dlg1.Invoke("Hello Sub 1")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'-- Call the second sub
dlg2.Invoke("Hello Sub 2")
End Sub
End Class
Public Class TestClass
'-- Simple class with two subs
Public Sub Sub1(ByVal Arg As String)
MsgBox("Sub1: " & Arg)
End Sub
Public Sub Sub2(ByVal Arg As String)
MsgBox("Sub2: " & Arg)
End Sub
End Class
I authored this video in the early summer of 2003 and had planned on doing more videos and charging for access. Well, we never got around to that, so I thought I'd share this (maybe the first of many?) high-quality how-to video.
This is a step-by-step how-to video that shows you how to create an asynchronous sockets terminal client program in VB.NET 2003
This technique is the best-practice for doing sockets on the client, and eclipses the other code I have on my website.
Enjoy, and don't forget to tell your friends about .NET Rocks! I have a big mortgage payment! :-)
http://www.franklins.net/video/sockets/
We took advantage of a hardware failure yesterday to upgrade franklins.net to Windows Server 2003! I can't believe how smooth the migration went.
Moving the SQL 2000 Server was a piece of cake. I just attached to the old data files and everything worked! I had never done that before. Nice work, MS.
Of course, rebuilding the websites was a pain, but it won't be next time because of IIS 6. It stores all the web server configuration data in an XML file. Good riddance to a really time consuming and frustrating manual process!
It was (for once) an enjoyable experience upgrading to a new version of Windows Server.
When using the alpha of VB.NET Whidbey I noticed that the dropdown list of overrides was missing. No reason for alarm. Here's Paul Vick's response to my query:
“They did get removed from the dropdown list, but they’re supposed to go somewhere else and they aren’t there in the alpha, I forget where. I’m pretty sure there’s a thread somewhere on the alpha newsgroups about this, just search for Jay Schmelzer’s name, he’s the PM that owns this area!”
*whew* Thanks, Paul!
So, I'm going through all of the new features of VB.NET Whdibey and posting my findings and samples. The next topic I tackled was operators. The first time I saw this I got it, so it was easy to implement. I never knew how much I needed this feature! Consider the following class:
Public
Class OrderItem
Private _productid As String
Private _quantity As Int32
Private _unitprice As Decimal
Public Property ProductID() As String
Get
Return _productid
End Get
Set(ByVal Value As String)
_productid = Value
End Set
End Property
Public Property Quantity() As Int32
Get
Return _quantity
End Get
Set(ByVal Value As Int32)
_quantity = Value
End Set
End Property
Public Property UnitPrice() As Decimal
Get
Return _unitprice
End Get
Set(ByVal Value As Decimal)
_unitprice = Value
End Set
End Property
Public ReadOnly Property Total() As Decimal
Get
Return UnitPrice * Quantity
End Get
End Property
Public Shared Operator +(ByVal Item1 As OrderItem, ByVal Item2 As OrderItem) As OrderItem
If Item1.ProductID <> Item2.ProductID Then
Throw New Exception("You can only add OrderItems where the ProductID is the same for both objects")
ElseIf Item1.UnitPrice <> Item2.UnitPrice Then
Throw New Exception("You can only add OrderItems where the UnitPrice is the same for both objects")
Else
Dim item As New OrderItem
With item
.ProductID = Item1.ProductID
.Quantity = Item1.Quantity + Item2.Quantity
.UnitPrice = Item1.UnitPrice
End With
Return item
End If
End Operator
End
Class
It's all pretty straight-ahead until you get to the Operator. Public Shared Operator + is the meat of it. That's saying “I want this code to execute when someone adds two of my objects together with the + operator. The arguments represent the addends (is that the right word?) and the result is what's returned on the left of the equal sign.
My operator basically insures that the productid and unit price are the same for both objects, and then simply adds the quantities together.
Here is some code in a button to test it.
Dim Item1 As New OrderItem
Dim Item2 As New OrderItem
Dim Item3 As OrderItem
With Item1
.ProductID = "1"
.Quantity = 5
.UnitPrice = 10
End With
With Item2
.ProductID = "1"
.Quantity = 4
.UnitPrice = 10
End With
Item3 = Item1 + Item2
'-- This shows 90!
MsgBox(Item3.Total)
So, I fired up Whidbey to write some code that uses a generic collection. Everything I could find on the web was just something like this
Dim col As New List(Of String)
col.Add(”Hi”)
Msgbox(col(0).ToLower)
This code doesn't say what List is, so I went to Amanda's PPT file from the PDC (choose TLS300) and the slide indicates that List is a custom class that looks like a collection.... kind of.
That stumped me. I knew I didn't have to write my own generic ArrayList class with (Of T), and after a bit of searching I found the Generic namespace. It has generic versions of the Comparer, Dictionary, KeyValuePair, List, Queue, SortedDictionary, and Stack classes. (Note, these may change in the future, so just take this post as an educational rant)
So, here's some code that I wrote to create a generic list of a class called Message, which contains a name, email address, and the message text. I was able to bind this list to the Listbox with no problem, and it was a piece of cake to work with.
Here's the Message class complete with XML Comments (the characters of which also may change according to Paul Vick):
Public
Class Message
Private _sendername, _senderemail, _text As String
Public Property SenderName() As String
Get
Return _sendername
End Get
Set(ByVal Value As String)
_sendername = Value
End Set
End Property
Public Property SenderEmail() As String
Get
Return _senderemail
End Get
Set(ByVal Value As String)
_senderemail = Value
End Set
End Property
Public Property Text() As String
Get
Return _text
End Get
Set(ByVal Value As String)
_text = Value
End Set
End Property
End Class
And here is the Windows Form code. There is only a single Listbox on the form.
This line goes at the class level:
Private
col As New Generic.List(Of Message)
And this code goes in Form_Load:
'-- Add a new message
col.Add(New Message)
col(0).SenderName = "Carl Franklin"
col(0).SenderEmail = "carl@franklins.net"
col(0).Text = "This is message one"
'-- Add another new message
col.Add(New Message)
col(1).SenderName = "Jay Franklin"
col(1).SenderEmail = "jay@franklins.net"
col(1).Text = "This is message two"
'-- Bind Listbox
With Listbox1
.DisplayMember = "SenderName"
.ValueMember = "SenderEmail"
.DataSource = col
End With
The names Carl Franklin and Jay Franklin show up in the list. When you double-click them, this code executes:
Private
Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
Dim msg As Message = CType(ListBox1.SelectedItem, Message)
MsgBox("Message from " & msg.SenderEmail & vbCrLf & "Text: " & msg.Text)
End Sub
So you can see how this is cool, right? First of all, you get the late-binding feature you always wanted out of the ArrayList (or List) and secondly, the compiler generates more efficient and type-safe code. It's a win-win.
http://www.franklins.net/dotnetrocks.asp#thisweek
36 Pictures from the show: http://www.franklins.net/pdcpics.asp
Bandwidth update: We will have 2 MB for the next two weeks, I'm told. Upstream ISP is upgrading, so we have to wait some more.
More Posts
Next page »