Newsgroup: it.comp.lang.visual-basic
Titolo: OCX

Ho un componete che si chiama XINI che crea i file INI! Il mio progetto è
privo di form e quindi volevo creare l'oggetto con CREATEOBJECT ma mi da un
errore! mi dice che nn posso creare l'oggetto! qualcuno sa di +? grazie

 ha scritto nel messaggio
news:mWe67.6174$NZ6.2...@news.infostrada.it...

Se non ricordo male, le specifiche ocx non consentono la creazione degli
oggetti via CreateObject, ma solo attraverso l'inserimento diretto di un
controllo in un form.
Quindi, delle 2 l'una:
1) inserisci un form "invisible" nel tuo progetto e ci metti sopra l'ocx.
2) Lasci perdere il controllo e usi una classe ad hoc o semplicemente del
codice tipo quello sotto:
ciao
ugo
p.s.: modulo bas
Attribute VB_Name = "IniFile"
Option Explicit
Private Const nBuffer = 255
Private Const nSectionBuffer = 2048
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
Private Declare Function GetPrivateProfileSection _
    Lib "kernel32" Alias "GetPrivateProfileSectionA" _
    (ByVal lpAppName As String, _
    ByVal lpReturnedString As String, _
    ByVal nSize As Long, _
    ByVal lpFileName As String) As Long
'*************************************************************
'  FUNCTION: GetIniKeyValue()
'
'     Used to return the value of a key in an .ini file. While you
'     could call alias_GetPrivateProfileString directly it's return
'     value is the number of characters read. It does not return the
'     characters that make up the key value.
'     alias_GetPrivateProfileString fills a buffer that you set
'     aside(lpReturnedString in this example function) with the
'     actual key value. GetIniKeyValue() returns this key value.
'     If you provide an invalid file name, section or key
'     this function returns the default key value.
'
'  ARGUMENTS:
'
'     lpFileName   - the .INI Filename (found in the
'                    Windows directory by default).
'     lpApplicationName  - is the section title that appears in
'                          square brackets in the .INI file.
'     lpKeyName          - The .INI file entry that points to the
'                          key (followed by an equal sign).
'     lpDefault          - Return value when key is not found.    '
'  EXAMPLE:    '
'     To find out the value of the Load= line in the [windows]
'     section of the WIN.INI file type the following into the
'     immediate window.    '
'     ?GetIniKeyValue("c:\windows\win.ini","windows","load","")    '
'*************************************************************
Public Function GetIniKey(lpFileName As String, lpApplicationName As String,
_
    lpKeyName As String, lpDefault As String) As String
    Dim lpReturnedString As String
    Dim CharReturned As Long
    On Error GoTo GetIni_err
    lpReturnedString = Space(nBuffer)
    CharReturned = GetPrivateProfileString(lpApplicationName, _
          lpKeyName, lpDefault, lpReturnedString, nBuffer, lpFileName)
    GetIniKey = lpReturnedString
    Exit Function
GetIni_err:
    MsgBox Error$
    Exit Function
End Function
Public Function GetIniSection(lpFileName As String, lpApplicationName As
String) As String
    Dim lpReturnedString As String
    Dim CharReturned As Long
    On Error GoTo GetIni_err
    lpReturnedString = Space(nSectionBuffer)
    CharReturned = GetPrivateProfileSection(lpApplicationName, _
           lpReturnedString, nSectionBuffer, lpFileName)
    GetIniSection = lpReturnedString
    Exit Function
GetIni_err:
    MsgBox Error$
    Exit Function
End Function
'*************************************************************
'  FUNCTION: WriteIniKeyValue()    '
'     Used to Set the value of a key in an .ini file. You
'     could call alias_WritePrivateProfileString directly.    '
'  ARGUMENTS:    '
'     lpFileName         - the .INI Filename (found in the
'                          Windows directory by default).
'     lpApplicationName  - is the section title that appears in
'                          square brackets in the .INI file.
'     lpKeyName          - The .INI file entry that points to the
'                          key (followed by an equal sign).
'     lpDefault          - Return value when key is not found.    '
'  EXAMPLE:    '
'     To set the value of the load= line in the [windows] section
'     of the WIN.INI file to load=write type the following into
'     the immediate window.    '
'     ?WriteIniKeyValue("c:\windows\win.ini","windows","load",_
'          "write")    '
'*************************************************************
Public Function WriteIniKey(lpFileName As String, lpApplicationName As
String, lpKeyName As String, _
        lpString As String) As Long
    WriteIniKey = WritePrivateProfileString(lpApplicationName, lpKeyName,
lpString, lpFileName)
End Function
Public Function Section2Array(sIniName As String, sSectionName As String) As
Variant
    Dim sReadSection As String
    Dim sTmp As String
    Dim tmpArray() As Variant
    Dim nn, nPos As Integer
    sReadSection = Trim(GetIniSection(sIniName, sSectionName))
    nn = 0
    nPos = InStr(sReadSection, Chr(0))
    Do While True
        sTmp = Left(sReadSection, nPos - 1)
        sReadSection = Mid(sReadSection, nPos + 1)
        If Len(sTmp) > 0 Then
            ReDim Preserve tmpArray(nn)
            tmpArray(nn) = sTmp
        End If
        nn = nn + 1
        nPos = InStr(sReadSection, Chr(0))
        If nPos = 0 Then Exit Do
    Loop
    Section2Array = tmpArray
End Function

Sfido altri a dare risposte cosě esaurienti!!!
Anche se non direttamente interessato devo fare i Complimenti a Ugo e mi
permetto di approfittare di alcune cose.
Alex.
-- 
Posted from [212.141.54.102] 
via Mailgate.ORG Server - 
http://www.Mailgate.ORG

 permetto di approfittare di alcune cose.
:-)
(qual'è l'emoticon di "arrossisco"...?)
Approfitta pure, ma sappi che mi sono limitato a fare un copy-paste di
codice altrui... :-)
ciao
ugo