Results 1 to 8 of 8

Thread: coding prob ***resolved***

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2004
    Posts
    100

    coding prob ***resolved***

    i have five values to be compared with a value.
    the five values must be greater than some value.
    if the 5 values are less than that,
    the system will count how many of them are less than
    the value.
    the count value will be displayed in a label.
    my prob is the count value will always return 0 value even though
    there is a lesser value .
    why is that??
    i'm new in vb programming, so anyone here could help me
    fixing the coding below.
    thank u in advance

    VB Code:
    1. bb = 0
    2. If Val(Label98.Caption) < Val(Label110.Caption) Then
    3.     bb = bb + 1
    4.    
    5. ElseIf Val(Label99.Caption) < Val(Label110.Caption) Then
    6.    bb = bb + 1
    7.    
    8. ElseIf Val(Label100.Caption) < Val(Label110.Caption) Then
    9.     bb = bb + 1
    10.    
    11. ElseIf Val(Label102.Caption) < Val(Label110.Caption) Then
    12.    
    13.     bb = bb + 1
    14. ElseIf Val(Label101.Caption) < Val(Labe110.Caption) Then
    15.    
    16.     bb = bb + 1
    17. End If
    18. Label33.Caption = bb
    Last edited by azrina; Feb 12th, 2004 at 04:13 PM.

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Don't use Else if....just If If if and so on...

  3. #3
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    NoteMe's correct

    If Val(Label101.Caption) < Val(Labe110.Caption) Then bb = bb + 1

  4. #4
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by da_silvy
    NoteMe's correct

    If Val(Label101.Caption) < Val(Labe110.Caption) Then bb = bb + 1
    thanks for pointing that out.....Ain't I always corect...


    The problem here is that it wil only check one of them, and not all of them..listen to the english words IF and Else...that meens not both...

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2004
    Posts
    100
    ive tried using 5 individual "if" statements.
    another prob is if the count value supposed returns 3 value only
    are less than the value, but the system will return 4 values.
    why?im confused..

    VB Code:
    1. bb = 0
    2. If Val(Label98.Caption) < Val(Label110.Caption) Then
    3.     bb = bb + 1
    4. End If
    5.  
    6. If Val(Label99.Caption) < Val(Label110.Caption) Then
    7.    bb = bb + 1
    8. End If
    9.  
    10. If Val(Label100.Caption) < Val(Label110.Caption) Then
    11.     bb = bb + 1
    12.  End If
    13.  
    14. If Val(Label102.Caption) < Val(Label110.Caption) Then
    15.    
    16.     bb = bb + 1
    17. End If
    18.  
    19. If Val(Label101.Caption) < Val(Labe110.Caption) Then
    20.     bb = bb + 1
    21. End If
    22.  
    23.  
    24. Label33.Visible = True
    25. Label33.Caption = bb

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    The bolded part looks like a typo. (You should use Option Explicit if you aren't already)
    VB Code:
    1. bb = 0
    2. If Val(Label98.Caption) < Val(Label110.Caption) Then
    3.     bb = bb + 1
    4.    
    5. ElseIf Val(Label99.Caption) < Val(Label110.Caption) Then
    6.    bb = bb + 1
    7.    
    8. ElseIf Val(Label100.Caption) < Val(Label110.Caption) Then
    9.     bb = bb + 1
    10.    
    11. ElseIf Val(Label102.Caption) < Val(Label110.Caption) Then
    12.    
    13.     bb = bb + 1
    14. ElseIf Val(Label101.Caption) < Val([b]Labe110[/b].Caption) Then
    15.    
    16.     bb = bb + 1
    17. End If
    18. Label33.Caption = bb

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jan 2004
    Posts
    100
    i didnt realize that
    thank u all for helping
    god bless u..

  8. #8
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Use Option Explicit...it is better for you........then the IDE will tell you when you make mistakes like that...

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