Results 1 to 8 of 8

Thread: Optimize this!!!!

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Québec, Canada
    Posts
    284

    Optimize this!!!!

    There must be a way to optimize this code:
    VB Code:
    1. If strTempo = "a" Or strTempo = "b" Or strTempo _
    2.             = "c" Or strTempo = "d" Or strTempo = "e" _
    3.             Or strTempo = "f" Or strTempo = "g" Or strTempo _
    4.             = "h" Or strTempo = "i" Or strTempo = "j" Or _
    5.             strTempo = "k" Or strTempo = "l" Or strTempo = "m" _
    6.             Or strTempo = "n" Or strTempo = "o" Or strTempo _
    7.             = "p" Or strTempo = "q" Or strTempo = "r" Or _
    8.             strTempo = "s" Or strTempo = "t" Or strTempo = _
    9.             "u" Or strTempo = "v" Or strTempo = "w" Or _
    10.             strTempo = "x" Or strTempo = "y" _
    11.             Or strTempo = "z" Or strTempo = "A" Or strTempo = "B" Or strTempo _
    12.             = "C" Or strTempo = "D" Or strTempo = "E" _
    13.             Or strTempo = "F" Or strTempo = "G" Or strTempo _
    14.             = "H" Or strTempo = "I" Or strTempo = "J" Or _
    15.             strTempo = "K" Or strTempo = "L" Or strTempo = "M" _
    16.             Or strTempo = "N" Or strTempo = "O" Or strTempo _
    17.             = "P" Or strTempo = "Q" Or strTempo = "R" Or _
    18.             strTempo = "S" Or strTempo = "T" Or strTempo = _
    19.             "U" Or strTempo = "V" Or strTempo = "W" Or _
    20.             strTempo = "X" Or strTempo = "Y" _
    21.             Or strTempo = "Z" Then
    22.                
    23.                 TrouverProchainAlpha = i - 1
    24.                 Exit Function
    25.         End If

    Please help me!

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    try...
    VB Code:
    1. If strTempo Like "[A-Z]" Or strTempo Like "[a-z]" Then
    2.  '...
    3. End If

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    WorkHorse
    Guest

    Little slow on the trigger

    VB Code:
    1. If strTempo Like "[A-Z]" Or strTempo Like "[a-z]" Then MsgBox "ALPHA!"

    EDIT: or you could use crptcbalde's code.

  4. #4
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Another way...
    VB Code:
    1. If ASC(Ucase$(strTempo)) >= A AND ASC(Ucase$(strTempo)) <= 90 Then
    2.         TrouverProchainAlpha = i - 1
    3.         Exit Function
    4. End If
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Québec, Canada
    Posts
    284
    Thank you guys!!

  6. #6
    WorkHorse
    Guest
    ASC(Ucase$(strTempo)) >= A

    Well, I see where you were going anyway.

  7. #7
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Sorry.... I was still pressing the Alt-Key (to check the number)

    VB Code:
    1. If ASC(Ucase$(strTempo)) >= 65 AND ASC(Ucase$(strTempo)) <= 90 Then
    2.         TrouverProchainAlpha = i - 1
    3.         Exit Function
    4. End If
    or
    VB Code:
    1. If UCase$(strTempo) >= "A" And UCase$(strTempo) <= "Z" Then
    2.         TrouverProchainAlpha = i - 1
    3.         Exit Function
    4. End If
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  8. #8
    Fanatic Member
    Join Date
    Jun 2001
    Posts
    521
    Use constants: vbKeyA, vbKeyZ.
    Store Asc(UCase$(strTemp) in a variable so you don't have to Asc and UCase$ it twice.
    VB Code:
    1. Dim charCode As Integer
    2.    
    3.     charCode = Asc(UCase$(strTempo))
    4.     If vbKeyA <= charCode And charCode <= vbKeyZ Then
    5.         TrouverProchainAlpha = i - 1
    6.         Exit Sub
    7.     End If
    By the way, don't ever code like you did when asking the question--checkerboard patterns are not for code . If you ever need to check a ton of values like that, line up the code more neatly.

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