Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

.INI File Questions

Okay, I need help - I'm making a program, where the title bar will say:


UNREGISTERED VERSION


And I want to include an option where you enter in a serial number and it says


REGISTERED TO: Your Name Here


And I want to do it with INI files. If anyone could give me source code for this, I would be forever greatful =) I've tried everything and cannot get it to work.


I'm using Visual Basic Standard Editon 4.0


Comments

  • 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


    lpApplicationName - The word in [ ]'s

    lpKeyName - The word proceeding "="

    lpDefault - Return if the value doesn't exist

    lpReturnedString* - Variable that will store value

    nSize - Length of lpReturnedString

    lpString - String value to write to file

    lpFileName - Name of ini file.*


    Example:


    MyApp.ini file:


    [RegInfo]

    SerialNum=123456


    Code:


    Settings = String(255, 0)

    RetVal = GetPrivateProfileString("RegInfo", "SerialNum", "", Settings, Len(Settings), "MyApp.ini")

    SerialNum = Val(Left$(Settings, RetVal))


    --SerialNum should now contain the numeric value 12345.--*


    RetVal = WritePrivateProfileString("RegInfo", "SerialNum", CStr(SerialNum), "MyApp.ini")




    *lpReturnString must be long enough to contain the returned string.


    *To specify the Win.ini file, you can use GetProfileString and WriteProfileString, instead. The only difference is these two don't allow you to specify the ini file.


    *GetPrivateProfileInt and WritePrivateProfileInt can be used to write and return numeric values, but I prefer to convert manually.


    Hope this helps!


  • One more question, how do I make the program read the INI file contents on startup and change UNREGISTERED to REGISTERED in my TitleBar? Thanks again.... i hope you didn't already cover this...


    RemiX


    : 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


    : lpApplicationName - The word in [ ]'s

    : lpKeyName - The word proceeding "="

    : lpDefault - Return if the value doesn't exist

    : lpReturnedString* - Variable that will store value

    : nSize - Length of lpReturnedString

    : lpString - String value to write to file

    : lpFileName - Name of ini file.*


    : Example:


    : MyApp.ini file:


    : [RegInfo]

    : SerialNum=123456


    : Code:


    : Settings = String(255, 0)

    : RetVal = GetPrivateProfileString("RegInfo", "SerialNum", "", Settings, Len(Settings), "MyApp.ini")

    : SerialNum = Val(Left$(Settings, RetVal))


    : --SerialNum should now contain the numeric value 12345.--*


    : RetVal = WritePrivateProfileString("RegInfo", "SerialNum", CStr(SerialNum), "MyApp.ini")


    :

    : *lpReturnString must be long enough to contain the returned string.


    : *To specify the Win.ini file, you can use GetProfileString and WriteProfileString, instead. The only difference is these two don't allow you to specify the ini file.


    : *GetPrivateProfileInt and WritePrivateProfileInt can be used to write and return numeric values, but I prefer to convert manually.


    : Hope this helps!





  • Sub Form_Load()


    'Use provided code and examples to check if the app is registered.

    'If app is registered(if the return value is valid), then


    Me.Caption = "REGISTERED"


    'otherwise


    Me.Caption = "UNREGISTERED"


    End Sub


  • Shawn CarterShawn Carter Member Posts: 0

    / http://forcoder.org / free ebooks and video tutorials about \ Perl PL/SQL Ruby Assembly Scratch C# MATLAB C R C++ PHP Python Go Visual Basic JavaScript Visual Basic .NET Swift Objective-C Java Delphi Bash Lisp Scala Kotlin Alice Rust D Dart Apex LabVIEW Erlang ML SAS Logo COBOL Fortran F# Crystal Scheme Julia Lua ABAP Ada Prolog VBScript Hack Transact-SQL FoxPro Awk Clojure \

Sign In or Register to comment.