473,386 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Select Case Assistance Requested

Please see my pseudocode below. I'm attempting to read a text file and find specific text in each string of text that is read. When a string of text is read that has the specific text I'm looking for the Case Statement will not evaluate to True. Is what I am doing possible with the Case Statement? Any Help will be appreciated.

dim strL as String

While not tso.eof

strL = tso.readline

Select Case strL

Case Left(strL, 8) = "someText"
do someting
Case Left(strL, 13) = "someOtherText"
do something

End Select

Loop
Apr 6 '10 #1
2 1932
Delerna
1,134 Expert 1GB
Case is meant for deciding an action based on the value of a single expreression
Expand|Select|Wrap|Line Numbers
  1. select case Left(strL, 8)
  2.    case "someText"
  3.       dosomething
  4.    case "someOthe"
  5.       dosomethingelse
  6. End select
  7.  
Since you need to select different length strings then that won't work


You will need to use if elseif which allows different expressions for each test
Expand|Select|Wrap|Line Numbers
  1. If Left(strL, 8) = "someText" Then
  2.     MsgBox "someText"
  3. ElseIf Left(strL, 13) = "someOtherText" Then
  4.     MsgBox "someOtherText"
  5. End If
  6.  
Apr 6 '10 #2
ADezii
8,834 Expert 8TB
Select Case is not being used in the proper context since you are not specifically analyzing the entire Line, namely strL. The following compact code segment will do the trick for you:
Expand|Select|Wrap|Line Numbers
  1. 'Must first set a Refernce to the Microsoft Scripting Runtime Library
  2. Dim fso As FileSystemObject
  3. Dim fil As File
  4. Dim strL As String
  5. Dim tso As TextStream
  6.  
  7. Set fso = New FileSystemObject
  8.  
  9. 'Open the File for Reading
  10. Set fil = fso.GetFile("C:\Windows\Setuplog.txt")
  11. Set tso = fil.OpenAsTextStream(ForReading)
  12.  
  13. Do While Not tso.AtEndOfStream
  14.   strL = tso.ReadLine
  15.     If Left$(strL, 8) = "sometext" Then
  16.       'YaDa, YaDa
  17.     ElseIf Left(strL, 13) = "someOtherText" Then
  18.       'More YaDa, YaDa
  19.     Else
  20.     End If
  21. Loop
Apr 6 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Ron Lounsbury | last post by:
I have a customer who has requested that I add "popup" text (a la ToolTips) to a couple of pulldown lists in a DHTML form we have in our project. He says - Just use the ALT tag. I went and double...
1
by: RF Rohrer | last post by:
I am seeking assistance in the development of a J/S script that will, on OnClick browser action cause another, external piece of HTML code to be displayed near where the mouse was when OnClick was...
2
by: Kenny G | last post by:
I would like some assistance on writing a procedure. I have a StartDate and an EndDate. If the EndDate is less than the StartDate then I need to undo the input in the EndDate, let the user know...
8
by: Daniel Antonson | last post by:
Fellow programmers, As one of you pointed out, I've been taking 3 online courses (2 are done) and have run into a time crunch. I started these courses in Oct04, but between work (US Army in...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
4
by: pike | last post by:
DB2 UDB 8.1 FP7 We are getting intermittent deadlocks (911 RC 2) even when U row-lock has been secured. The transaction is as follows: 1) Select current application number value from table....
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
3
by: emalcolm_FLA | last post by:
Hello and Thanks in advance for any help. I have been tasked with rewriting a christmas assistance database using Access 2003. The old system used pre-assigned case numbers to identify...
2
by: csolomon | last post by:
Hello: I am creating a form that will calculate a value based on the value selected from a case statement in a function. The function I created is called GetYield and accepts 3 arguments. I...
7
by: SteveGod | last post by:
Hi, I'm trying to create a report that will produce automated sets of Committee Minutes for School Appeals, where there are a set range of different outcomes. The field involved are all from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.