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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with array

Status
Not open for further replies.

Agentsix1

Programmer
Jan 13, 2012
1
US
so i want to load a file and send it to an array and then send a if then statment

do until i have no idea what to put here if you can help me please that would be awsome
loads file (i dont know how to do this)
builds array
sends if then statment
if array(i) = "something" Then
DO SOmething
else

end if
loop


im loading a file of names from a text file i know how to save the file and stuff so i just need this bit then im good thank you for help ahead of time


PS im a noob when it comes to coding so the shorter the code the better lol
 
Somthing like this should get you going:
Code:
Option Explicit
Const ForReading = 1
Dim sFilename
sFilename = "C:\MyFile.txt"

Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(sFilename, ForReading)

Dim sAllLines, arrAllLines, sLine
sAllLines = f.ReadAll
arrAllLines = Split(sAllLines, vbCrLf)
For Each sLine in arrAllLines 
   If sLine = "something"
      'Do something
   Else
      'Do something else
   End If
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top