
Dec 24th, 2013, 10:59 AM
#1
Thread Starter
Junior Member
[RESOLVED] how to make short

Dec 24th, 2013, 11:11 AM
#2
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

Dec 24th, 2013, 11:21 AM
#3
Thread Starter
Junior Member
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

Dec 24th, 2013, 11:46 AM
#4
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

Dec 24th, 2013, 11:56 AM
#5
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.

Dec 24th, 2013, 12:06 PM
#6
Thread Starter
Junior Member
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

Dec 24th, 2013, 12:07 PM
#7
Thread Starter
Junior Member
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

Dec 24th, 2013, 12:11 PM
#8
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

Dec 24th, 2013, 12:18 PM
#9
Thread Starter
Junior Member
Re: how to make short
jcis
i forgot text1 to text15

Dec 24th, 2013, 01:48 PM
#10
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
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
