Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Status message form in VB 2005

Status
Not open for further replies.

jbehrne

Programmer
Dec 18, 2002
484
US
Hi all,

I wrote an application in VB 2003 that interfaces with a MS SQL database. When the user performs various tasks (adding/editing/deleting records) a form (containing 1 label) is displayed that shows the status of the task. For instance, when the user opens a form that displays data in a datagrid the message form pops up with the label displays 'Connecting to database...'. Once the connection is made the form displays 'Transfering data...' after the data is transfered and the connection is dropped the form is closed. Here is some sample code:

Code:
Private Function SaveRec(ByVal strConn as string, Byval sqlString as string) As Boolean

Dim frmStatusMessage As New frmStatus 'status message form
Dim Conn As SqlConnection
Dim objInsert As SqlCommand

Try

'display message screen
frmStatusMessage.Show("Saving Record")

'connect and run the query
Conn = New SqlConnection(strConn)
Conn.Open()
objInsert = New SqlCommand(sqlString, Conn)

objInsert.ExecuteNonQuery()

Conn.Close()
objInsert.Dispose()
Conn.Dispose()

Catch ex As Exception
SaveRec = False            
MsgBox("ERROR")
Conn.Dispose()
frmStatusMessage.Close()
Exit Function

End Try

frmStatusMessage.Close()
SaveRec= True

End Function

However, since moving to VB 2005 I have tried to create a similiar message form (a form with 1 label to display the message) which I can't seem to get to work. If I use the same code listed above the status message form causes an error which is:

"Unable to cast object of type 'System.String' to type 'System.Windows.Forms.IWin32Window'."

If I set the text of the label it seems to work, however the status message form will not display any message until after the task has completed and the form only opens for a second before closing (not quick enough to read the message). Does anyone have any idea as to what I need to do in order to get the status message form to display the desired message? Is there a better way to create a message form (I cannot use a status bar on forms due to circumstances beyond my control...)?

Thanks,

jbehrne


If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations
 
Well, the reason why you're getting the error is because the Form.Show method is looking for Owner as the parameter.

As far as updating the status screen, you could put the process on a different thread so that the update to the status screen will be performed (and be visible) while the process is being done.
 
I was thinking that I may have to run the status form on a different thread - but I was going to wait to see if anyone else had conquered this problem... It's interesting to see that the functionality (as far as this status form example goes) offered in 2003 was lost in 2005.

jbehrne

If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top