They say you learn something new every day.

Asps in Nets (31/01/2012)

I’m struggling a little bit with .Net. It’s a little bit different from languages I’ve used before, and I’m worried that I’m falling back on what I know a bit – doing things in less efficient ways because that’s how I’ve always done them.

This is a bit of a problem really. What’s always inspired me to learn something new is the drive to get something to work. If I can get it to work, albeit in the “wrong” way, then I tend to stop.

Now, on the one hand, this may result in code that’s a little tatty, but on the other, the user doesn’t care. What they want is the functionality, and if it looks nice, works and is easy to use, they’re happy.

If it’s written in nice OOP code, or cobbled together from bits and bobs then they’re happy.

Now, I’m not advocating crappy code in any way. Oh God no, I’ve had enough problems with my own crappy code without writing more. But what I’ve realised is that more important than the neatness of the code is the richness of the application.

It’s much more important to get the functionality in there, make it work and tweak from there.

I realised this when putting together this function to return the group membership for a particular computer. It’s a little cobbled together, but it works. And now that I’ve got the functionality I can start tweaking it to make it work better and faster, and start identifying faults and fixing them.

I think people need to remember. We don’t code to write code. We code to solve a problem. 

FUNCTION GetMembers(Asset AS String) As String

DIM members

DIM objADAM As DirectoryEntry = New DirectoryEntry() 

objADAM.RefreshCache()

DIM objSearchADAM As DirectorySearcher = New DirectorySearcher(objADAM)

objSearchADAM.Filter = “(&(cn=” & Asset & “))”

objSearchADAM.SearchScope = SearchScope.Subtree

DIM objSearchResults As SearchResultCollection = objSearchADAM.FindAll()

If objSearchResults.Count 0 Then

Dim objResult As SearchResult

For Each objResult In objSearchResults

DIM memberof AS Object = objResult.GetDirectoryEntry.properties(“memberof”).value

IF NOT IsNothing(memberof) THEN

DIM collectiontotal= objResult.GetDirectoryEntry().Properties(“memberOf”).Count -1

Dim member,adgroup, i

For i = 0 To collectiontotal

member = objResult.GetDirectoryEntry().Properties(“memberOf”)(i).ToString(

members = members & member
Next

ELSE

members = “There are no groups on this computer.”

END IF

Next objResult

Else

members = “Computer could not be found.”

End If

GetMembers = members

END FUNCTION 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Tag Cloud

%d bloggers like this: