Categories
Geeky/Programming

VBA – Reading a Base64 Element into XML and using as Byte Array

Ok, more VBA

Getting a response back as Base64, but when trying to convert it from XML to binary data just having issues.. coming back as ASCII which converts wacked.

What you need to do:

Dim MyInfo As MSXML2.IXMLDOMNodeList
Set MyInfo = xmlDoc.getElementsByTagName(“MyBase64Element”)
MyInfo .Item(0).DataType = “bin.base64”

Dim image() As Byte
image = MyInfo .Item(0).nodeTypedValue

then you can use it in a byte array and convert to an image or whatever datatype you need.

The key here is overriding the type (probably Variant/String by default) to “bin.base64” and then making sure to use the “nodeTypedValue”

This one threw me for a loop for a little while 🙂

Technorati tags: , , , , , , ,
Categories
Geeky/Programming Life Product Reviews

MacBook Battery X Problem

The other day I turned on my MacBook (thanks Reena! – still waiting for the “real” power charger…) and noticed the battery had a black X in it. I had it plugged in, it wasn’t charging. I unplugged it, and the MacBook shut down. Dang.

I unseated the battery, put it back in, and plugged it in, tried again. Same thing.

I did some digging on Apple’s site..

I tried Resetting MacBook and MacBook Pro System Management Controller (SMC) .   That didn’t work. They talk about battery update 1.2 (which I already had) was supposed to fix this problem, so that wouldn’t be the issue.

I then found another link, http://www.apple.com/support/macbook_macbookpro/batteryupdate/

Looks like the jackpot. Free battery replacement outside of warranty for this issue. Looks like I am heading to the Apple store in the West Towne Mall, to see if they actually go for it. I am going to print off the page and see.

Update: I went to the apple store, and signed up for the genius bar. They had a wait, the guy was like ” why don’t you sit through the iPhone getting started training. Ok I said, what a joke..  But as far as the battery, I got a new one for free. She was like “let it drain once a month” – which is what caused the problem in the first place, ugh

Technorati tags: , , , , , , , ,
Categories
Geeky/Programming SQLServerPedia Syndication

SQL Server 2005 Books Online Scoped Search

Stumbled upon this today

http://search.live.com/macros/sql_server_user_education/booksonline/

Pretty sweet, using search macros, you can search books online..well, ONLINE 🙂

Here is a search for DATEDIFF

http://search.live.com/results.aspx?q=DATEDIFF&go=Search&form=QBJK&q1=macro%3Asql_server_user_education.booksonline

Handy little macro if you don’t have SQL BOL installed. You can always search Google or MSDN to find the info, but this seems “scoped” for just what you need for books online, pretty cool if you ask me..

Technorati tags: , , , ,
Categories
Geeky/Programming

PHP, IIS7, Vista, VS2005

Tonight, just for the heck of it, I decided to get PHP running on my machine. I am running Vista (not SP1 beta). I already have IIS installed, so that pre-req was taken care of.

First thing, I made sure I had everything turned on..

Start->Run->Programs and Features->Turn Windows Features on or off…

image

