Thread: vbscript help
View Single Post
Old 2008-11-12, 12:12   #14
Patrick123
 
Patrick123's Avatar
 
Jan 2006
JHB, South Africa

2358 Posts
Default

It's only a pleasure IronBits.

I notice that the extra line that you inserted:
Code:
UserName = Team_Name
This should actually be placed before the conditionals as it overrides all you conditionals.

Now instead of using an array and simply looping through it until the team name is found, we apply a very simplified hashing technique.

What we do is to load the team.dat file & get the maximum occurrence of the first letter in Uppercase, as you can see, there are 2 teams that start with 'X' and another 2 with 'A'

In this case, we then create a 2 dimensional array (26,2) and slot the teams into this array based on their starting letter e.g.
Code:
t(0,0) = "AMDUsers"
t(0,1) = "ArsTechnica"
...
t(23,0) = "XtremeSystems"
t(23,1) = "XGrubbersKickAss"
The array will have a lot of blank or unused slots, but where we lose on the swings, we make up on the merry-go-round i.e. memory vs speed

Now it will be a simple matter of coding:
Code:
arrMyTeamName = Split(Team_Name,"_",-1,1)

UserName = Team_Name ' no need to include 'gd' as this will take care of him.

If UBound(arrMyTeamName) > 0 then
   idx := Asc(arrMyTeamName(0)) - 65  ' this will make 'A' = 0, 'B' = 1, etc.

   For col = 0 to UBound(t(idx))
      If t(idx,col) = arrMyTeamName(0) then
         UserName = arrMyTeamName(1)
         Exit For    ' break out, we don't need to check further.
      End If
   Next Col

End If

Regards
Patrick
Patrick123 is offline   Reply With Quote