Re: Read info from a file
From: Newbie (nospam_at_noidea.com)
Date: 11/01/04
- Next message: Randy Birch: "Re: Read info from a file"
- Previous message: Newbie: "Re: Read info from a file"
- In reply to: Newbie: "Re: Read info from a file"
- Next in thread: Douglas Marquardt: "Re: Read info from a file"
- Reply: Douglas Marquardt: "Re: Read info from a file"
- Messages sorted by: [ date ] [ thread ]
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
>>> >>
>>> >>
>>> >
>>> >
>>>
>>>
>>
>>
>
>
- Next message: Randy Birch: "Re: Read info from a file"
- Previous message: Newbie: "Re: Read info from a file"
- In reply to: Newbie: "Re: Read info from a file"
- Next in thread: Douglas Marquardt: "Re: Read info from a file"
- Reply: Douglas Marquardt: "Re: Read info from a file"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|