Results 1 to 6 of 6

Thread: Elseif<Easy>

  1. #1

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Elseif<Easy>

    Just wondering why this consistently picks the same values, and how i can fix it:

    VB Code:
    1. cjb = Val(Left(ListView1.ListItems(pppp).ListSubItems(2).Text, Len(ListView1.ListItems(pppp).ListSubItems(2).Text) - 3))
    2.            
    3.             If cjb > 400 Then
    4. ListView1.ListItems(pppp).ListSubItems(4).Text = "Bad"
    5.            
    6.             Elseif cjb > 300 < 400 Then ListView1.ListItems(pppp).ListSubItems(4).Text = "Laggy"                    '< 400
    7.            
    8.             Elseif cjb > 200 < 300 Then ListView1.ListItems(pppp).ListSubItems(4).Text = "Decent" '< 300
    9.            
    10.             Elseif cjb > 100 < 200 Then ListView1.ListItems(pppp).ListSubItems(4).text = "Good"
    11.            
    12.            Elseif cjb < 100 Then ListView1.ListItems(pppp).ListSubItems(4).Text = "Great"

  2. #2
    Lively Member
    Join Date
    Apr 2005
    Posts
    68

    Re: Elseif<Easy>

    Try
    Code:
    Elseif cjb > 300 and cjb < 400 Then ListView1.ListItems(pppp).ListSubItems(4).Text = "Laggy"
    Do the same for all the ElseIf

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Elseif<Easy>

    You need to evaluate the conditions completely, so to speak.
    VB Code:
    1. Elseif cjb > 300 And cjb < 400 Then 'blah, blah, blah...
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Elseif<Easy>

    Try a Select Case. Easier to read:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.   Select Case cjb
    5.     Case Is > 399
    6.       ListView1.ListItems(pppp).ListSubItems(4).Text = "Bad"
    7.     Case 300 To 399
    8.       ListView1.ListItems(pppp).ListSubItems(4).Text = "Laggy"                    '< 400
    9.     Case 200 To 299
    10.       ListView1.ListItems(pppp).ListSubItems(4).Text = "Decent" '< 300
    11.     Case 100 To 199
    12.       ListView1.ListItems(pppp).ListSubItems(4).Text = "Good"
    13.     Case Else
    14.       ListView1.ListItems(pppp).ListSubItems(4).Text = "Great"
    15.   End Select
    16. End Sub

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Elseif<Easy>

    Even though I agree with dg about using a Select Case statement I would just like to add that in the If statement you're using you don't need to check if a value is lower then another.
    VB Code:
    1. If cjb > 400 Then
    2.     ListView1.ListItems(pppp).ListSubItems(4).Text = "Bad"
    3. ElseIf cjb > 300 Then
    4.     ListView1.ListItems(pppp).ListSubItems(4).Text = "Laggy"                    '
    5. Elseif cjb > 200 Then
    6.     ListView1.ListItems(pppp).ListSubItems(4).Text = "Decent" '< 300
    7. Elseif cjb > 100 Then
    8.     ListView1.ListItems(pppp).ListSubItems(4).text = "Good"
    9. Else
    10.     ListView1.ListItems(pppp).ListSubItems(4).Text = "Great"
    11. End If
    Since the first if checks if cbj is over 400, if it's not then it will traverse into the first elseif statement and check if cbj is greater then 300 in which case you already know that it isn't greater then 400 because if it was the first If would have been true.

  6. #6

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Elseif<Easy>

    thanks dude

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