I made sure CGI and ISAPI was checked. I then downloaded and installed PHP (http://www.php.net/get/php-5.2.5-win32-installer.msi/from/a/mirror)

When I went through the install, I changed the path from Program Files to Windows (read online that it would be better – rights – if in Program Files it doesn’t have the same rights as in Windows)

Then, I opened IIS7, and  went to “Handler Mappings” and clicked “Add Script Map”

image

It will prompt you when you hit ok to add to CGI stuff, hit Yes.

Then you can make a test PHP page in your wwwroot, put <?php  phpInfo();  ?> in there and it should work!

Now, as an added bonus, I wanted to use VS2005 IDE to develop PHP scripts, and found VS.PHP (http://www.jcxsoftware.com/vs.php) which lets you make PHP projects in VS2005. There is a 30 day trial, but then it is 99 dollars. I installed it and tried it , pretty awesome.

I don’t know how much PHP programming I will do, but every now and then it is nice to dabble into other technologies and code up something, or just keep up on the latest trends.

Technorati tags: , , , , , , , , , ,
Categories
Geeky/Programming

MSXML2.IXMLDOMNodeList – Loading XML from files or strings

Again with the VBA, working with MSXML2.IXMLDOMNodeList objects. How do you load XML? Well MSDN shows you how to do it from an XML file..

Loading from an XML File:

Dim MyIXMLDOMNodeListVar As MSXML2.IXMLDOMNodeList
Dim xmlDoc As New MSXML2.DOMDocument30

xmlDoc.Load “c:myxml.xml”

If (xmlDoc.parseError.ErrorCode <> 0) Then
   Dim myErr
   Set myErr = xmlDoc.parseError
   MsgBox (“You have error ” & myErr.reason)
Else
   Set MyIXMLDOMNodeListVar = xmlDoc.getElementsByTagName(“MyElement”)
End If

Loading from XML string:

Dim MyIXMLDOMNodeListVar As MSXML2.IXMLDOMNodeList
Dim xmlDoc As New MSXML2.DOMDocument30
Dim myXml As String

myXml = “<MyElement>Steve Rules!</MyElement>”
xmlDoc.loadXML (myXml)

If (xmlDoc.parseError.ErrorCode <> 0) Then
   Dim myErr
   Set myErr = xmlDoc.parseError
   MsgBox (“You have error ” & myErr.reason)
Else
   Set MyIXMLDOMNodeListVar = xmlDoc.getElementsByTagName(“MyElement”)
End If

You will notice there isn’t much difference, except when you want to load from a string, you use xmlDoc.loadXml instead of just xmlDoc.Load .. I wish I could have found that in the documentation somewhere (maybe it’s there and I just didn’t look hard enough) 🙂

Technorati tags: , , , , ,
Categories
Geeky/Programming

VBA vs VB.NET – turn bytes into bitmaps

So, recently working on some things, I have noticed the HUGE difference between VBA and VB.NET, specifically with turning bytes into bitmaps.. (assume GiveMeBytes() returns a byte array that is a bitmap)

VB.NET:

Dim image As Byte() = GiveMeBytes()
Dim memStream As MemoryStream = New MemoryStream(image)
Dim bitImage As Bitmap = New Bitmap(System.Drawing.Image.FromStream(memStream))

bitImage.Save(“C:test.bmp”)

 

VBA:

Dim image() As Byte
image = GiveMeBytes()

Dim bitImage

bitImage = FreeFile
Open “c:test.bmp” For Binary Access Write As bitImage
Put #bitImage, , image()
Close #bitImage

Now, maybe there is an easier way in VBA/VB6 to do it, but this is the way I learned way back in the day. I am sure you can do something with the FileSystemObject (I am guessing)..

You notice that the VB.NET snippet mostly deals with converting bytes to MemoryStream to Bitmap, and the saving is 1 line, whereas the VBA is really nothing with converting but mostly deals with saving the file. Can we get the best of both worlds? I am not sure, but I still like the .NET implementation better, it just seems “cleaner” to me, and the VBA just seems “dirty”, but they both do the same thing.. (notice in the VBA I didn’t strongly type the bitImage Dim)

In conclusion…”viva .NET!” 🙂

Technorati tags: , , , , , , , , ,
Categories
Geeky/Programming Life

Relationships and Geeks

Saw a post this morning on Geeks are Sexy, about “Why Geeks Shouldn’t Change For Anybody”, which has a clip from Diggnation (which, I would love to do a show like this, just need someone to do it with).. anyways..

Watch the video:

 

They are spot on. This is exactly right, and it is funny, because it does happen. I am going to be playing video games when you leave, and yes, when you come back I will be playing the same video game. Why? Because that is what we do. We are normal. Geeks are going to take over the world, they already are, so people should get used to it. 🙂

 

Via GaS

Technorati tags: , , , ,
Categories
Business Intelligence Geeky/Programming SQLServerPedia Syndication

SQL 2005: OpenRowset, Dynamic MDX and Variable Scope

So, the other day I had to create something in T-SQL that called a MDX query using OpenRowset – this is pretty easy to do, you can query around the openrowset and get the values back you need in a T-SQL Query. This was fine when the MDX query was a static string.

The format of the query would be like this:

SELECT * FROM OpenRowset(‘MSOLAP’, ‘DATA SOURCE=MySSASServer; Initial Catalog=MySSASDB;’,’MyMDXQuery HERE’) as a

Now, the * will give you the columns from your MDX query, in the example above MyMDXQuery would be replaced with your actual MDX query.

The problem comes in, if you want your MDX query (which is a string), to contain some variable, so that you can pass something into the OpenRowset (say a date, or some other variable)…

The problem is, you need to execute the whole query (not just the OpenRowset) as a string, and the scope of variables is lost. You cannot declare a variable outside the TSQL string you want to EXEC, then set it inside the TSQL statement, then use it after. This makes it tough to get data out of the OpenRowset execution. Now if you just are executing the TSQL and getting a result set back for a report or something, it will work without doing what I am doing here, but if you need a scalar value back or something to use in a query later in your proc, then you need to do this. I tried different solutions and this was the only one I could get to work. Like I said, declaring a var before and trying to use in the TSQL exec wont work. Also, a RETURN wont work, it will give you an error saying it doesn’t work in the scope or something similar, here is an example of what does work – using a temp table.

 

DECLARE @TSQL varchar(max)

CREATE TABLE #results
(
  mytempresult DECIMAL(10, 3)
)

SET @TSQL = ‘
DECLARE @myVar AS DECIMAL(10,3)

SELECT @myVar =
SELECT [Measures].[MyMeasure] FROM
OpenRowset(
”MSOLAP”,
”DATA SOURCE=MySSASServer; Initial Catalog=MySSASDB;”,
”WITH
   MEMBER Measures.[MyMeasure]
  AS (‘ + @SomeDynamicString + ‘)
SELECT
{[Measures].[MyMeasure]} ON COLUMNS
FROM [MyCube]
”)
as a

INSERT INTO #results VALUES (@myVar)

EXEC ( @TSQL )

DECLARE @myVarForReal AS DECIMAL(10, 3)
SELECT  @myVarForReal = mytempresult
FROM    #results

DROP TABLE #results

as you can see, I CREATE the temp table outside the TSQL var, then I actually declare a var inside the TSQL statement, set it in my OpenRowset call, which I pass in some other var (@SomeDynamicString) and then insert that value into my temp table.

I then EXEC that TSQL statement, and then grab my variable for real from the temp table, and drop the temp table. You would think that I could just reference @myVar after the EXEC, but it doesn’t exist, and if I declare it outside the TSQL var, it will be empty after, and it won’t get set when I EXEC the TSQL.

Just a “gotcha” if you ever run into executing dynamic MDX from TSQL and you need to get a scalar value back from the MDX.. whew 🙂

Technorati tags: , , , , ,
Categories
Geeky/Programming Product Reviews Random

Total Geekdom: Ordering Pizza Via Text Message

So I read last week you could order pizza via text message now, from Papa Johns. Was feeling like some pizza last night, so I decided to try it out. I already had an online account at Papa Johns, to order delivery, so I went there and checked it out. I set up 4 favorite orders, and then texted FAV to 47272. You have to have your mobile set up in your online account so it knows it is you first.

Once I texted FAV, it texted me back with my 4 options I set up, and I texted back FAV1 to order my first favorite. It wanted me to confirm, so I texted Y1 to confirm. Since I already had it set up online to deliver to my apt, and the tip amount set, and to use my check card as payment, I didn’t have to do anything. 35 minutes later, the pizza shows up, I sign the receipt, and all is good.

I think the next logical step is for me to just “think” about pizza and they just bring it to me automatically.

 

Technorati tags: , , , , ,
Categories
Geeky/Programming

Windows Vista and netsh – How to connect to adhoc networks if you IT dept locks you down…

Ok, so for some reason you can’t play with adhoc networks, maybe your IT dept locked you down, maybe something else happened, some security software or something jacked your settings. Well, you can use netsh to allow adhoc access again. Maybe you don’t even want to connect to ad-hoc, but you want to run one, same difference.. anyways, just run this cmd:

netsh wlan delete filter permission=denyall networktype=”adhoc”

and you should be good to go!

Technorati tags: , , , ,