Results 1 to 10 of 10

Thread: [RESOLVED] how to make short

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2013
    Posts
    23

    Resolved [RESOLVED] how to make short

    Name:  index - Copy.png
Views: 436
Size:  48.1 KB

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: how to make short

    use the mod operator...

    Code:
    If (index mod 10 ) = 1 then ....
    To further that, I'd use elseIf for the remainder:
    Code:
    If (index mod 10 ) = 1 then .... 
    elseIf (index mod 10 ) = 2 then .... 
    elseIf (index mod 10 ) = 3 then .... 
    elseIf (index mod 10 ) = 4 then .... 
    elseIf (index mod 10 ) = 5 then .... 
    elseIf (index mod 10 ) = 6 then .... 
    elseIf (index mod 10 ) = 7 then .... 
    elseIf (index mod 10 ) = 8 then .... 
    elseIf (index mod 10 ) = 9 then .... 
    elseIf (index mod 10 ) = 0 then ....

    or use a Case statement:
    Code:
    Select case  (index mod 10 )
      case 1
    ...
      case 2
    ...
      case 3
    ...
      case 4
    ...
      case 5
    ...
      case 6
    ...
      case 7
    ...
      case 8
    ...
      case 9
    ...
      case 0
    ...
    End case

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2013
    Posts
    23

    Re: how to make short

    sorry but i nedd sort

    If Index = 1 Or Index = 11 Or Index = 21 Or Index = 31 Or Index = 41 Then
    t.Text = Text1(Index)
    End If

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: how to make short

    sweet jesus... so that means you don't know about the mod operator do you? sigh... yes, I know you're trying to shorten it... there's only so much you can with it... based on the code I saw a pattern.... 1,11,21,3,1,41,51,61, etc...

    1 mod 10 = 1
    11 mod 10 = 1
    21 mod 10 = 1
    31 mod 10 = 1
    ... see a pattern there?

    2 mod 10 = 2
    12 mod 10 = 2
    22 mod 10 = 2
    see the pattern again?

    10 mod 10 = 0
    20 mod 10 = 0
    30 mod 10 = 0
    40 mod 10 = 0
    Again... see a pattern?

    that did exactly what you asked for... shortening the if statements...based on what you gave as a pattern, using Mod 10 against index as I showed will shorten down the coding... a lot...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: how to make short

    Using Mod as techgnome suggested you can even short all your code to this:
    Code:
        Dim lngIndex As Long
        lngIndex = Index Mod 10
        If lngIndex = 0 Then lngIndex = 10
        t.Text = Me.Controls("Text" & lngIndex)(Index)
    Last edited by jcis; Dec 24th, 2013 at 12:07 PM.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Dec 2013
    Posts
    23

    Re: how to make short

    techgnome

    thank you

    i checked now
    your code is good


    can you make short for this ??

    If Index = 1 Or Index = 16 Or Index = 31 Or Index = 46 Or Index = 61 Then
    t.Text = Text1(Index)
    End If
    If Index = 2 Or Index = 17 Or Index = 32 Or Index = 47 Or Index = 62 Then
    t.Text = Text1(Index)
    End If
    If Index = 3 Or Index = 18 Or Index = 33 Or Index = 48 Or Index = 63 Then
    t.Text = Text1(Index)
    End If
    If Index = 4 Or Index = 19 Or Index = 34 Or Index = 49 Or Index = 64 Then
    t.Text = Text1(Index)
    End If
    If Index = 5 Or Index = 20 Or Index = 35 Or Index = 50 Or Index = 65 Then
    t.Text = Text1(Index)
    End If
    If Index = 6 Or Index = 21 Or Index = 36 Or Index = 51 Or Index = 66 Then
    t.Text = Text1(Index)
    End If
    If Index = 7 Or Index = 22 Or Index = 37 Or Index = 52 Or Index = 67 Then
    t.Text = Text1(Index)
    End If
    If Index = 8 Or Index = 23 Or Index = 38 Or Index = 53 Or Index = 68 Then
    t.Text = Text1(Index)
    End If
    If Index = 9 Or Index = 24 Or Index = 39 Or Index = 54 Or Index = 69 Then
    t.Text = Text1(Index)
    End If
    If Index = 10 Or Index = 25 Or Index = 40 Or Index = 55 Index = 70 Then
    t.Text = Text1(Index)
    End If
    If Index = 11 Or Index = 26 Or Index = 41 Or Index = 56 Or Index = 71 Then
    t.Text = Text1(Index)
    End If
    If Index = 11 Or Index = 27 Or Index = 42 Or Index = 57 Or Index = 72 Then
    t.Text = Text1(Index)
    End If
    If Index = 13 Or Index = 28 Or Index = 43 Or Index = 58 Or Index = 73 Then
    t.Text = Text1(Index)
    End If
    If Index = 14 Or Index = 29 Or Index = 44Or Index = 59 Or Index = 74 Then
    t.Text = Text1(Index)
    End If
    If Index = 15 Or Index = 30 Or Index = 45 Or Index = 60 Or Index = 75 Then
    t.Text = Text1(Index)
    End If

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Dec 2013
    Posts
    23

    Re: how to make short

    techgnome

    thank you

    i checked now
    your code is good


    can you make short for this ??

    If Index = 1 Or Index = 16 Or Index = 31 Or Index = 46 Or Index = 61 Then
    t.Text = Text1(Index)
    End If
    If Index = 2 Or Index = 17 Or Index = 32 Or Index = 47 Or Index = 62 Then
    t.Text = Text1(Index)
    End If
    If Index = 3 Or Index = 18 Or Index = 33 Or Index = 48 Or Index = 63 Then
    t.Text = Text1(Index)
    End If
    If Index = 4 Or Index = 19 Or Index = 34 Or Index = 49 Or Index = 64 Then
    t.Text = Text1(Index)
    End If
    If Index = 5 Or Index = 20 Or Index = 35 Or Index = 50 Or Index = 65 Then
    t.Text = Text1(Index)
    End If
    If Index = 6 Or Index = 21 Or Index = 36 Or Index = 51 Or Index = 66 Then
    t.Text = Text1(Index)
    End If
    If Index = 7 Or Index = 22 Or Index = 37 Or Index = 52 Or Index = 67 Then
    t.Text = Text1(Index)
    End If
    If Index = 8 Or Index = 23 Or Index = 38 Or Index = 53 Or Index = 68 Then
    t.Text = Text1(Index)
    End If
    If Index = 9 Or Index = 24 Or Index = 39 Or Index = 54 Or Index = 69 Then
    t.Text = Text1(Index)
    End If
    If Index = 10 Or Index = 25 Or Index = 40 Or Index = 55 Index = 70 Then
    t.Text = Text1(Index)
    End If
    If Index = 11 Or Index = 26 Or Index = 41 Or Index = 56 Or Index = 71 Then
    t.Text = Text1(Index)
    End If
    If Index = 11 Or Index = 27 Or Index = 42 Or Index = 57 Or Index = 72 Then
    t.Text = Text1(Index)
    End If
    If Index = 13 Or Index = 28 Or Index = 43 Or Index = 58 Or Index = 73 Then
    t.Text = Text1(Index)
    End If
    If Index = 14 Or Index = 29 Or Index = 44Or Index = 59 Or Index = 74 Then
    t.Text = Text1(Index)
    End If
    If Index = 15 Or Index = 30 Or Index = 45 Or Index = 60 Or Index = 75 Then
    t.Text = Text1(Index)
    End If

  8. #8
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: how to make short

    Everything inside those IF look the same, so the short version is simply:
    Code:
    t.Text = Text1(Index)
    I bet you missed something else there

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Dec 2013
    Posts
    23

    Re: how to make short

    jcis
    i forgot text1 to text15

  10. #10
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: how to make short

    Try Mod 15 ... mod returns the remainder of a division operation... so when you see a repeating pattern like the ones above, you just need to determine the value you need to reproduce the pattern... in that last case it's 15 ...

    -tgb
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

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