... all I'm offering is the truth. Nothing more. RSS 2.0
# Wednesday, January 07, 2009

I have been doing some with XSL transformations, and VBScript has been my enemy recently. What little grey matter still knows Visual Basic 6 is hit and miss for VBScript. In my case I was trying to create a case statement which in VB can be formatted as follows:

Select Case Numb
    Case 32 to 50    'This is legal in VB 6
    Case 65,66,67,67
    Case Else
End Select

Unfortunately you have to do something like this in VBScript…

Select Case Numb
    Case 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50
    Case 65,66,67,67
    Case Else
End Select

… not very elegant but I am not sure if I have any options.

Technorati tags:
Wednesday, January 07, 2009 11:14:56 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] - Trackback
Visual Basic
# Friday, October 26, 2007

I have doing a little too much work with legacy code (Visual Basic 6) recently, I was actually a better than good VB6 developer at one point but suddenly my mind cannot get around the fact that Strings in VB6 just simply do not have all the trappings (.Length, .Trim, .Remove, .Split etc) of their C# equivalents.

Anyway, I was tackling an issue that required me to remove all the unprintable characters (specifically the ASCII range 0-31) from a string in VB6 and this is what I came up with:

Dim lIndex as Integer
Dim sParseThis as String

sParse = GetDataWithWierdCharacters

For lIndex = 0 to 31
     sParse = Replace(sParse, Chr(lIndex), "")
Next

When I started thinking about this code in terms of C# my immediate desire was to make sure I am taking advantage of the glorious spackle that is the .NET Framework. Simply put I did not want to copy the above code, line for line in C#. So I thought I could take advantage of regular expressions.

string sParse;
sParse = GetDataWithWierdCharacters();
sParse = Regex.Replace(sParse, "[\x01-\x1F]", "");

Much better!

Friday, October 26, 2007 8:30:14 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] - Trackback
C# | Programming | Visual Basic
# Tuesday, February 13, 2007

Agent Smith (aka Jason S) had me looking at what it would take to consume some XML files in VB6. Thankfully I had been doing work with VB recently and so had some clue's about what to do.

It should be noted that I was loading the XML into DOM, which actually puts the whole thing into memory so while it is flexible (forward and backwards reads) it will potentially consume a lot of memory.

'If we consider this XML snippet.
<?xml version='1.0'?>
<MyInfo>
<LastName>Agent</LastName>
<FirstName>Smith</FirstName>
<Email>asmith@matrix.com </Email>
</MyInfo>

'Then we can access it like this.
Dim Xml As New MSXML2.FreeThreadedDOMDocument
Dim Root As MSXML2.IXMLDOMNode
Dim Agents As MSXML2.IXMLDOMNode
Dim Agent As MSXML2.IXMLDOMNode
Dim sLastName as String
Dim sFirstName as String
Dim sEmail as String
'Load the XML string to the DOM document
Xml.async = False
If Xml.Load(Left("C\MyFile.xml") Then
    Set Root = Xml.documentElement
    Set Agents = Root.selectSingleNode ("/MyInfo")
  sLastName = Agents.selectSingleNode("LastName").Text
  sFirstName = Agents.selectSingleNode("FirstName").Text
  sEmail = Agents.selectSingleNode("Email").Text
End If

'or if there are multiple agents as below looping could be done like this...
<?xml version='1.0'?>
<MyInfo>
<MatrixAgents>
  <Agent>
   <LastName>Smith</LastName>
   <FirstName>Agent</FirstName>
   <Email>asmith@matrix.com</Email>
  </Agent>
  <Agent>
   <LastName>OtherGuy</LastName>
   <FirstName>WithGlasses</FirstName>
   <Email>wg@matrix.com</Email>
  </Agent>
  <Agent>
   <LastName>Last</LastName>
   <FirstName>Agent</FirstName>
   <Email>la@matrix.com</Email>
  </Agent>
</MatrixAgents>
</MyInfo>

Xml.async = False
If Xml.Load(Left("C:\MyFile.xml") Then
   Set Root = Xml.documentElement
    Set Agents = Root.selectSingleNode ("/MyInfo/MatrixAgents")
    For Each Agent In Agents.childNodes
  'Get Agent Smith
  if Agent.selectSingleNode("LastName").Text = "Smith" THen
   sLastName = Agent.selectSingleNode ("LastName").Text
   sFirstName = Agent.selectSingleNode("FirstName").Text
   sEmail = Agent.selectSingleNode("Email").Text
  End if
    Next
    GoTo Done
End If

'Remember to clean up after yourself with vb6 ... Xml = Nothing ... etc

"He who praises everybody, praises nobody." - Samuel Johnson

Technorati tags: , ,
Tuesday, February 13, 2007 5:19:46 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] - Trackback
Programming | Visual Basic
Blogroll
Statistics
Total Posts: 334
This Year: 22
This Month: 0
This Week: 0
Comments: 32
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
Mark Downie
Sign In
All Content © 2010, Mark Downie
DasBlog theme 'Business' created by Christoph De Baene (delarou)