Solved

Textbox does not update with new value

Posted on 2011-03-23
18
244 Views
Last Modified: 2012-05-11
I have a sub that will loop through twice on the first time the WirelessBase_RF_CH_Changed is set to false and goes into the first condition. One the second loop the WirelessBase_RF_CH_Changed is set to true with the updated value (the value is there and has been updated) I then assign it to the me.Label (lblBaseRFChannel.text) the me.Label shows the updated value when I place a breakpoint in the debug mode, however after I step through and look at the runtime the value on the screen is the old value from the first loop through

Any ideas?
If WirelessBase_RF_CH_Changed = False Then
                    BaseRFChannel = FindBaseStationArrayInformation(23)
                    BaseRFChannel = BaseRFChannel.Substring(BaseRFChannel.LastIndexOf("..") + 2).Trim()
                    Me.lblBaseRFChannel.Text = BaseRFChannel
                Else
                    Me.lblBaseRFChannel.Text = String.Empty
                    BaseRFChannel = RF_Selected
                    Me.lblBaseRFChannel.Text = BaseRFChannel
                End If

Open in new window

0
Comment
Question by:cmdolcet
  • 9
  • 5
  • 2
  • +1
18 Comments
 
LVL 10

Expert Comment

by:kdwood
ID: 35198591

See if this does the trick, add Application.DoEvents after you update the label?

http://msdn.microsoft.com/en-us/library/system.windows.forms.application.doevents.aspx

Regards,

Keith
0
 

Author Comment

by:cmdolcet
ID: 35199245
No that method on the link about calling the Doevents did not work
0
 
LVL 10

Expert Comment

by:kdwood
ID: 35199275

Can you post your code where you have your loops set up?  I think we will need to see more to determine what is happening.

0
 

Author Comment

by:cmdolcet
ID: 35199451

Private Sub UpdateBaseUnit_Mobile_Collect()
        Try
            If Wireless_Base_Updated = False Then
                FindBaseStationArrayInformation = strDataCOM1.Split(New Char() {Chr(13)}, StringSplitOptions.RemoveEmptyEntries)
                grpBaseStation.Enabled = True

                Dim serialnumber As String = FindBaseStationArrayInformation(6)
                serialnumber = serialnumber.Substring(serialnumber.LastIndexOf("..") + 2).Trim()
                Me.lblbaseserial.Text = serialnumber
                Wireless_MC_USB_Base_Serial = serialnumber

                Dim BaseModel As String = FindBaseStationArrayInformation(3)
                BaseModel = BaseModel.Substring(BaseModel.LastIndexOf("..") + 2).Trim()
                Me.lblBaseModel.Text = BaseModel

                Dim FirmwareVer As String = FindBaseStationArrayInformation(4)
                FirmwareVer = FirmwareVer.Substring(FirmwareVer.LastIndexOf("..") + 2).Trim()
                Me.lblBaseFirmwareVer.Text = FirmwareVer
                BaseStation_Version = FirmwareVer

                Dim BaseFirmwareDate As String = FindBaseStationArrayInformation(5)
                BaseFirmwareDate = BaseFirmwareDate.Substring(BaseFirmwareDate.LastIndexOf("..") + 2).Trim()
                Me.lblBaseFirmwareDate.Text = BaseFirmwareDate
                BaseStation_Version_Date = BaseFirmwareDate

                Dim BaseOperationalMode As String = FindBaseStationArrayInformation(8)
                BaseOperationalMode = BaseOperationalMode.Substring(BaseOperationalMode.LastIndexOf("..") + 2).Trim()
                Me.lblBaseOperationalMode.Text = BaseOperationalMode

                Dim BaseDescription As String = FindBaseStationArrayInformation(10)
                BaseDescription = BaseDescription.Substring(BaseDescription.LastIndexOf("..") + 2).Trim()
                Me.lblBaseDescription.Text = BaseDescription

                BaseStationID = FindBaseStationArrayInformation(20)
                BaseStationID = BaseStationID.Substring(BaseStationID.LastIndexOf("..") + 2).Trim()
                Me.lblBaseStationID.Text = BaseStationID

                BaseNetworkID = FindBaseStationArrayInformation(21)
                BaseNetworkID = BaseNetworkID.Substring(BaseNetworkID.LastIndexOf("..") + 2).Trim()
                Old_Base_NetworkID = BaseNetworkID
                Me.lblBaseNetworkID.Text = BaseNetworkID


                BasePanID = FindBaseStationArrayInformation(22)
                BasePanID = BasePanID.Substring(BasePanID.LastIndexOf("..") + 2).Trim()
                Me.lblBasePANID.Text = BasePanID
                Base_PAN_ID_HEX_Value1 = "&H" & BasePanID.Substring(0, 2)
                Base_PAN_ID_HEX_Value2 = "&H" & BasePanID.Substring(2, 2)
                Dim Send_PAN_ID_HEX() As Byte = {Base_PAN_ID_HEX_Value1, Base_PAN_ID_HEX_Value2}
                Send_PAN_ID_Original_HEX = Send_PAN_ID_HEX
                If WirelessBase_RF_CH_Changed = False Then
                    BaseRFChannel = FindBaseStationArrayInformation(23)
                    BaseRFChannel = BaseRFChannel.Substring(BaseRFChannel.LastIndexOf("..") + 2).Trim()
                    Me.lblBaseRFChannel.Text = BaseRFChannel
                Else
                    'Updates the New RF Channel on the Form in Runtime
                    Me.lblBaseRFChannel.Text = String.Empty
                    BaseRFChannel = RF_Selected
                    Me.lblBaseRFChannel.Text = BaseRFChannel
                End If

   End If
        Catch ex As Exception

        End Try
    End Sub

