Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Read In A Flat File
Message
General information
Forum:
Visual Basic
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00568718
Message ID:
00570138
Views:
13
Hi!

To demo how to read/write values in INI file (that mentioned Alexander Golovlev):
Private Declare Function GetPrivateProfileString Lib "kernel32.dll" Alias "GetPrivateProfileStringA" _
   (ByVal lpAppName As String, _
   ByVal lpKeyName As String, _
   ByVal lpDefault As String, _
   ByVal lpReturnedString As String, _
   ByVal nSize As Long, _
   ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32.dll" Alias "WritePrivateProfileStringA" _
   (ByVal lpAppName As String, _
   ByVal lpKeyName As String, _
   ByVal lpString As String, _
   ByVal lpFileName As String) As Long

Private Function GetValueFromINI(ByVal strINIFileName, _
    ByVal strName As String, ByVal strDefaultValue As String, _
    Optional ByVal strSection As String = "MAIN") As String
   
' return string from the INI file "VBCOM" section
  Dim lpstr As String, Result As Integer
  lpstr = Space(10000)
  Result = GetPrivateProfileString(strSection, strName, strDefaultValue, lpstr, 5000, strINIFileName)
  Result = InStr(1, lpstr, Chr(0), vbBinaryCompare)
  If Result <> 0 Then lpstr = Left(lpstr, Result - 1)
  GetValueFromINI = lpstr
End Function

Private Sub WriteValueToINI(ByVal strINIFileName, _
    ByVal strName As String, ByVal strString As String, _
    Optional ByVal strSection As String = "MAIN")
  WritePrivateProfileString strSection, strName, strString, strINIFileName
End Sub
HTH.


>I'm trying to read in an INI file. I have:
>
>Open "c:\myfile.ini" For Input As #1
>
>While Not EOF(1)
>
>  Get #1, , sString
>
>  ' Other commands go here
>
>Wend
>

>
>
>I get a 'Bad File Mode' error on the GET line. Can anyone help
>please?
>
>Thanks
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.com
ICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs

It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.
Previous
Reply
Map
View

Click here to load this message in the networking platform