The Classic: Cannot refer to an instance member of a class from within a shared method…

I am sure you’ve gotten this before:

Cannot refer to an instance member of a class from within a shared method

Well, instead of all the reasons why, I will just tell you one simple solution:

Pretend you’re doing this:

Public Shared Function getSomething() As Integer
   For Each tControl As Control In FlowLayoutPanel1.Controls    Next

End Function

It will ERROR.

Now Add the form name:

Public Shared Function getSomething() As Integer
   For Each tControl As Control In sampleForm.FlowLayoutPanel1.Controls   Next

End Function

And run again!

The Classic: Cannot refer to an instance member of a class from within a shared method…

Setting up port forwarding in VMWare Workstation 8

To setup port forwarding (maybe you have IIS or Apache running in a VM and want to access from other machines or the host).

If you vm is setup with NAT like this:

…You can go to “Edit > Virtual Network Editor”, this brings up this:

If you choose “NAT” network type, and click “NAT Settings”, you can configure port forwarding like this:

Enter your port, VM IP, etc. Click “OK” a bunch of times and you should be good. Don’t forget about firewalls on the host and VM.

 

Setting up port forwarding in VMWare Workstation 8

Importing IIS Logs into a SQL Database / Table

1. Download the Log Parser tool from Microsoft here. I know, it’s old but works great.

2. Dump your IIS log files somewhere (ie: c:\temp\logs).

3. Run this in cmd:

C:\Program Files (x86)\Log Parser 2.2>logparser “SELECT * INTO iisLogs FROM c:\temp\logs\*.log ” -i:iisw3c -o:SQL -server:localhost -database:webLogs -username:sa -password:yourpass -createTable: ON

if you’re on 32bit, run Log Parser will be in this folder:

C:\Program Files\Log Parser 2.2>logparser “SELECT * INTO iisLogs FROM c:\temp\logs\*.log ” -i:iisw3c -o:SQL -server:localhost -database:webLogs -username:sa -password:yourpass -createTable: ON

Now you have a table w/ tons of data!

Update:

In an updated article, I discuss increasing import performance the transactionRowCount option.

Importing IIS Logs into a SQL Database / Table

VB.net Measure string width & height – including multi-line strings

Dim fontToMeasure As New Font("Microsoft Sans Serif", 14, FontStyle.Bold)
Dim sizeOfString As New SizeF
Dim g As Graphics = Me.CreateGraphics

sizeOfString = g.MeasureString("This is line 1" & vbcrlf & "This is line 2", fontToMeasure)
Debug.WriteLine("String Height: " & sizeOfString.Height)
Debug.WriteLine("String Width: " & sizeOfString.Width)

If you want to limit the width (so it wraps), use below (300 was my width to set as max):

Dim fontToMeasure As New Font("Microsoft Sans Serif", 14, FontStyle.Bold)
Dim sizeOfString As New SizeF
Dim g As Graphics = Me.CreateGraphics

sizeOfString = g.MeasureString("This is line 1" & vbcrlf & "This is line 2", fontToMeasure, 300)
Debug.WriteLine("String Height: " & sizeOfString.Height)
Debug.WriteLine("String Width: " & sizeOfString.Width)
VB.net Measure string width & height – including multi-line strings

Creating & Playing Playlist – VB.Net Windows Media Player Control

'create playlist
 Dim newPlayList As WMPLib.IWMPPlaylist = wmpControl.playlistCollection.newPlaylist("soundsToPlay")
 newPlayList.appendItem(wmpControl.newMedia("C:\Sample1.mp3"))
 newPlayList.appendItem(wmpControl.newMedia("C:\Sample2.mp3"))
'play the list
 wmpControl.Visible = False
 wmpControl.currentPlaylist = newPlayList
 wmpControl.stretchToFit = True
 wmpControl.Ctlcontrols.play()
Creating & Playing Playlist – VB.Net Windows Media Player Control