[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

Problem: a text field not yeilding its contents

Friends,

I have a textbox, called txtLevel1, that has its text property initially set to 0.0005.  Now, I use this for a comparison utility; however, when it comes time to use its text value, the form is claiming that the value is Nothing.  I do the same thing with a textbox called txtLevel2.  

Basically, if the resulting difference is over 0.0005, but less than 0.0010 I want the line to turn yellow, but if it is over 0.0010 I want to turn the line red.  However, I can't compare my values to Nothing.

Here is my code:

Public Sub AddItemsToQualificationSessionHistory(ByVal DisplayCarNumber As String, ByVal DisplayPCLapTime As String, ByVal DisplayPCDifference As String, ByVal DisplayAMBLapTime As String, ByVal DisplayCameraDifference As String, ByVal DisplayCameraLapTime As String, ByVal LargestDifference As Decimal)
        Try

            Dim Level1TextToDecimal As Decimal
            Dim Level2TextToDecimal As Decimal
            Dim li As ListViewItem
            Dim ConvertLevel1Text As String
            Dim ConvertLevel2Text As String

            ConvertLevel1Text = Me.txtLevel1.Text
            ConvertLevel2Text = Me.txtLevel2.Text

            Level1TextToDecimal = CType(ConvertLevel1Text, Decimal)
            Level2TextToDecimal = CType(ConvertLevel2Text, Decimal)

            li = lvQualificationSessionHistory.Items.Add(DisplayCarNumber)
            If LargestDifference > Level2TextToDecimal Then
                li.BackColor = Color.Red
            ElseIf LargestDifference > Level1TextToDecimal Then
                li.BackColor = Color.Yellow
            Else
                li.BackColor = Color.White
            End If
            li.SubItems.Add(DisplayAMBLapTime)
            li.SubItems.Add(DisplayPCLapTime)
            li.SubItems.Add(DisplayPCDifference)
            li.SubItems.Add(DisplayCameraLapTime)
            li.SubItems.Add(DisplayCameraDifference)

        Catch ex As Exception

            MessageBox.Show(ex.Message, "Add Record to Qual Session History")

        End Try

    End Sub

Thanks in advance!
0
indy500fan
Asked:
indy500fan
  • 12
  • 11
1 Solution
 
ctm5Commented:
Have you experimented with conversion functions other than CType? For example, you could try CDec or Convert.ToDecimal (although using that one with a string is not CLS-compliant).

Also, remember that you can probably avoid the decimal conversion altogether by simply comparing the two textbox values as strings. The string .00001 will always be "less" than .00005.

     Dim LargestDifference As String = ".00007"      'or whatever
     If LargestDifference > txtLevel1.Text Then....


ctm5
0
 
indy500fanAuthor Commented:
ctm5,

The conversion isn't the problem.  If I physically set ConvertLevel1Text = "0.0005" it would work fine.  The problem is coming from reading the text property of the txtLevel1 textbox.  I have set it to "0.0005" in the properties setting, but when my program reaches this point in the execution, it is saying (via quick watch) that txtLevel1.text = Nothing.

Eric
0
 
ctm5Commented:
Hmmm. I just did a little test and set the value of a text box to .0005 and things worked fine. At what point are you using the quick watch? Are you stepping through the code? If so, you can watch the quick watch to see where the value of the textbox changes. You can also search your code for instances of txtLevel1.Text to see if by accident you are resetting it. Do you dispose of the textbox or anything like that? Remember that the values of controls won't persist if you close the form. Some wild stabs here, but what you are reporting points to a problem other than an issue with the particular value you want to have in the textbox.  Try changing the text of txtLevel1 to, say, "George" or "2006" to prove that.

ctm5
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
indy500fanAuthor Commented:
ctm5,

I hear what you are saying, but I searched the entire project, and I never reset the value.

In fact, I wondered if it was an initialization problem, so I set the text property of txtLevel1 to nothing.  Now, on form load, I set the values of the text property to "0.0005," and in fact, that value shows up in the textbox.  However, later, when I run the code previously posted, the text property is still showing Nothing.

Private Sub QCUMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Global.SQLServer = txtSqlServer.Text
        Global.CompletedLapRecordActive = True
        Global.TrackRecordActive = True
        'GetSettings()
        '<==== Add this line
        QCUDatabaseUpdater.QCUMainForm = Me
        'QCUSessionHistoryUpdater.QCUMainForm = Me

        txtLevel1.Text = "0.0005"
        txtLevel2.Text = "0.0010"
      End Sub

I think I've got something going really weird.  If I put a breakpoint where a textbox text property read occurs, it doesn't fully stop debugging, but the form disappears and never comes back.  However, if I rerun it without the break point it runs past that code, but the txtLevel1.text property is showing blank.

Weird.  Any suggestions?
0
 
ctm5Commented:
In the code you originally posted, what does "Me" refer to? Are you sure it is referring to the form? What happens if you take out the Me?

ctm5
0
 
indy500fanAuthor Commented:
I added the Me to see if it would help with the loss of value.

Me is the main form that all this is happening in.
0
 
indy500fanAuthor Commented:
To answer the second part of your question, nothing different happens.
0
 
ctm5Commented:
Is it just this one textbox? Try deleting it and adding it again.

ctm5
0
 
indy500fanAuthor Commented:
It's two, but I think I tried that already.  I'll try it again.
0
 
ctm5Commented:
I just went back and read over all of this. Did you step through the code to see where exactly the value of the textbox changes?

ctm5
0
 
indy500fanAuthor Commented:
Yes, and I can tell you that, at the time the form loads, the value of the text property is ""

So somewhere between me pushing the play button and the form loading, it gets set to "".
0
 
ctm5Commented:
Sorry to be so particular, but you are my eyes here!

I'm glad that you recognize that this is wacky behavior on the text box's part. The only way to solve this problem is to go back to the beginning.

Double and triple check the properties of the text box. Make sure the Text property is set to .0005. You should see this reflected in the design-time mockup of your form. If you haven't set the Text property, the design-time mockup might just show the name of the control.

Search through the code again, making sure to include hidden text, for any instance of txtLevel1.Text to double check that the value isn't getting reset. Don't match case, don't search for whole word, and search through your entire project. Also search for txtLevel1.Clear, txtLevel1.Dispose, and txtLevel1.Undo.

When you hit play, are you running the Debug or Release version?

ctm5
0
 
indy500fanAuthor Commented:
Thank you for sticking with this and being patient

I am running this in Debug version.

I'll search using the criteria you mentioned.
0
 
ctm5Commented:
Again, I don't mean to insult your intelligence. But I have a feeling this is going to be one of those "I can't believe I overlooked this...." kind of situations. ("Ma! The TV doesn't work!" "Is it plugged in?" "Oh.")

ctm5

 ````
   o o
    ~~
0
 
indy500fanAuthor Commented:
No insult taken.  I have a lot of these "I can't believe I overlooked this..."

:)
0
 
