Results 1 to 5 of 5

Thread: Need some help regarding .ini

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    3

    Need some help regarding .ini

    Using Visual Basics 2008

    Ok.
    I've started on a little project for an online game.

    Basically I want the user to enter what drive their game is installed on "C:\, D:\, Etc..."

    Once they type in what drive they are using, they click a save button.
    The save button, then adds what drive they are using to a .ini file.

    The contents of the .ini file look like:
    Code:
    [Settings]
    Drive=C

    So far I've gotten the above steps done.
    Now what I'm trying to accomplish is the following.

    After they have saved what drive the game is installed on.
    They will then click a start button.

    The program will then try and find files located in the game's installation folder using the information in the .ini file.

    Is this possible?
    Is there any easier way?

    Here is the code I currently have:
    Code:
    Imports System.IO
    
    Public Class Form1
    
        Public Class IniFile
            ' API functions
            Private Declare Ansi Function GetPrivateProfileString _
              Lib "kernel32.dll" Alias "GetPrivateProfileStringA" _
              (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
            Private Declare Ansi Function WritePrivateProfileString _
              Lib "kernel32.dll" Alias "WritePrivateProfileStringA" _
              (ByVal lpApplicationName As String, _
              ByVal lpKeyName As String, ByVal lpString As String, _
              ByVal lpFileName As String) As Integer
            Private Declare Ansi Function GetPrivateProfileInt _
              Lib "kernel32.dll" Alias "GetPrivateProfileIntA" _
              (ByVal lpApplicationName As String, _
              ByVal lpKeyName As String, ByVal nDefault As Integer, _
              ByVal lpFileName As String) As Integer
            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
            Dim strFilename As String
    
            ' Constructor, accepting a filename
            Public Sub New(ByVal Filename As String)
                strFilename = Filename
            End Sub
    
            ' Read-only filename property
            ReadOnly Property FileName() As String
                Get
                    Return strFilename
                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, strFilename)
    
            End Function
    
            Public Function GetInteger(ByVal Section As String, _
              ByVal Key As String, ByVal [Default] As Integer) As Integer
                ' Returns an integer from your INI file
                Return GetPrivateProfileInt(Section, Key, _
                   [Default], strFilename)
            End Function
    
            Public Function GetBoolean(ByVal Section As String, _
              ByVal Key As String, ByVal [Default] As Boolean) As Boolean
                ' Returns a boolean from your INI file
                Return (GetPrivateProfileInt(Section, Key, _
                   CInt([Default]), strFilename) = 1)
            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, strFilename)
                Flush()
            End Sub
    
            Public Sub WriteInteger(ByVal Section As String, _
              ByVal Key As String, ByVal Value As Integer)
                ' Writes an integer to your INI file
                WriteString(Section, Key, CStr(Value))
                Flush()
            End Sub
    
            Public Sub WriteBoolean(ByVal Section As String, _
              ByVal Key As String, ByVal Value As Boolean)
                ' Writes a boolean to your INI file
                WriteString(Section, Key, CStr(CInt(Value)))
                Flush()
            End Sub
    
            Private Sub Flush()
                ' Stores all the cached changes to your INI file
                FlushPrivateProfileString(0, 0, 0, strFilename)
            End Sub
    
        End Class
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim objIniFile As New IniFile("c:\nexon2\data.ini")
            objIniFile.WriteString("Settings", "Drive", TextBox1.Text)
            Dim strData As String = _
                objIniFile.GetString("Settings", "Drive", "(none)")
            MsgBox(objIniFile.GetString("Settings", "Drive", "C:\"))
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim objIniFile As New IniFile("c:\nexon2\data.ini")
            Dim strData As String = _
               objIniFile.GetString("Settings", "Drive", "(none)")
            TextBox2.Text = objIniFile.GetString("Settings", "Drive", "*")
    
    
    
    
        End Sub
    End Class
    I'm not a very good coder, and I mainly copy and paste codes and edit them accordingly. lol


    Any help is appreciated.
    Thanks in advance,
    I'm just a noob.

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Need some help regarding .ini

    Welcome to the Forum

    Yes, you can do that with an INI.

    However, you can use the app to identify where it is installed using: Application.StartupPath

    As a side note, you can use the applications Settings to store user data too, just do a search for: My.Settings

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    3

    Re: Need some help regarding .ini

    Quote Originally Posted by Bruce Fox
    Welcome to the Forum

    Yes, you can do that with an INI.

    However, you can use the app to identify where it is installed using: Application.StartupPath

    As a side note, you can use the applications Settings to store user data too, just do a search for: My.Settings
    Thanks for the reply!
    Can I can an example how I'd relate this to what I'm trying to do.

  4. #4
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Need some help regarding .ini

    The program will then try and find files located in the game's installation folder
    Use: Application.StartupPath

    That will return the path where the application exe resides, from that you can use it reference. For example it may be something like:
    C:/Program Files/JustANoob (if the exe is in this folder)

    Eg. If you had a sound file installed in the same folder as the exe, then you can use Application.StartupPath plus the filename to play the sound like:

    Dim sound As New Sound(Application.StartupPath & "/mysoundfile.wav"
    sound.Play()

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    3

    Re: Need some help regarding .ini

    Quote Originally Posted by Bruce Fox
    Use: Application.StartupPath

    That will return the path where the application exe resides, from that you can use it reference. For example it may be something like:
    C:/Program Files/JustANoob (if the exe is in this folder)

    Eg. If you had a sound file installed in the same folder as the exe, then you can use Application.StartupPath plus the filename to play the sound like:

    Dim sound As New Sound(Application.StartupPath & "/mysoundfile.wav"
    sound.Play()
    Thanks a lot, this way is much easier then what I was trying to accomplish.

    Now I just have ONE more question.

    So my program will look for running processes, if the game is open it moves certain files to a different folder.

    If the game is closed, it moves the files back. (If they where moved in the first place)

    I have the above steps done, but I'm having trouble with having the program look for the the running process every X number of seconds.

    I guess you'd say I'm looking for a loop that would run every X number of seconds.

    Here is a sample of what I have:
    Public Class Form1

    HTML Code:
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Timer1.Enabled = True
    
    
            TextBox1.Text = Application.StartupPath
            For Each myprocess In Process.GetProcesses
                If myprocess.MainWindowTitle.Contains("Combat_Arms") Then
                    Label2.Hide()
                    Label3.Show()
    
                End If
    
            Next
    
        End Sub
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            Timer1.Enabled = False
            For Each myprocess In Process.GetProcesses
                If myprocess.MainWindowTitle.Contains("Combat_Arms") Then
                    Label2.Hide()
                    Label3.Show()
    
                End If
    
            Next
        End Sub
    
    End Class


    I was trying to loop using timer1, but it isn't working out.
    Any help?
    Last edited by JustANoob; Jan 3rd, 2009 at 08:36 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width