Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 7th, 2007, 11:35 AM
Authorized User
 
Join Date: Dec 2006
Posts: 70
Thanks: 0
Thanked 1 Time in 1 Post
Default Need to be able to re-initialize a form

I need to be able to re-initialize a form without exiting and restarting the form.
What's the best way to accomplish this? I haven't found anything that really addresses this. Or did I miss something?

Thanks,
Karen

 
Old May 7th, 2007, 11:41 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

...explain what you are trying to do? Why do you need to re-initialize the form? Is what you need to do something that could be achieved by using Static members?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old May 7th, 2007, 12:08 PM
Authorized User
 
Join Date: Dec 2006
Posts: 70
Thanks: 0
Thanked 1 Time in 1 Post
Default

Sorry about that ...
I created a form to use to scan our incoming equipment.
I would like to be able to have a button that would, in effect, close and re-load the form to re-initialize all the values, but without the user seeing the close and re-load.

More detail:
I have four combo lookup boxes that get filled based on previous values selected.
There are also two other combo lookup boxes that keep the same values the whole time.
The data grid view gets populated with those values (but the columns are hidden) plus the serial number from the phone.
The user needs to be able to change the values in the lookup boxes, and keep scanning, without losing much time. (The user is generally scanning 7-10 thousand phones at a time.)
A quick save, re-select values, and continue.

I hope that helps you help me.
Karen

 
Old May 8th, 2007, 09:41 AM
Authorized User
 
Join Date: Dec 2006
Posts: 70
Thanks: 0
Thanked 1 Time in 1 Post
Default

I think I've figured out how to do what I want.

I created a Reset button on my form.

The Click event is supposed to cause the data in the data grid to be saved.

Then I want it to go to the Load function for the form.

I added the Click event for the button to the Handles clause on the Load event for the form.

When I tested, the Click event on the Reset button was handled first, But the Load event was not handled.
Is there a way to make this happen? What am I missing?

 
Old May 8th, 2007, 10:02 AM
Authorized User
 
Join Date: Nov 2006
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ef1196
Default

You might be making this more difficult than it needs to be. Try this approach:

1.) Take the code that is currently in your form_load event and create a procedure from it. Remove everything from your form_load event except a call to your new procedure.

2.) Take the code that is currently handling the data/save tasks in your button_click event and create a procedure from it. Remove everything from the button_click event except a call to your new data/save procedure and your procedure from #1 above.

As a general rule I implement procedures/functions from event code (form_load, button_click, etc.) rather than writing code directly into those events. That way if I need to reuse a portion of code all I have to do is call that procedure again.

Clear as mud? Here is an example:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call Me.subLoadData() '* This procedure clears and resets data.
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call Me.subSaveData() '* I'm saving the data here.
        Call Me.subLoadData() '* I'm resetting the form here.
    End Sub





Best Regards,
Earl Francis
 
Old May 8th, 2007, 11:44 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Nice, Earl—nice and compact.
 
Old May 9th, 2007, 07:55 AM
Authorized User
 
Join Date: Dec 2006
Posts: 70
Thanks: 0
Thanked 1 Time in 1 Post
Default

Code:
    
Private Sub ScanIncomingEquipment_Load(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load
End Sub

Private Sub btnReset_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnReset.Click
        ' save work done to this point
        Me.EquipmentTableAdapter.Update(Me.APC_WirelessDataSet.Equipment)
        ' give focus to Manufacturer combo button to start next set of scans
End Sub
This is the code contained in my load and click events.
At this point, there is nothing in the load event to make a procedure.

I thoroughly understand what you are trying to show me and I agree and I like the way you explained it (you forgot to mention the Mississippi River mud, though).

I'm just not sure where to go from here.

Karen

 
Old May 9th, 2007, 08:10 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Ok. Regardless if you have any initialization going on in the Form_Load event, the methodology is the same.

Private Sub resetFormValues()
'Set all form values to their defaults
End Sub

Private Sub btnReset_Click(ByVal sender as System.Object, ByVal e as System.EventArgs) Handles btnReset.Click
 Me.EquipmentTableAdapter.Update(Me.APC_WirelessDat aSet.Equipment)
 Me.resetFormValues()
End Sub

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old May 9th, 2007, 08:22 AM
Authorized User
 
Join Date: Nov 2006
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ef1196
Default

Try this:
    Private Sub btnReset_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles btnReset.Click
        ' save work done to this point
        Me.EquipmentTableAdapter.Update(Me.APC_WirelessDat aSet.Equipment)

        '* This should refill your table adapter and reset/rebind
        '* any controls on your form. You may need to manually
        '* clear/reset any unbound controls.

        Me.EquipmentTableAdapter.ClearBeforeFill = True
        Me.EquipmentTableAdapter.Fill(Me.APC_WirelessDataS et.Equipment)


        ' give focus to Manufacturer combo button to start next set of scans
    End Sub




Best Regards,
Earl Francis
 
Old May 9th, 2007, 01:23 PM
Authorized User
 
Join Date: Dec 2006
Posts: 70
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thanks to Earl and Doug for your help.

Now I'm trying to figure out how to clear a datasource from a combo box.

This works fine during the initial load of the form.
Code:
        If (Me.cmbCarrier.DataSource = "CarrierLookups") Then
            Me.cmbCarrier.DataSource = "Nothing"
        End If
        Me.cmbCarrier.Items.Clear()
This is its complaint now:
System.InvalidCastException was unhandled
  Message="Overload resolution failed because no Public '=' can be called with these arguments:
    'Public Shared Operator =(a As String, b As String) As Boolean':
        Argument matching parameter 'a' cannot convert from 'DataTable' to 'String'."

I did what I thought I understood the information in Help said, but obviously I misunderstood.

Karen






Similar Threads
Thread Thread Starter Forum Replies Last Post
how to initialize arrays in c# apoorvchandra C# 2005 1 July 12th, 2008 08:35 PM
Can't initialize variables auguri Visual Basic 2005 Basics 1 March 26th, 2007 05:05 PM
failing to initialize the enterprise manager caojun SQL Server 2000 2 May 9th, 2005 08:23 PM
initialize variables junemo Pro PHP 2 July 15th, 2004 03:04 PM
initialize serial port miguel.ossa C++ Programming 0 February 13th, 2004 01:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.