Re: Read info from a file

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Newbie (nospam_at_noidea.com)
Date: 11/01/04


Date: Mon, 1 Nov 2004 15:27:52 -0000

I have used the following - is this the best way to do it or would you
recommend some other way . ..

Dim fnum As Integer, isopen As Boolean
Dim strLgth As Long

On Error GoTo Error_Handler
fnum = FreeFile()
Open filename For Input As #fnum
isopen = True
Do While Not EOF(fnum) ' Loop until end of file.
   Line Input #1, strSQLSVR ' Read line into variable.
   Debug.Print strSQLSVR ' Print to the Immediate window.
    If Left(strSQLSVR, 6) = "SQLSVR" Then
     strLgth = Len(strSQLSVR)
        strSQLSVR = Mid(strSQLSVR, 8, strLgth - 7)
    Debug.Print strSQLSVR
    End If
Loop
Close #1 ' Close file.
"Newbie" <nospam@noidea.com> wrote in message
news:uOIatLCwEHA.2804@TK2MSFTNGP14.phx.gbl...
>I have tried to download the sample that you told me but it doesn't work or
>rather wont open on my machine.
>
> Any other samples
>
> Thanks
> "Douglas Marquardt" <no_spam@dummy.com> wrote in message
> news:OAg%23NJCwEHA.1988@TK2MSFTNGP12.phx.gbl...
>> Hi:
>>
>> If you want to go the ini route, then have a look at the sample I
>> suggested.
>> (which should work just fine for what you want).
>>
>> If you want to use the registry, then have a look in the vb docs under
>> "GetSetting" and "SaveSetting"
>>
>> Doug.
>>
>>
>> "Newbie" <nospam@noidea.com> wrote in message
>> news:uLFC26BwEHA.4048@TK2MSFTNGP15.phx.gbl...
>>> Thanks
>>>
>>> Yes I am using ADO to connect to the db and the only part of the
>>> connection
>>> string I wanted to read from the file was the Initial Catalog and the
>>> Data
>>> Source as these can change.
>>>
>>> Any ideas how I do this?
>>> "Douglas Marquardt" <no_spam@dummy.com> wrote in message
>>> news:%23Vh8g0BwEHA.4028@TK2MSFTNGP15.phx.gbl...
>>> > Hi:
>>> >
>>> > For reading ini files, have a look at the KPINI.ZIP file located at:
>>> >
>>> > http://www.mvps.org/vb/index2.html?samples.htm
>>> >
>>> > I wouldn't recommend storing the connect strings in a file,
>>> > unless you're not worried about db security.
>>> >
>>> > Are you using ADO to connect to the db?
>>> > If so, then you could use the built in login for the provider,i.e.
>>> >
>>> > Dim cn As ADODB.Connection
>>> >
>>> > On Error GoTo EH
>>> >
>>> > Set cn = New ADODB.Connection
>>> > cn.Provider = "SQLOLEDB"
>>> > cn.Properties("Prompt").Value = adPromptAlways
>>> > cn.Open
>>> >
>>> > ...etc
>>> >
>>> > Done:
>>> > 'Clean up here, i.e. close the connection, etc.
>>> > Exit Sub
>>> > EH:
>>> > Select Case Err.Number And Not vbObjectError
>>> > Case 3662 'Open method was cancelled by the user
>>> > ..etc
>>> > Case Else
>>> > MsgBox Err.Description
>>> > End Select
>>> > Resume Done
>>> >
>>> > Note: the above code was off the top of my head and may
>>> > not be 100% correct --- but you get the idea.
>>> >
>>> > Hope this helps,
>>> >
>>> > Doug.
>>> >
>>> >
>>> > "Newbie" <nospam@noidea.com> wrote in message
>>> > news:eF1IzgBwEHA.3276@TK2MSFTNGP15.phx.gbl...
>>> >> Hi,
>>> >>
>>> >> I have a project that is going to connect to a SQL Server.
>>> >>
>>> >> At the moment whenever I have to try out the .exe I have to rewrite
>>> >> the
>>> >> connection string so that it looks at the correct SQL Server and
>>> >> Database
>>> >> name.
>>> >>
>>> >> Is it possible to have these settings in a for eg .ini file and have
>>> >> the
>>> >> program read the entries from here.
>>> >>
>>> >> If yes what would be the best way to go about this and how would I
>>> >> read
>>> >> from
>>> >> a .ini file?
>>> >>
>>> >> Thanks
>>> >>
>>> >>
>>> >
>>> >
>>>
>>>
>>
>>
>
>



Relevant Pages

  • Re: Read info from a file
    ... > Dim fnum As Integer, ... > Open filename For Input As #fnum ... > Do While Not EOF' Loop until end of file. ... > Debug.Print strSQLSVR ' Print to the Immediate window. ...
    (microsoft.public.vb.syntax)
  • Re: Challenging?
    ... Dim FNum As Integer ... Microsoft MVP - Excel ... Team\SE Airports TSA Team ...
    (microsoft.public.excel.programming)
  • Re: Reading Files Byte-For-Byte
    ... > A bit confusing here. ... > Dim fnum as long ... > Also a bit confused about reading non-text data into a text file? ...
    (microsoft.public.vb.general.discussion)
  • Re: Chip Pearson Import/Export Macros - Added Twist
    ... Dim FNum As Integer ... Dim Rng As Range ... > I need to modify it to reflect a specila twist so that another program can> read it, and that is I want the macro to export all cell values as text, but> put each cell value in one column only i.e. in destination file. ...
    (microsoft.public.excel.programming)
  • Maybe Im going blind
    ... > If the size of the string to replace stays the same as the string to find ... > Dim FNum As Integer ... > Open FileName For Binary As #FNum ... > search string falls across segment boundaries. ...
    (microsoft.public.vb.general.discussion)