pet wrote:
> er der en der har en løsning på en opgave. det er at jeg kan åbne en fil men
> hvordant får jeg de data filen inholder til at blive til variable istedet
> for text jeg åbner den son liner i en string data fra filen ser således ud
>
> [weather_tendency]
> comment_1 = "-1=not valid, 0=no change of air pressure"
> comment_2 = " 1=air pressure rising, 2=air pressure falling"
> number = 1
>
> [indoor_temperature]
> deg_C = "22.8"
> deg_F = "73.0"
>
> [outdoor_temperature]
> deg_C = "17.8"
> deg_F = "64.0"
>
> [indoor_humidity]
> percent = "51"
>
> [outdoor_humidity]
> percent = "73"
>
> [dewpoint]
> deg_C = "12.9"
> deg_F = "55.2"
Betragt filen som en 'ini'-fil, så er det meget let.
Den nødvendige kode er her, du må selv flette den ind i dit projekt
(eller vende tilbage)
Option Explicit
'©2007 Gert Krabsen
' Ini-filer
Dim IniFileName As String
Declare Function GetPrivateProfileString Lib "Kernel32.dll" Alias
"GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal
lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As
String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Declare Function WritePrivateProfileString Lib "Kernel32.dll" Alias
"WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal
lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Declare Function GetWindowsDirectory Lib "Kernel32.dll" Alias
"GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long)
As Long
Sub InitProfile(IniFile As String, WinDir As Integer)
Const BufLen = 256
Dim iret As Integer
Dim Buf As String * BufLen
If WinDir Then
iret = GetWindowsDirectory(Buf, BufLen)
If iret > 0 Then
IniFileName = Trim$(Left(Buf, iret)) & "\" & IniFile
End If
Else
IniFileName = IniFile
End If
End Sub
Function ReadProfile(Section As String, Entry As String, Default As
String) As String
Const BUF_LEN = 80
Dim Buf As String * BUF_LEN
Dim ReturnLen As Integer
If IniFileName <> "" Then
ReturnLen = GetPrivateProfileString(Section, Entry, Default,
Buf, BUF_LEN, IniFileName)
If ReturnLen <> 0 Then
ReadProfile = Trim$(Left(Buf, ReturnLen))
End If
End If
End Function
Function WriteProfile(Section As String, Entry As String, Value As
String) As Integer
If IniFileName <> "" Then
WriteProfile = WritePrivateProfileString(Section, Entry, Value,
IniFileName)
End If
End Function
Filen initieres med
Global iniFilNavn As String
iniFilNavn = brugerSti & "\weather.txt"
InitProfile iniFilNavn, False
Hent oplysning med
ReadProfile(sektionsnavn, linienavn, default værdi)
eks:
ReadProfile("[indoor_temperature]", "deg_C" , 10)
Gem med
DIM svar
dim talVærdi as long
talVærdi=9.9
svar = WriteProfile(sektionsnavn, linienavn, Værdi)
eks: svar = WriteProfile("[indoor_temperature]", "deg_C", talVærdi)