Macro help

S

Search

Hi there ,


I have a text file with 1000 lines.
Each line consist exact 128 characters.

the first 2 characters of each line determines wich code I should use :

for example : 21 means code ....
22 means another code.....

What I try to do is ..... to use a if then function....

If (character [1,2]) = 21 then ......
If (character [1,2]) = 22 then ......
If (character [1,2]) = 23 then ......

I simply search the code for determing the string of each first 2 characters
of each line.

Any Help would be appreciated...



Knd Rgds


Gerry
 
P

Perry

Hi Search,

Here's a simple example:

'read textfile and store in array
Open "c:\temp\128lines.txt" For Input As #1
arrLines = Split(Input(LOF(1), 1), vbCrLf)
Close #1

'loop through the array dimensions
'in search for a qualification of left 2 characters
'in this case, I'm looking for even numbers
For x = 0 To UBound(arrLines)
Select Case Left(arrLines(x), 2) Mod 2
Case 0
Debug.Print Left$(arrLines(x), 2) & " is even"
Case Else
Debug.Print Left$(arrLines(x), 2) & " is not even"
End Select
Next

Krgrds,
Perry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top