Login | |
|
 |
hello! problem with code - 5/29/2007 2:41:44 AM
|
|
 |
|
| |
jbauer
Posts: 2
Score: 0
Joined: 5/29/2007
Status: offline
|
I belive there is something wrong with my case selection but i am not sure. I would appreciate any input, as this script is not working at the moment. I am trying to read a ftp log file (.txt) and write any errors to another file to use as a upload template. here is the code i have written. set fso=createobject("scripting.filesystemobject") Set infile=fso.OpenTextFile("c:\logfile_bad.txt", 1) Set out=fso.CreateTextFile("c:\ftpput.txt",true) Do Until infile.AtEndOfStream myrec=infile.readline Select Case infile.readline Case mid(myrec,6,3)="put" If lst_put="" Then lst_put=myrec Else out.writeline mid(lst_put,6) lst_put=myrec End If Case mid(myrec,5,8)="Transfer" myrec="" Case mid(myrec,6,2)="cd" out.writeline mid(myrec,6) End Select loop infile.close() out.close() Set fso=Nothing
|
|
| |
|
|
|
 |
RE: hello! problem with code - 5/29/2007 4:40:38 AM
|
|
 |
|
| |
mcds99
Posts: 434
Score: 4
Joined: 2/28/2006
Status: online
|
So this would be a Case where using Case would not work. Yes it's a week attempt at humor with some education included it's good to have examples of where NOT to use specific code. This way there is a way to compare what works and what doesn't.
_____________________________
Sam Keep it Simple Make it Fun KiSMiF
|
|
| |
|
|
|
 |
RE: hello! problem with code - 5/29/2007 6:09:05 AM
|
|
 |
|
| |
ebgreen
Posts: 5035
Score: 31
Joined: 7/12/2005
Status: online
|
I have not spent a lot of time looking at all of the requirements for the initial question but I wanted to add in one gotcha to watch out for when using Select Case True. This code does one thing: strTest = "This is the test string" If InStr(strTest, "This") > 0 Then 'Code End If If Instr(strTest, "the") > 0 Then 'Code End If If InStr(strTest, "string") > 0 Then 'Code End If This code looks like it might do the same thing but does not: strTest = "This is the test string" Select Case True Case InStr(strTest, "This") > 0 'Code Case InStr(strTest, "test") > 0 'Code Case InStr(strTest, "string") > 0 'Code End Select This If-End If code is what the Select-Case above really does: strTest = "This is the test string" If InStr(strTest, "This") > 0 Then 'Code ElseIf InStr(strTest, "test") > 0 Then 'Code ElseIf InStr(strTest, "string") > 0 Then 'Code End If
< Message edited by ebgreen -- 5/29/2007 6:10:30 AM >
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: hello! problem with code - 5/29/2007 6:26:26 AM
|
|
 |
|
| |
DiGiTAL.SkReAM
Posts: 1184
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
|
Heh. You don't want one. Actually, to be more precise, it is OCPD I live with, but since nobody ever comes across or hears of OCPD, it is usually easier to describe it as OCD.
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers) "It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury
|
|
| |
|
|
|
 |
RE: hello! problem with code - 5/29/2007 6:30:42 AM
|
|
 |
|
| |
DiGiTAL.SkReAM
Posts: 1184
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
|
quote:
ORIGINAL: ebgreen I have not spent a lot of time looking at all of the requirements for the initial question but I wanted to add in one gotcha to watch out for when using Select Case True. This code does one thing: strTest = "This is the test string" If InStr(strTest, "This") > 0 Then 'Code End If If Instr(strTest, "the") > 0 Then 'Code End If If InStr(strTest, "string") > 0 Then 'Code End If This code looks like it might do the same thing but does not: strTest = "This is the test string" Select Case True Case InStr(strTest, "This") > 0 'Code Case InStr(strTest, "test") > 0 'Code Case InStr(strTest, "string") > 0 'Code End Select This If-End If code is what the Select-Case above really does: strTest = "This is the test string" If InStr(strTest, "This") > 0 Then 'Code ElseIf InStr(strTest, "test") > 0 Then 'Code ElseIf InStr(strTest, "string") > 0 Then 'Code End If You are correct, ebgreen, however, in the instance above, i carefully looked at the "cases" that were being tested, and they were: 3 Characters, starting at position 6 8 Characters, starting at position 5 2 Characters, starting at position 6 From what he was testing for ("put", "Transfer", "cd") I was able to determine that in no case would these 'overlap' so to speak, so it would be safe to use Select...Case. But what you say is aboslutely correct, and if there were any overlap - one test shows true for multiple results - then Select Case would not be the proper method to use.
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers) "It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury
|
|
| |
|
|
|
 |
RE: hello! problem with code - 5/29/2007 7:31:23 AM
|
|
 |
|
| |
dm_4ever
Posts: 2663
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
|
quote:
ORIGINAL: DiGiTAL.SkReAM Heh. You don't want one. Actually, to be more precise, it is OCPD I live with, but since nobody ever comes across or hears of OCPD, it is usually easier to describe it as OCD. OCD and OCPD always bring to mind Jack Nicholson in the movie "As Good As It Gets" since he shows symptoms of both.
_____________________________
dm_4ever My philosophy: K.I.S.S - Keep It Simple Stupid Read Me: http://www.visualbasicscript.com/m_24727/tm.htm Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
|
|