Results 1 to 6 of 6

Thread: [RESOLVED] Less Then 0 but greater then (negative .5)

  1. #1

    Thread Starter
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Resolved [RESOLVED] Less Then 0 but greater then (negative .5)

    Making a traffic light color app and cannot figure out how to handle a negative value ( -0.5) to make a panels BackColor = Color.Yellow


    Code:
      
      If CDbl(TxFrontThrustAfter.Text) < 0.0 And CDbl(TxFrontThrustAfter.Text) > -0.5 Then
                PnlFrontAfterThrust.BackColor = Color.Yellow
            End If
    Please see attached image

    Name:  PXL_20231028_041219131.jpg
Views: 256
Size:  24.7 KB

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Less Then 0 but greater then (negative .5)

    That code could be improved in various ways but it looks like it should do exactly what you want as it is. What's the actual problem?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: Less Then 0 but greater then (negative .5)

    thankyou, i am now thinking its due to below in a earlier sub.

    Code:
            'REMOVES "-" VALUE FROM TEXTBOX
        If TxFrontThrustAfter.Text.Contains("-") Then
                'MessageBox.Show(TxFThrustBefore.Text)
                Dim Str As String = TxFrontThrustAfter.Text
                Str = Str.Replace(“-“, “”)
                TxFrontThrustAfter.Text = Str
                End If
    Last edited by toecutter; Oct 28th, 2023 at 03:14 AM.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [RESOLVED] Less Then 0 but greater then (negative .5)

    Maybe you should be using a NumericUpDown in the first place, rather than a TextBox.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [RESOLVED] Less Then 0 but greater then (negative .5)

    Also, I'm not sure whether this is appropriate in your context but you might consider a Select Case to determine the colour:
    Code:
    Dim x As Double
    
    Select Case x
        Case Is >= 0.2
    
        Case Is >= 0.0
    
        Case Is >= -0.5
    
        Case Else
    
    End Select
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: [RESOLVED] Less Then 0 but greater then (negative .5)

    Quote Originally Posted by jmcilhinney View Post
    Also, I'm not sure whether this is appropriate in your context but you might consider a Select Case to determine the colour:
    Code:
    Dim x As Double
    
    Select Case x
        Case Is >= 0.2
    
        Case Is >= 0.0
    
        Case Is >= -0.5
    
        Case Else
    
    End Select
    this would be perfect, thx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width