|
-
Jun 12th, 2002, 05:56 AM
#1
INI files in practice
Hi there,
I have downloaded John Percival's "Sample INI program" which is a very nice and clear demo. However there's a point which doesn't make sense to me. Probably it's a beginners question and maybe it does not have anything to do with the specific demo project itself, but as I'm not sure I transcribe below the relevant parts of John code (ok, if you want to run it you'll have to download the project as it contains a few textboxes, etc):
'This part was in a module
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyName As Any, ByVal lsString As Any, ByVal lplFilename As String) As Long
Public Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPriviteProfileIntA" (ByVal lpApplicationname As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
'and this part was on a form
Option Explicit
Private IniFileName As String
Private Sub Form_Load()
IniFileName = InputBox("Which file do you want to read/edit/create?")
If IniFileName = "" Then End
End Sub
Private Sub cmdget_Click()
Dim ret As Long
Dim Temp As String * 50
Dim lpAppName As String, lpKeyName As String, lpDefault As String, lpFileName As String
lpAppName = appname.Text
lpKeyName = Keyname.Text
lpDefault = IniFileName
lpFileName = IniFileName
ret = GetPrivateProfileString(lpAppName, lpKeyName, lpDefault, Temp, Len(Temp), lpFileName)
If ret = 0 Then
Beep
Else
txtvalue.Text = Trim(Temp)
End If
End Sub
Private Sub cmdstore_Click()
Dim lpAppName As String, lpFileName As String, lpKeyName As String, lpString As String
Dim ret As Long
lpAppName = appname.Text
lpKeyName = Keyname.Text
lpString = txtvalue.Text
lpFileName = IniFileName
ret = WritePrivateProfileString(lpAppName, lpKeyName, lpString, lpFileName)
If ret = 0 Then
Beep
End If
End Sub
Now, my question relates to the cmdget_click() subroutine. As you can see the returned value is assigned to a TextBox: txtvalue.text=Trim(Temp)
But if I want to directly assign this returned value to a string variable (in the test ini file I'm using I'm actually reading a string), it turns out that my string variable is not trimmed at all.
I've tried: MyStrVar = Trim(Temp) which returns the string in the file plus a trail of charcters up to the total capacity of the Temp buffer variable.
What am I missing?
Thank you
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|