Open in new window

0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 35199506
You sure you're not getting an exception that is being ignored?...

Pop a MessageBox in your Catch block:

        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
0
 

Author Comment

by:cmdolcet
ID: 35206236
Idle_Mind:I added the MessageBox.Show(ex.ToString) to the catch block and I didn;t receive any errors.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 35206712
...and you're sure it's making it into the main If block the second time?

    Private Sub UpdateBaseUnit_Mobile_Collect()
        Try
            If Wireless_Base_Updated = False Then

So "Wireless_Base_Updated" didn't somehow get changed to True?
0
 

Author Comment

by:cmdolcet
ID: 35206949
yes correct. I stepped through the loop twice and at no point in time did it ever get caught by the catch statement.

I even look at the variable  BaseRFChannel and it contains the updated value I even step a line further and see that the Me.lblBaseRFChannel.Text  is changed to the updated value.

It seems just not on the form the update happens
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 15

Expert Comment

by:x77
ID: 35297870
You says WirelessBase_RF_CH_Changed through twice  ?

Is this a Event sub ?.

Is a common mistake think that the Changed Event is raised only when user changes the value. It raises also when your code modify the value.

private Processing_WirelessBase_RF_CH_Changed = false.
Private sub WirelessBase_RF_CH_Changed (...)
   if Processing_WirelessBase_RF_CH_Changed  then return
   Procesing_WirelessBase_RF_CH_Changed= true
   ..... here your code .....
   Processing_WirelessBase_RF_CH_Changed= false
end sub


0
 

Author Comment

by:cmdolcet
ID: 35317928
x77: Yes this is an event sub.
0
 

Author Comment

by:cmdolcet
ID: 35374906
x77: I may be misleading everyone. Let me explain in detail at what i am doing and what I want to accomplish. I have (2) forms the first form loads and opens a serial COM port. and keeps it open on the first form I have a textbox that will return a value from the Serial string once the COM Port is open, then I open the second form up from a control button and set a value to the variable. I then want to take that public variable and set the value to my textbox on my first form.

0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 35375940
So you pass the value from the first form to the second form.  Got it.
The user is then changing the value on the second form?
...and you want to update the value on the first form with the new value?

Do you want the update to occur in real-time?...or only when the second form is closed?
0
 

Author Comment

by:cmdolcet
ID: 35378603
I think I am  trying to invoke a method on the form before the form has finished initializing. However I would like to do it real time.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 35379410
So when the value in the second form is changed, you want the value in the first form to change at the same time?
0
 

Accepted Solution

by:
cmdolcet earned 0 total points
ID: 35383669
Idle_Mind: The code below seemed to have solved the issue. It seems I wasn;t initializing correctly.





Public F1 As Form1
in some method:
F1.MethodName()

Form1:
in a button click:
Dim F2 As New Form2
F2.F1 = Me
F2.Show()

Open in new window

0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 35383692
Glad you figured it out.  I see you are passing a reference to Form1 into Form2.  =)
0
 

Author Closing Comment

by:cmdolcet
ID: 35414378
There was a similar issue
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now