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!

use browse for file to locate file and import into array

Status
Not open for further replies.

jhardy325

Technical User
Feb 9, 2009
4
Hey Guys-

So I am trying to create a form that requests the user to select a flat text file that has a unique value per line, i.e...
test1
test2
test3
test4
...
test11

I have the select file portion executing properly

SET objCMN = CreateObject("Useraccounts.CommonDialog")
DIM objCMN

objCMN.Filterindex = 1
intResult = objCMN.Showopen
Wscript.echo objCMN.FileName

But when I go to use the objCMN.FileName in a split statement, everything goes wrong.

Please understand that I haven't had to do an scripting for about 9 years, so for all intensive purposes, I am NEW!!

Here is the code I am using to try and split the data into an array

fileName = objDialog.FileName
serverName = SPLIT(objFSO.OpenTextFile(fileName).ReadAll(), vbCrLf,-1,1)

I am know that I am way off on this, but I have tried probably a dozen different things and this is all I have left. Any help would be great!

Thanks!
 
An alternative way to get the file name. (works with XP. To use on Vista you must copy and register safrcdlg.dll from an XP machine)


Code:
'==========================================================================
'
' NAME: fileBrowse.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 9/28/2004
'
' COMMENT: <comment>
'
'==========================================================================

set oFO = CreateObject("SAFRCFileDlg.FileOpen")
' browse to file name thanks to safrcdlg.dll
oFO.OpenFileOpenDlg
' show what the user clicked on.
wscript.echo oFO.FileName

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
So here is my new snipet of code. Still no workie...

Code:
oFO.OpenFileOpenDlg
    wscript.echo oFO.FileName
serverName = SPLIT(objFSO.OpenTextFile(oFO.FileName).ReadAll(), vbCrLf)
    MsgBox join(serverName, vbCrLf)

That code also throws a Type Mismath Error for Line serverName = SPLIT(...)

Thanks!
 
Wow, you are confused on many levels.

Give this a try instead.

Code:
Set oFO = CreateObject("SAFRCFileDlg.FileOpen")
' browse to file name thanks to safrcdlg.dll
oFO.OpenFileOpenDlg

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set oTextStream = objFSO.OpenTextFile(oFO.FileName)
'make an array from the data file
TextArray = Split(oTextStream.ReadAll, vbNewLine)
'close the data file
oTextStream.Close
'Now do something with the data
For Each Line In TextArray
	WScript.Echo Line
Next

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Like I said, it's been a very LONG time...

Anyway, I still have the same issue.

Line: serverName = SPLIT(...)
Char: 5
Error: Type mismatch
Code: 800A000D

I've already declared the array that I need to input the data into (serverName).

Here's my snipet.

Code:
SET oFO = CreateObject("SAFRCFileDlg.FileOpen")
REDIM serverName(serverArraySize)

IF serverCount > 9 THEN
  oFO.OpenFileOpenDlg
  wscript.echo oFO.FileName
  SET oTextStream = objFSO.OpenTextFile(oFO.FileName)
    serverName = SPLIT(oTextStream.ReadAll, vbNewLine)
    oTextStream.Close
    FOR EACH Line IN serverName
        WScript.Echo Line
    NEXT
ELSE

Thanks!
 
I figured it out... I was pre-assigning the array serverName as a dynamic array

Code:
serverName ()

Thank you very much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top