|
-
Apr 18th, 2005, 11:18 PM
#1
Thread Starter
Admodistrator
Elseif<Easy>
Just wondering why this consistently picks the same values, and how i can fix it:
VB Code:
cjb = Val(Left(ListView1.ListItems(pppp).ListSubItems(2).Text, Len(ListView1.ListItems(pppp).ListSubItems(2).Text) - 3))
If cjb > 400 Then
ListView1.ListItems(pppp).ListSubItems(4).Text = "Bad"
Elseif cjb > 300 < 400 Then ListView1.ListItems(pppp).ListSubItems(4).Text = "Laggy" '< 400
Elseif cjb > 200 < 300 Then ListView1.ListItems(pppp).ListSubItems(4).Text = "Decent" '< 300
Elseif cjb > 100 < 200 Then ListView1.ListItems(pppp).ListSubItems(4).text = "Good"
Elseif cjb < 100 Then ListView1.ListItems(pppp).ListSubItems(4).Text = "Great"
-
Apr 18th, 2005, 11:27 PM
#2
Lively Member
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
-
Apr 18th, 2005, 11:28 PM
#3
Re: Elseif<Easy>
You need to evaluate the conditions completely, so to speak.
VB Code:
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Apr 18th, 2005, 11:43 PM
#4
Re: Elseif<Easy>
Try a Select Case. Easier to read:
VB Code:
Option Explicit
Private Sub Form_Load()
Select Case cjb
Case Is > 399
ListView1.ListItems(pppp).ListSubItems(4).Text = "Bad"
Case 300 To 399
ListView1.ListItems(pppp).ListSubItems(4).Text = "Laggy" '< 400
Case 200 To 299
ListView1.ListItems(pppp).ListSubItems(4).Text = "Decent" '< 300
Case 100 To 199
ListView1.ListItems(pppp).ListSubItems(4).Text = "Good"
Case Else
ListView1.ListItems(pppp).ListSubItems(4).Text = "Great"
End Select
End Sub
-
Apr 19th, 2005, 12:03 AM
#5
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:
If cjb > 400 Then
ListView1.ListItems(pppp).ListSubItems(4).Text = "Bad"
ElseIf cjb > 300 Then
ListView1.ListItems(pppp).ListSubItems(4).Text = "Laggy" '
Elseif cjb > 200 Then
ListView1.ListItems(pppp).ListSubItems(4).Text = "Decent" '< 300
Elseif cjb > 100 Then
ListView1.ListItems(pppp).ListSubItems(4).text = "Good"
Else
ListView1.ListItems(pppp).ListSubItems(4).Text = "Great"
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.
-
Apr 19th, 2005, 03:31 PM
#6
Thread Starter
Admodistrator
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|