Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Case, reading lines in a document 1

Status
Not open for further replies.

pds

Programmer
Jul 2, 2001
9
US
I'm reading lines in a text file and using the values. I am reading one value on one line, and two values on another line. I'm a little confused on how the code should look.


Should it look like this?
------------------------------------------------------------
Select Case LineNumber
Case 31
value1 = Mid(LineString, 72, 7)
var1 = CSng(value1)
Case 54
value2 = Mid(LineString, 111, 6)
var2 = CSng(value2)
Case 54
value3 = Mid(LineString, 127, 5)
var3 = CSng(value3)
End Select
------------------------------------------------------------


Or is it this?
------------------------------------------------------------
Select Case LineNumber
Case 31
value1 = Mid(LineString, 72, 7)
var1 = CSng(value1)
Case 54
value2 = Mid(LineString, 111, 6)
var2 = CSng(value2)

'the 2nd Case 54 is removed

value3 = Mid(LineString, 127, 5)
var3 = CSng(value3)
End Select
------------------------------------------------------------

Thanks.

pds



 
Either way works. But the first has a redundant line (the third case statement), so the second way is the preferred method.

Herman :-Q
 
Only the second method will work. In the first method, only the first Case 54 would be evaluated, because it would drop out after finding the first match.
 
Herman is right in the sense that both will run, but as far as your value3 and var3 assignments, only the second method will assign values.
 
Thanks for your help, guys!

pds
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top