Using input to read files

I am using input to read an ini file.  
Open "C:\test.ini" for input as #1

My ini file has a line that has comma's in it.  It seems that when using the input it is using the comma's to as delimiters.  Is there a way to turn this off.  I need it to read the whole line and ignore comma's.  Thanks
Who is Participating?
kamallConnect With a Mentor Commented:
Oh...., you got it to work... thats great.
Thanks for your comment anyway.
    Line Input #1, MyString

This will read an entire line from the file. Then you can check for the comma's in the string using the InStr function, to find if any comma's exist and at what character positions.
Hope that helps.

strongdAuthor Commented:
This works for 1 variable but I am reading in over 20 variables into VB.   How do I sparate them.  I tried using commas but I keep gettting an error.  

Line Input #1, MyString, Mystring2, mystring3, mystring4, mystring5, mystring6,.....etc...
This will not work.   What do I use to sparate them??

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Minor Point first

when declaring the file to open do not hard code the file number use a proxy
ie Dim intFreeFile as integer

open myDoc for input as intFreeFile

Use Kamall's code to input the line into a string variable

then as he suggests break up the line using instr() and read in into an array

As a Starter here's some code to help

dim MyString() as string
dim intPos as integer
dim intOldPos as integer
dim intCounter as integer
dim intNewPos as integer
lets assume we've got to the line with commas we can check for this by looking at each line inputted  with:

If instr(strInputLine,",")>0 then
intOldPos = 1
intPos = 1
intNewPos = 1
intPos = InStr(strInputLine, ",")
intCounter = 1
If intPos > 1 Then
    ReDim MyString(intCounter)
    MyString(intCounter - 1) = Mid(strInputLine, intNewPos, intPos - 1)
    intNewPos = intPos + 1
    Do While intPos > 0
        intPos = InStr(intNewPos, strInputLine, ",")
        If intPos > 0 Then
            intCounter = intCounter + 1
            ReDim Preserve MyString(intCounter)
            MyString(intCounter - 1) = Mid(strInputLine, intNewPos, intPos - intNewPos)
            intNewPos = intPos + 1
            intCounter = intCounter + 1
            ReDim Preserve MyString(intCounter)
            MyString(intCounter - 1) = Mid(strInputLine, intNewPos)
        End If
End If

Once you have got your array then you can assign the values as you wish:

ie  MyVar1=Mystring(7)
    MyVar2=MyString(4) etc
strongdAuthor Commented:
Thats sucks!   I have to do all this just so it will put the commas with the string...  I hate Microsoft.   Line input can only read one variible at a time is really really lame.  
I'll try it.   But I am thinking about read the ini file in as a binary file.   Thanks for your help.
strongdAuthor Commented:
I got it to work.

Open "C:\test.ini" for input as #1
Input #1, mystring, mystring2, mystring3, mystring4
Line Input #1, Mystring5        ' line with comma's
Input #1, mystring6, mystring7, mystring8.....etc.....

This worked great!  Kamall, answer this again and i'll give you the points.  Thanks

strongdAuthor Commented:
You are welcome.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.