![]() |
|
|
#12 | |
|
Jan 2006
JHB, South Africa
9D16 Posts |
Quote:
The other piece of code: Code:
Team_Name = MyArray(1)
arrMyTeamName = Split(Team_Name,"_",-1,1)
if arrMyTeamName(0) = "gd" Then UserName = Team_Name End If
If arrMyTeamName(0) = "Free-DC" Then UserName = arrMyTeamName(1) End If
If arrMyTeamName(0) = "AMDUsers" Then UserName = arrMyTeamName(1) End If
If arrMyTeamName(0) = "ArsTechnica" Then UserName = arrMyTeamName(1) End If
If arrMyTeamName(0) = "XtremeSystems" Then UserName = arrMyTeamName(1) End If
If arrMyTeamName(0) = "Team_Italia" Then UserName = arrMyTeamName(1) End If
If arrMyTeamName(0) = "XGrubbersKickAss" Then UserName = arrMyTeamName(1) End If
If arrMyTeamName(0) = "Ukraine" Then UserName = arrMyTeamName(1) End If
If arrMyTeamName(0) = "Singapura" Then UserName = arrMyTeamName(1) End If
If arrMyTeamName(0) = "RaidersOfTheLostPrime" Then UserName = arrMyTeamName(1) End If
Code:
Team_Name = MyArray(1)
arrMyTeamName = Split(Team_Name,"_",-1,1)
If UBound(arrMyTeamName) > 0 then
UserName = arrMyTeamName(1)
Else
UserName = Team_Name
End If
Regards Patrick |
|
|
|
|
|
|
#13 |
|
I ♥ BOINC!
Oct 2002
Glendale, AZ. (USA)
3·7·53 Posts |
Thank you for your suggestions and ideas Patrick.
I had to add another line to that hardcoded team mess, on the last line, so that UserNames that don't have Team_UserName will get captured. ![]() Code:
Team_Name = MyArray(1)
arrMyTeamName = Split(Team_Name,"_",-1,1)
if arrMyTeamName(0) = "gd" Then UserName = Team_Name End If
If arrMyTeamName(0) = "Free-DC" Then UserName = arrMyTeamName(1) End If
If arrMyTeamName(0) = "AMDUsers" Then UserName = arrMyTeamName(1) End If
If arrMyTeamName(0) = "ArsTechnica" Then UserName = arrMyTeamName(1) End If
If arrMyTeamName(0) = "XtremeSystems" Then UserName = arrMyTeamName(1) End If
If arrMyTeamName(0) = "Team_Italia" Then UserName = arrMyTeamName(1) End If
If arrMyTeamName(0) = "XGrubbersKickAss" Then UserName = arrMyTeamName(1) End If
If arrMyTeamName(0) = "Ukraine" Then UserName = arrMyTeamName(1) End If
If arrMyTeamName(0) = "Singapura" Then UserName = arrMyTeamName(1) End If
If arrMyTeamName(0) = "RaidersOfTheLostPrime" Then UserName = arrMyTeamName(1) End If
UserName = Team_Name
Then use the arrTeams to see if any match arrMyTeamName(0)? I can't remember the code to easily do that efficiently and cleanly. I'll do a better job of file handling to ensure we don't get input/output file name collisions. I ran a test run with what I have, and it completes over 40,000 lines in under a second, so I'm very pleased with the performance, just trying to be a better programmer and learn some tips and tricks along the way. BTW, this is my FIRST useful vbscript I've written. Thank you again for your time! :cheers: Last fiddled with by IronBits on 2008-11-12 at 08:40 |
|
|
|
|
|
#14 |
|
Jan 2006
JHB, South Africa
157 Posts |
It's only a pleasure IronBits.
I notice that the extra line that you inserted: Code:
UserName = Team_Name 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" 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 |
|
|
|
|
|
#15 |
|
Jun 2003
23·683 Posts |
There is a faster trick than the above hash (only faster in a scripting language)
Code:
C = ",AMDUsers,ArsTechnica,...,XtremeSystems,XGrubbersKickAss,"
If InStr("," & arrMyTeamName(0) & ",", C) > 0 Then
...
End If
|
|
|
|
|
|
#16 |
|
Jan 2006
JHB, South Africa
157 Posts |
|
|
|
|
|
|
#17 |
|
I ♥ BOINC!
Oct 2002
Glendale, AZ. (USA)
3×7×53 Posts |
More hot tips!
![]() Ok, here is what I did in those sections Const C = ",Free-DC,AMDUsers,ArsTechnica,..... if Left(str_CurrentLine,5) = "user=" Then MyArray = Split(str_CurrentLine,"=",-1,1) Team_Name = MyArray(1) UserName = Team_Name arrMyTeamName = Split(Team_Name,"_",-1,1) If InStr("," & arrMyTeamName(0) & ",", C) > 0 Then UserName = arrMyTeamName(1) End If But it doesn't strip the Team_ from UserName |
|
|
|
|
|
#18 |
|
I ♥ BOINC!
Oct 2002
Glendale, AZ. (USA)
3×7×53 Posts |
Ok, so this works
![]() Const strTeams = "",Free-DC,AMDUsers,ArsTechnica,..... if Left(str_CurrentLine,5) = "user=" Then MyArray = Split(str_CurrentLine,"=",-1,1) Team_Name = MyArray(1) arrMyTeamName = Split(Team_Name,"_",-1,1) StringPos = InStr(1, strTeams, arrMyTeamName(0), vbTextCompare) if StringPOS > 0 Then UserName = arrMyTeamName(1) Else UserName = Team_Name End If Maybe one of you can find a cleaner way to achieve the same thing? Last fiddled with by IronBits on 2008-11-12 at 16:17 |
|
|
|
|
|
#19 | |
|
Mar 2006
10001010102 Posts |
Quote:
Code:
If Left(str_CurrentLine,5) = "user=" Then
MyArray = Split(str_CurrentLine,"=",-1,1)
Team_Name = MyArray(1)
If InStr(1, Team_Name, "Team_", 1) > 0 Then
UserName = Right(Team_Name, Len(Team_Name)-5)
Else
UserName = Team_Name
End If
End If
http://www.w3schools.com/VBscript/vb..._functions.asp |
|
|
|
|
![]() |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| vbscript datediff.vbs | IronBits | Programming | 0 | 2008-12-06 09:20 |