Aug 28 2009

Tweets made on 2009-08-28

  • I am pondering…that I know I am getting old when…CTRL + has become my favorite web browser keystroke. Try it. #

Powered by Twitter Tools.

Aug 27 2009

How do you create a cancelable event in vb.net

IN VB.NET (not c#)...

I want to create an event than can be canceled by the listener. Just like you can cancel the closing event of a winforms form in which case the form won't close.

I have already implemented a derived class from EventArgs that has a settable Cancel property as follows:

Public Class AnnounceNavigateEventArgs
    Inherits EventArgs

    Private _cancel As Boolean = False

    ''' <summary>
    ''' Initializes a new instance of the AnnounceNavigateEventArgs class.
    ''' </summary>
    Public Sub New(ByRef cancel As Boolean)
        _cancel = cancel
    End Sub
    Public Property Cancel() As Boolean
        Get
            Return _cancel
        End Get
        Set(ByVal value As Boolean)
            _cancel = value
        End Set
    End Property

End Class

Notice that I am passing the cancel argument byRef to the constructor.

The listener I have setup is setting the property to Cancel=True. I thought ByRef meant that both _cancel and cancel would point to the same location on the stack and that setting _cancel=true would therefore make the cancel = true. But this is not the behavior I am getting. _cancel becomes true in the setter but I guess the argument to the constructor remains false.

What is the proper way to do this in vb.net?

Seth

Aug 25 2009

Is there a way to supply query parameters to a SQL Server Reporting Services Report at deployment time rather than at design time

Hello,

SUMMARY: I have created a SSRS Report. I want to be able to supply parameters for the report at DEPLOYMENT time rather than just design time or runtime.

DETAILS: I want to create ONE report and deploy it multiple times with the only difference being that I want to change one of the query parameters. I do not want to prompt the user for the value.

Can this be done?

Seth

Aug 16 2009

Answer by Seth Spearman for Why can’t I see the most recently inserted record in an Access database?

In my experience you have a security permissions issue. Need to check NTFS and share permissions. Be sure the ASPNET account (or other account... depends on OS) has write permissions on the folder (and the file).

Aug 16 2009

Answer by Seth Spearman for Windows.Form c# without visual studio

I am going against the grain here... But I think that your idea is not such a bad one... especially for a small project.

But using Notepad (or at LEAST use Notepad++) will teach you more about MSBuild and the VBC or CSC compiler syntax than it will teach you about the language features. The best way to learn the language, is, as other have said, using Visual Studio. The intellisense is a great way to learn.

But it also makes us lazy and it is true that we don't have to memorize as much...and sometimes having things memorized comes in handy. (ie.... I am at a customer and logged in remotely to the servers... no visual studio is installed... BUT... yippee... .NET 2 is there... at that moment you will have appreciated the exercise...)

Honestly, to do this for a reasonably small project I think would be a good exercise in learning. I say go for it. Hell, I might even join you.

But, that said, I think the very best way to do it would be to use both methods side-by-side. For example... If you want to use multiple files the way to do that is to create a folder and put an vbproj (or csproj) file in it. MSBuild.exe receives vbproj files (and sln files for that matter) as arguments. So, one of the quickest ways to learn the vbproj file syntax is to use visual studio to create a project... and then open the vbproj file in Notepad++.

The problem is that Visual Studio IS SO AWESOME BECAUSE it abstracts so much away from the developer. But it is silly to not acknowledge there is a downside to that. That abstraction means that we don't need to have as deep an understanding. Things just work automagically. So I say dig a little deeper. I don't think you will regret it.

Aug 16 2009

Answer by Seth Spearman for Windows.Form c# without visual studio

Nona,

I am going against the grain here...but I think that your idea is not such a bad one...especially for a small project.

But using Notepad (or at LEAST use Notepad++) will teach you more about MSBuild and the VBC or CSC compiler syntax than it will teach you about the language features. The best way to learn the language, is, as other have said, using Visual Studio. The intellisense is a great way to learn.

But it also makes us lazy and it is true that we don't have to memorize as much...and sometimes having things memorized comes in handy. (ie....I am at a customer and logged in remotely to the servers...no visual studio is installed..BUT...yippee....NET 2 is there...at that moment you will have appreciated the exercise...)

Honestly, to do this for a reasonably small project I think would be a good exercise in learning. I say go for it. Hell, I might even join you.

But, that said, I think the very best way to do it would be to use both mehtods side-by-side. For example...if you want to use multiple files the way to do that is to create a folder and put an vbproj (or csproj) file in it. MSBuild.exe recieves vbproj files (and sln files for that matter) as arguments. So, one of the quickest ways to learn the vbproj file syntax is to use visual studio to create a project....and then open the vbproj file in Notepad++.

The problem is that Visual Studio IS SO AWESOME BECAUSE it abstracts so much away from the developer. But it is silly to not acknowledge there is a downside to that. That abstraction means that we don't need to have as deep an understanding. Things just work automagically. So I say dig a little deeper. I don't think you will regret it.

Seth

Aug 15 2009

How can I return only one resultset from a pivot query in sql server?

Hello,

I have the following T-SQL Pivot query.

SELECT AccountNumber, EventID, 
    	CreateDate, [ITEMBOOK] AS ITEMBOOK, 
    	[POSTER] AS POSTER
FROM
    (SELECT ProductID, Quantity, EventID,AccountNumber,CreateDate
    FROM #tmpStartupItems) ps
    PIVOT
    (
    SUM (Quantity)
    FOR ProductID IN
    ( [ITEMBOOK], [POSTER])
    ) AS pvt

When i run this it is returning both of the resultsets...is there a way to limit it to return just the pivoted result set?

Seth

Aug 15 2009

Answer by Seth Spearman for C# and Access 2000

For the record this answer is copied/edited from another question I answered.


Aristo,

You CAN use Access as your centralized data store.

It is simply NOT TRUE that access will choke in multi-user scenarios--at least up to 15-20 users.

It IS true that you need a good backup strategy with the Access data file. But last I checked you need a good backup strategy with SQL Server, too. (With the very important caveat that SQL Server can do "hot" backups but not Access.)

So...you CAN use access as your data store. Then if you can get beyond the company politics controlling your network, perhaps then you could begin moving toward upfitting your current application to use SQL Server.

I recently answered another question on how to split your database into two files. Here is the link. http://stackoverflow.com/questions/1147702/rookie-ms-access-creating-the-front-end-mde/1147858#1147858

Splitting your database file into front end : back end is sort of a key to making it more performant. (Assume, as David Fenton mentioned, that you have a reasonably good design.)

If I may mention one last thing...it is ridiculous that your company won't give you other deployment options. Surely there is someone there with some power who you can get to "imagine life without your application." I am just wondering if you have more power than you might realize.

Seth

Aug 13 2009

What is the proper way to setup events for inheritance

Hello,

Normally I setup events like this...

Public Delegate Sub MySpecialEventHandler(sender as object, e as mySpecialEventEventArgs)  '  ...I will not show the implementation of mySpecialEventArgs.
Public Event MySpecialEvent as MySpecialEventHandler  

Private Sub OnMySpecialEvent(newStatus as string)  
     Raise Event MySpecialEvent(Me,New mySpecialEventEventArgs(newStatus))  
End Sub

I have an interface...it looks like this...

Public Interface IWizardUserControl
    ReadOnly Property ShowNavigatePrevious() As Boolean
    ReadOnly Property ShowNavigateNext() As Boolean
    ReadOnly Property ShowNavigateFinish() As Boolean
    ReadOnly Property ShowNavigateCancel() As Boolean
    ReadOnly Property Description() As String
    ReadOnly Property StepCaption() As String
    ReadOnly Property PageImage() As System.Drawing.Image
    ReadOnly Property PageHelpText() As String
    Property IsValid() As Boolean
    Sub OnValidStatusChanged(ByVal validStatus As Boolean)
    Event ValidStatusChanged()
End Interface

I would like the event setup such as what you see above to be implemented in the above interface.

When you setup a delegate in the interface. No errors. But when you try to implement the delegate in the userControl Visual studio says "Delegates cannot implement interface methods" .

My goal is to have a controller class that would cast the derived class as the interface and then add a handler for the interfaces event.

Any help would be appreciated. Thanks in advance.

EDIT - I took John Saunders advice and drilled into the web.ui class. Here is what I did and it is working perfectly.

In the interface I added/changed the following...

Sub OnValidStatusChanged(ByVal validStatus As Boolean)  
Sub ValidStatusChangedHandler(ByVal sender As Object, ByVal e AsValidStatusChangedEventArgs)  
Event ValidStatusChanged As EventHandler

Most relevant point being that I ValidStatusChangedHandler is declared as a Sub not a delegate.

I implemented those in my derived class as follows...

Protected Event ValidStatusChanged As EventHandler Implements IWizardUserControl.ValidStatusChanged

Protected Sub ValidStatusChangedHandler(ByVal sender As Object, ByVal e As ValidStatusChangedEventArgs) Implements IWizardUserControl.ValidStatusChangedHandler
    OnValidStatusChanged(e.ValidStatus)
End Sub

Private Sub OnValidStatusChanged(ByVal status As Boolean) Implements IWizardUserControl.OnValidStatusChanged
    RaiseEvent ValidStatusChanged(Me, New ValidStatusChangedEventArgs(status))
End Sub

Finally in the controller class I am doing this...

Dim iwp As IWizardUserControl = DirectCast(wizardUserControl, IWizardUserControl)
AddHandler iwp.ValidStatusChanged, AddressOf iwp.ValidStatusChangedHandler

Works like a charm.

Seth

Aug 13 2009

Does anyone know of a tool that will auto-generate Unit Test stubs?

Hello,

I am writing a winforms application and eventually I would like to write unit test for this application from the DAL, and Biz Objects layers etc.

Does someone know of a FREE tool that can recieve the path to an assembly and then output unit test stubs with matching signatures for the assembly.

Any configurable options like "public interfaces only", "test framework choice", "language choice" would be a plus.

I at least would need this tool to emit vb.net against nunit.

Thanks.

Seth