Convert VBA to VBS

Posted by dnLL on Stack Overflow See other posts from Stack Overflow or by dnLL
Published on 2012-11-30T14:04:54Z Indexed on 2012/11/30 17:04 UTC
Read the original article Hit count: 181

Filed under:
|
|
|

I have a little VBA script with some functions that I would like to convert to a single VBS file.

Here is an example of what I got:

Private 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

Private Function ReadIniFileString(ByVal Sect As String, ByVal Keyname As String) As String
    Dim Worked As Long
    Dim RetStr As String * 128
    Dim StrSize As Long
    Dim iNoOfCharInIni As Integer
    Dim sIniString, sProfileString As String

    iNoOfCharInIni = 0
    sIniString = ""
    If Sect = "" Or Keyname = "" Then
        MsgBox "Erreur lors de la lecture des paramètres dans " & IniFileName, vbExclamation, "INI"
        Access.Application.Quit
    Else
        sProfileString = ""
        RetStr = Space(128)
        StrSize = Len(RetStr)
        Worked = GetPrivateProfileString(Sect, Keyname, "", RetStr, StrSize, IniFileName)
        If Worked Then
            iNoOfCharInIni = Worked
            sIniString = Left$(RetStr, Worked)
        End If
    End If
    ReadIniFileString = sIniString
End Function

And then, I need to use this function to put some values in strings. VBS doesn't seem to like any of my var declaration ((Dim) MyVar As MyType).

If I'm able to adapt that code to VBS, I should be able to do the rest of my functions too. How can I adapt/convert this to VBS? Thank you.

© Stack Overflow or respective owner

Related posts about vba

Related posts about ms-access