/ Forside / Teknologi / Udvikling / VB/Basic / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
VB/Basic
#NavnPoint
berpox 2425
pete 1435
CADmageren 1251
gibson 1230
Phylock 887
gandalf 836
AntonV 790
strarup 750
Benjamin... 700
10  tom.kise 610
Skrive til en ini-fil <-> Fatter gejl =)
Fra : Søren Aaholm Møller


Dato : 19-07-01 17:16

Hej - jeg har fået følgende modul :

Declare Function GetPrivateProfileString Lib "kernel32" 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" Alias
"WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal
lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long


Function GetString(strSection As String, strEntry As String, strStdStreng As
String, bytValueSpace As Byte, Optional strinifil As String = "") As String
'Get a string from ini-file
Dim strTemp As String ' Temporary String
Dim lngBytesHentet As Long ' How many bytes was recieved by the API call
Dim strEntryValue As String
strTemp = Space(bytValueSpace)
lngBytesHentet = GetPrivateProfileString(strSection, strEntry,
strStdStreng, strTemp, Len(strTemp), strinifil)
strEntryValue = Left(strTemp, lngBytesHentet)
GetString = IIf(strEntryValue = "", strStdStreng, strEntryValue)
End Function
Sub WriteString(strSection As String, strEntry As String, strValue As
String, Optional strinifil As String = "")
'Write a string to ini-file
WritePrivateProfileString strSection, strEntry, strValue, strinifil
End Sub

- - -

Men fatter minus af hvordan jeg skal behandle kommandoen GetString og
WriteString som den gerne vil have at jeg gøre =)

Hvordan klarer jeg lige den?

Må godt skæres lidt ud i pap, da jeg er rimelig ny i vb =)

// Søren



 
 
Knut Nordal (20-07-2001)
Kommentar
Fra : Knut Nordal


Dato : 20-07-01 13:56

Hei

sender over utklipp over en inifunksjon som jeg har notert
INI EKSEMPEL

Form Load
iniPath$ = App.Path + "\Ini.ini"

'Leser ini-fil
Text1.Text = GetFromINI("Info1", "1", iniPath$) 'Text 1
Text2.Text = GetFromINI("Info1", "2", iniPath$) 'Text 2
Text3.Text = GetFromINI("Info2", "1", iniPath$) 'Text 3
Text4.Text = GetFromINI("Info2", "2", iniPath$) 'Text 4

Form Unload
'Skriver info til ini-fil
'Øker entry(x)$ med 1 nummer for hver kobling
entry1$ = Text1.Text 'Text 1
entry2$ = text2.Text 'Text 2
entry3$ = Text3.Text 'Text 3
entry4$ = Text4.Text 'Text 4

r% = WritePrivateProfileString("Info1", "1", entry1$, iniPath$) 'Text 1
r% = WritePrivateProfileString("Info1", "2", entry2$, iniPath$) 'Text 2
r% = WritePrivateProfileString("Info2", "1", entry3$, iniPath$) 'Text 3
r% = WritePrivateProfileString("Info2", "2", entry4$, iniPath$) 'Text 4

If r% <> 1 Then MsgBox "En feil oppstod ved skriving til fil"

Modul
'32 Bit API Declarations
Declare Function GetPrivateProfileString Lib "Kernel32" Alias
"GetPrivateProfileStringA" (ByVal lpApplicationName As String, lpKeyName As
Any, ByVal lpDefault As String, ByVal lpRetunedString As String, ByVal nSize
As Long, ByVal lpFileName As String) As Long
Declare Function WritePrivateProfileString Lib "Kernel32" Alias
"WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal
lpKeyName As Any, ByVal lpString As Any, ByVal lplFileName As String) As
Long

'Variable Declarations
Global r% 'Result Code from WritePrivateProfileString

'Øker Global entry(x)$ med 1 nummer for hver kobling
Global entry1$ 'Passed to WritePrivateProfileString
Global entry2$ 'Passed to WritePrivateProfileString
Global entry3$ 'Passed to WritePrivateProfileString
Global entry4$ 'Passed to WritePrivateProfileString

Global iniPath$ 'Path to .ini file

Modul "Funksjon"
Function GetFromINI(AppName$, KeyName$, FileName$) As String
Dim RetStr As String
RetStr = String(255, Chr(0))
GetFromINI = Left(RetStr, GetPrivateProfileString(AppName$, ByVal
KeyName$, "", RetStr, Len(RetStr), FileName$))
End Function

sender over en skrevet i word som er lettere å tyde

MVH Knut Nordal


"Søren Aaholm Møller" <swdata@image.dk> skrev i melding
news:OKD57.2527$oH6.233165@news010.worldonline.dk...
> Hej - jeg har fået følgende modul :
>
> Declare Function GetPrivateProfileString Lib "kernel32" 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" Alias
> "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal
> lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As
Long
>
>
> Function GetString(strSection As String, strEntry As String, strStdStreng
As
> String, bytValueSpace As Byte, Optional strinifil As String = "") As
String
> 'Get a string from ini-file
> Dim strTemp As String ' Temporary String
> Dim lngBytesHentet As Long ' How many bytes was recieved by the API call
> Dim strEntryValue As String
> strTemp = Space(bytValueSpace)
> lngBytesHentet = GetPrivateProfileString(strSection, strEntry,
> strStdStreng, strTemp, Len(strTemp), strinifil)
> strEntryValue = Left(strTemp, lngBytesHentet)
> GetString = IIf(strEntryValue = "", strStdStreng, strEntryValue)
> End Function
> Sub WriteString(strSection As String, strEntry As String, strValue As
> String, Optional strinifil As String = "")
> 'Write a string to ini-file
> WritePrivateProfileString strSection, strEntry, strValue, strinifil
> End Sub
>
> - - -
>
> Men fatter minus af hvordan jeg skal behandle kommandoen GetString og
> WriteString som den gerne vil have at jeg gøre =)
>
> Hvordan klarer jeg lige den?
>
> Må godt skæres lidt ud i pap, da jeg er rimelig ny i vb =)
>
> // Søren
>
>



Søg
Reklame
Statistik
Spørgsmål : 177558
Tips : 31968
Nyheder : 719565
Indlæg : 6408929
Brugere : 218888

Månedens bedste
Årets bedste
Sidste års bedste