hi,
i have mixed a piece of code i found with a simple variable code i made:
and i want to call this part with a button click at my main form:Code:Imports System.Runtime.InteropServices Module inimod Public Class IniFile ' API functions <DllImport("kernel32.dll")> _ Private Shared Function GetPrivateProfileString(ByVal lpApplicationName As String, _ ByVal lpKeyName As String, ByVal lpDefault As String, _ ByVal lpReturnedString As System.Text.StringBuilder, _ ByVal nSize As Integer, ByVal lpFileName As String) _ As Integer End Function <DllImport("kernel32.dll")> _ Private Shared Function WritePrivateProfileString(ByVal lpApplicationName As String, _ ByVal lpKeyName As String, ByVal lpString As String, _ ByVal lpFileName As String) As Integer End Function Private Declare Ansi Function FlushPrivateProfileString Lib "kernel32.dll" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As Integer, ByVal lpKeyName As Integer, ByVal lpString As Integer, ByVal lpFileName As String) As Integer Private _filename As String ' Constructor, accepting a filename Public Sub New(ByVal Filename As String) _filename = Filename End Sub ' Read-only filename property ReadOnly Property FileName() As String Get Return _filename End Get End Property Public Function GetString(ByVal Section As String, _ ByVal Key As String, ByVal [Default] As String) As String ' Returns a string from your INI file Dim intCharCount As Integer Dim objResult As New System.Text.StringBuilder(256) intCharCount = GetPrivateProfileString(Section, Key, [Default], objResult, objResult.Capacity, _filename) If intCharCount > 0 Then GetString = Left(objResult.ToString, intCharCount) Else GetString = "" End If End Function Public Sub WriteString(ByVal Section As String, _ ByVal Key As String, ByVal Value As String) ' Writes a string to your INI file WritePrivateProfileString(Section, Key, Value, _filename) Dim chan1 As String Dim chan2 As String Dim chan3 As String Dim chan4 As String Dim chan5 As String Dim chan6 As String Dim chan7 As String Dim chan8 As String Dim chan9 As String Dim chan10 As String Dim r chan1 = main.memfreq1.Text chan2 = main.memfreq2.Text chan3 = main.memfreq3.Text chan4 = main.memfreq4.Text chan5 = main.memfreq5.Text chan6 = main.memfreq6.Text chan7 = main.memfreq7.Text chan8 = main.memfreq8.Text chan9 = main.memfreq9.Text chan10 = main.memfreq10.Text r = WritePrivateProfileString("RadioLinks", "1", chan1, Application.ExecutablePath & "\test\test.ini") End Sub End Class End Module
but the call procedure and is not working. even when i set:Code:Public Sub WriteString(ByVal Section As String, _ ByVal Key As String, ByVal Value As String) ' Writes a string to your INI file WritePrivateProfileString(Section, Key, Value, _filename) Dim chan1 As String Dim chan2 As String Dim chan3 As String Dim chan4 As String Dim chan5 As String Dim chan6 As String Dim chan7 As String Dim chan8 As String Dim chan9 As String Dim chan10 As String Dim r chan1 = main.memfreq1.Text chan2 = main.memfreq2.Text chan3 = main.memfreq3.Text chan4 = main.memfreq4.Text chan5 = main.memfreq5.Text chan6 = main.memfreq6.Text chan7 = main.memfreq7.Text chan8 = main.memfreq8.Text chan9 = main.memfreq9.Text chan10 = main.memfreq10.Text r = WritePrivateProfileString("RadioLinks", "1", chan1, Application.ExecutablePath & "\test\test.ini") End Sub
.Code:Sub writeproperties() Dim chan1 As String Dim chan2 As String Dim chan3 As String Dim chan4 As String Dim chan5 As String Dim chan6 As String Dim chan7 As String Dim chan8 As String Dim chan9 As String Dim chan10 As String Dim r chan1 = main.memfreq1.Text chan2 = main.memfreq2.Text chan3 = main.memfreq3.Text chan4 = main.memfreq4.Text chan5 = main.memfreq5.Text chan6 = main.memfreq6.Text chan7 = main.memfreq7.Text chan8 = main.memfreq8.Text chan9 = main.memfreq9.Text chan10 = main.memfreq10.Text r = WritePrivateProfileString("RadioLinks", "1", chan1, Application.ExecutablePath & "\test\test.ini") End Sub
i made some stuff on vb6 a few years and im not a regular coder, i have a book for api functions but is regarding vb6 and vb8 seems diferent...
How can i write on my ini through the click of the main form button calling the function in the module?
Thanks:
Duarte V.




Reply With Quote
