IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New TypeOf/GetType/GetType
[link|http://www.codeproject.com/dotnet/CheatSheetCastingNET.asp|http://www.codeproje...eetCastingNET.asp]
--
Chris Altmann
New Here is what I did
Create a hash table:
\n    Public htFieldAddrMap As New Hashtable\n


Fill it with the control file keys and the actual
objects.

Note: I forgot to name the object with the type
prefix. I saw a chunk of code, was reminded, and
then started doing it. I didn't go back and
fix the ones I already did.

I hate the VB Editor. I've exported the form into
a flat file so I can clean it up in gvim later.

\n        htFieldAddrMap.Add("JOB", Me.job)\n        htFieldAddrMap.Add("PROJECT", Me.Project)\n        htFieldAddrMap.Add("CLEAR_LOCKS", Me.ClearLocks)\n        htFieldAddrMap.Add("PNT_WFD", Me.WFD_File)\n


This list goes on for about a 40 fields and objects.
Different types. But I only have one list type, which
I handle in hard code later.

I read the control file via:

\n   Dim arr() As String = Split(line, "=")\n   arr(0) = arr(0).Trim()\n   arr(1) = arr(1).Trim()\n\n   If htFieldAddrMap.ContainsKey(arr(0)) Then\n     Dim type = htFieldAddrMap(arr(0)).GetType().ToString\n\n     Select Case type\n       Case "System.Windows.Forms.TextBox"\n          htFieldAddrMap(arr(0)).text = arr(1)\n       Case "System.Windows.Forms.CheckBox"\n          htFieldAddrMap(arr(0)).checked = arr(1)\n       Case "System.Windows.Forms.NumericUpDown"\n          htFieldAddrMap(arr(0)).value = arr(1)\n       Case "System.Windows.Forms.ComboBox"\n          htFieldAddrMap(arr(0)).text = arr(1)\n       Case Else\n          MsgBox("Unhandled Type:" & arr(0) & "]:[" & type & "]")\n       End Select\n\n


I basically do the reverse when writing, converting booleans
to 1/0 since my later code wants it that way.

New Re: Here is what I did
Can't work it into the case statement, but you could do it this way:
\n        If htFieldAddrMap.ContainsKey(arr(0)) Then\n            If TypeOf htFieldAddrMap(arr(0)) Is TextBox Then\n                htFieldAddrMap(arr(0)).text = arr(1)\n            ElseIf TypeOf htFieldAddrMap(arr(0)) Is CheckBox Then\n                htFieldAddrMap(arr(0)).checked = arr(1)\n            ElseIf TypeOf htFieldAddrMap(arr(0)) Is NumericUpDown Then\n                htFieldAddrMap(arr(0)).value = arr(1)\n            ElseIf TypeOf htFieldAddrMap(arr(0)) Is ComboBox Then\n                htFieldAddrMap(arr(0)).text = arr(1)\n            Else\n                MsgBox("Unhandled Type:" & arr(0) & "]:[" _\n                & htFieldAddrMap(arr(0)).GetType().ToString & "]")\n            End If\n        End If\n
--
Chris Altmann
New That's not so bad
Saves stringing the types.
On the other hand, I was going to create a 2nd level table to consolidate the the duplicate behaviours.
But then again, I'm probably going to throw this away and rewrite it in C# in a couple of days anyway.
     Setting up hash table with addresses in VB.net - (broomberg) - (5)
         Never mind - (broomberg) - (4)
             TypeOf/GetType/GetType - (altmann) - (3)
                 Here is what I did - (broomberg) - (2)
                     Re: Here is what I did - (altmann) - (1)
                         That's not so bad - (broomberg)

Is that a Dune reference?
36 ms