<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog of Travis Hydzik &#187; function</title>
	<atom:link href="http://thydzik.com/tag/function/feed/" rel="self" type="application/rss+xml" />
	<link>http://thydzik.com</link>
	<description>random snippets and information</description>
	<lastBuildDate>Mon, 30 Apr 2012 15:46:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>VB6/VBA functions to convert binary string to Base64 string</title>
		<link>http://thydzik.com/vb6vba-functions-to-convert-binary-string-to-base64-string/</link>
		<comments>http://thydzik.com/vb6vba-functions-to-convert-binary-string-to-base64-string/#comments</comments>
		<pubDate>Tue, 16 Aug 2011 05:46:19 +0000</pubDate>
		<dc:creator>thydzik</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[Base64]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[byte array]]></category>
		<category><![CDATA[function]]></category>

		<guid isPermaLink="false">http://thydzik.com/?p=637</guid>
		<description><![CDATA[Here are some functions to convert a binary string, to a byte array, to a Base64 string and then back to a byte array and binary string. Run tester to see it in action, enjoy. Thanks to Tim Hastings for the Base64 functions.<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://thydzik.com/vb6vba-functions-to-convert-binary-string-to-base64-string/' addthis:title='VB6/VBA functions to convert binary string to Base64 string ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Here are some functions to convert a binary string, to a byte array, to a <a href="http://en.wikipedia.org/wiki/Base64" title="Wikipedia Base64" target="_blank">Base64</a> string and then back to a byte array and binary string. Run <em>tester</em> to see it in action, enjoy.</p>
<pre class="brush: vb; title: ; notranslate">
Private Function encodeBase64(ByRef arrData() As Byte) As String
    Dim objXML As MSXML2.DOMDocument
    Dim objNode As MSXML2.IXMLDOMElement

    Set objXML = New MSXML2.DOMDocument

    Set objNode = objXML.createElement(&amp;quot;b64&amp;quot;)
    objNode.DataType = &amp;quot;bin.base64&amp;quot;
    objNode.nodeTypedValue = arrData
    encodeBase64 = objNode.Text

    Set objNode = Nothing
    Set objXML = Nothing
End Function

Private Function decodeBase64(ByVal strData As String) As Byte()
    Dim objXML As MSXML2.DOMDocument
    Dim objNode As MSXML2.IXMLDOMElement

    Set objXML = New MSXML2.DOMDocument
    Set objNode = objXML.createElement(&amp;quot;b64&amp;quot;)
    objNode.DataType = &amp;quot;bin.base64&amp;quot;
    objNode.Text = strData
    decodeBase64 = objNode.nodeTypedValue

    Set objNode = Nothing
    Set objXML = Nothing
End Function

Function bin2Byte(ByVal s As String) As Byte()
    Dim bitsIn As Long
    bitsIn = 8

    Dim i As Long
    'pad with zeros
    If Len(s) Mod bitsIn &amp;lt;&amp;gt; 0 Then
        For i = 1 To bitsIn - Len(s) Mod bitsIn
            s = &amp;quot;0&amp;quot; &amp;amp; s
        Next i
    End If

    i = Len(s)
    Dim bytes() As Byte
    Dim byteCount As Long
    byteCount = -1
    Dim sByte As String
    Do While LenB(s) &amp;gt; 0
        byteCount = byteCount + 1
        ReDim Preserve bytes(byteCount)

        sByte = Mid$(s, Len(s) - bitsIn + 1)
        'sByte = Mid$(s, 1, bitsIn)
        For i = 0 To 7 Step 1
            bytes(byteCount) = bytes(byteCount) + CLng(Mid$(sByte, 8 - i, 1)) * 2 ^ i
        Next i
        s = Mid$(s, 1, Len(s) - bitsIn)
        's = Mid$(s, bitsIn + 1)
    Loop
    bin2Byte = bytes
End Function

Function byte2Bin(ByRef bytes() As Byte) As String
    Dim i As Long, j As Long
    Dim bin As String
    For i = 0 To UBound(bytes)
        bin = Space$(8)

        For j = 0 To 7
            If bytes(i) And 2 ^ j Then
                Mid(bin, 8 - j, 1) = &amp;quot;1&amp;quot;
            Else
                'Mid(bin, 8 - j, 1) = &amp;quot;0&amp;quot;
            End If
        Next j

        byte2Bin = bin &amp;amp; byte2Bin
    Next i
    byte2Bin = LTrim$(byte2Bin)
    byte2Bin = Replace(byte2Bin, &amp;quot; &amp;quot;, &amp;quot;0&amp;quot;, 1, -1, vbBinaryCompare)
End Function

Sub tester()
    'note we can't add any 0 padding to the test binary string
    Dim bin As String
    bin = &amp;quot;111101000001100010101&amp;quot;
    Dim binOut As String
    binOut = byte2Bin(decodeBase64(encodeBase64(bin2Byte(bin))))

    MsgBox binOut = bin
End Sub
</pre>
<p>Thanks to <a href="http://www.nonhostile.com/howto-encode-decode-base64-vb6.asp" title="Free, Easy and Quick Base64 Encoding and Decoding in Visual Basic">Tim Hastings</a> for the Base64 functions.</p>
<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://thydzik.com/vb6vba-functions-to-convert-binary-string-to-base64-string/' addthis:title='VB6/VBA functions to convert binary string to Base64 string ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://thydzik.com/vb6vba-functions-to-convert-binary-string-to-base64-string/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simple Ping function VBScript</title>
		<link>http://thydzik.com/simple-ping-function-vbscript/</link>
		<comments>http://thydzik.com/simple-ping-function-vbscript/#comments</comments>
		<pubDate>Sun, 14 Nov 2010 17:04:06 +0000</pubDate>
		<dc:creator>thydzik</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[cmd]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[ping]]></category>
		<category><![CDATA[timeout]]></category>

		<guid isPermaLink="false">http://thydzik.com/?p=567</guid>
		<description><![CDATA[I was after a ping function that met the following constraints; Didn&#8217;t use GetObject. Didn&#8217;t display any command (cmd) prompt. Didn&#8217;t use a temporary files. Here is what I found; I was looking at a way to timeout the ping function after 1 second using Threading but this didn&#8217;t quite make it so simple. Whilst [...]<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://thydzik.com/simple-ping-function-vbscript/' addthis:title='Simple Ping function VBScript ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>I was after a ping function that met the following constraints;</p>
<ul>
<li>Didn&#8217;t use GetObject.</li>
<li>Didn&#8217;t display any command (cmd) prompt.</li>
<li>Didn&#8217;t use a temporary files.</li>
</ul>
<p>Here is what I found;</p>
<p>
<pre class="brush: vb; title: ; notranslate">&lt;br /&gt;
Function ping(node)&lt;br /&gt;
    Set WshShell = CreateObject(&amp;quot;WScript.Shell&amp;quot;)&lt;br /&gt;
    ping = Not CBool(WshShell.Run(&amp;quot;ping -n 1 &amp;quot; &amp;amp; node, 0, True))&lt;br /&gt;
End Function&lt;br /&gt;
</pre>
</p>
<p>I was looking at a way to timeout the ping function after 1 second using Threading but this didn&#8217;t quite make it so simple. Whilst ping offers a timeout value if you ping an incorrect hostname it will hang for a little while.</p>
<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://thydzik.com/simple-ping-function-vbscript/' addthis:title='Simple Ping function VBScript ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://thydzik.com/simple-ping-function-vbscript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>In Excel, find the value on the last row as a function, not VBA</title>
		<link>http://thydzik.com/in-excel-find-the-value-on-the-last-row-as-a-function-not-vba/</link>
		<comments>http://thydzik.com/in-excel-find-the-value-on-the-last-row-as-a-function-not-vba/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 23:58:53 +0000</pubDate>
		<dc:creator>thydzik</dc:creator>
				<category><![CDATA[Random]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[last row]]></category>
		<category><![CDATA[not VBA]]></category>

		<guid isPermaLink="false">http://thydzik.com/?p=256</guid>
		<description><![CDATA[Here is a quick post, how to find the value of the last cell in a column. Exaample below uses Column A with the first 3 rows used for the header: =INDEX(A:A,COUNT(A:A)+3)<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://thydzik.com/in-excel-find-the-value-on-the-last-row-as-a-function-not-vba/' addthis:title='In Excel, find the value on the last row as a function, not VBA ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Here is a quick post, how to find the value of the last cell in a column.</p>
<p>Exaample below uses Column A with the first 3 rows used for the header:</p>
<pre>=INDEX(A:A,COUNT(A:A)+3)</pre>
<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://thydzik.com/in-excel-find-the-value-on-the-last-row-as-a-function-not-vba/' addthis:title='In Excel, find the value on the last row as a function, not VBA ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://thydzik.com/in-excel-find-the-value-on-the-last-row-as-a-function-not-vba/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Object Caching 634/642 objects using disk: basic
Content Delivery Network via t01.thydzik.com

Served from: thydzik.com @ 2012-05-23 07:57:30 -->