indy500fanAuthor Commented:
Well that turns out to be a bust.  I searched and turned up nothing.  I even looked for my favorite of txtLevel1.Text = Something that would break it
0
 
ctm5Commented:
Add a third textbox. Set its Text property to your initials or something. See what happens to its value.

Also, in the form load, add a MsgBox(txtLevel1.Text) to see what you get.

ctm5
0
 
ctm5Commented:
Also, you can try creating a brand new project. Add a form and put a textbox on it. Set its Text to be .0005. I guarantee that will work. So we can see that it isn't your setup, etc.

Also, try quitting out of VS with the project that is causing you fits. Maybe even reboot. Just to eliminate all other possibilities.

If worse comes to worse, send me your form and I will study it.

ctm5
yes, I actually do some of my own work from time to time!
0
 
indy500fanAuthor Commented:
I've tried all those things and yes I have had the same results (except for the new project -- and it worked as you suspected)

I'm glad I wasn't drinking when I read that last line, I probably would have had it shooting out of my nose!
0
 
ctm5Commented:
So send me your form, if you want. I'm out of other ideas.

ctm5
0
 
indy500fanAuthor Commented:
Hey, I just deleted my pbd file, recompiled it and it seems to be working <saying that cautiously>
0
 
ctm5Commented:
<groan> We knew it would be something ridiculous.

,,,,,,
 ~~
   o
0
 
indy500fanAuthor Commented:
Thanks for working with me on this!

Regards,
Eric
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 12
  • 11
Tackle projects and never again get stuck behind a technical roadblock.
Join Now