| View previous topic :: View next topic |
| Author |
Message |
hackerkts Expert Cheater
Reputation: 0
Joined: 21 Jan 2006 Posts: 160 Location: Singapore
|
Posted: Tue Jan 08, 2008 12:40 pm Post subject: [VB6] Reading values from .INI and use it in flash trainer |
|
|
Hi there, I have a question about VB6.
How do you actually read values from a INI and used it in my flash trainer,
Example one of the guy who created his trainer, he also include a system.ini
| Code: | [Default]
Text12=commando
Text11=none
Text10=none
Text9=life
Text8=ammo
Text7=bomb
Text6=Variable 4
Text5=
Text4=life_left
Text3=slug_left
Text2=bomb_left
Text1=http://www.miniclip.com/games/commando/en/commando.swf?mc_gamename=Commando&mc_hsname=1760 |
I want the flash trainer to read the variables and values from the ini file, but I don't know how. Oh one more thing, I have no knowledge for VB XD
Thanks!
_________________
| Quote: | | "Give a man a fish and he will eat for a day. Teach a man to fish and he will eat for the rest of his life." |
Read it, learn it and love it! |
|
| Back to top |
|
 |
Michel Expert Cheater
Reputation: 0
Joined: 16 May 2007 Posts: 214 Location: The Netherlands
|
|
| Back to top |
|
 |
killersamurai Expert Cheater
Reputation: 0
Joined: 10 Sep 2007 Posts: 197 Location: Colorado
|
Posted: Tue Jan 08, 2008 1:09 pm Post subject: |
|
|
GetPrivateProfileString() will do the trick. Even though you don't know vb, you can use c++. You have three options: MFC, ATL, or pure win32. MFC would be the best choice for activex controls.
Use of GetPrivateProfileString
| Code: |
wchar_t wcDir[] = L"c:\\system.ini";
wchar_t wcRetVal[101] = { 0 };
GetPrivateProfileString(L"Default", L"Text1", NULL, wcRetVal, 101, wcDir);
|
Where default is, that is where you put in the section header. Where Text1 is, that is where you put the variable name. Where NULL is, that is what will get returned if no key is found (the variable you entered). wcRetVal will contain the value of the key. 101 is the buffer size. wcDir tells GetPrivateProfileString where the .ini is. Hope this helped. If you want to do it in vb, it's practically the same. All you have to do is import the function.
|
|
| Back to top |
|
 |
hackerkts Expert Cheater
Reputation: 0
Joined: 21 Jan 2006 Posts: 160 Location: Singapore
|
Posted: Tue Jan 08, 2008 9:53 pm Post subject: |
|
|
After reading and trying, I still don't understand a single thing.. >.<
Oh ya, I have any knowledge for C++ too.
_________________
| Quote: | | "Give a man a fish and he will eat for a day. Teach a man to fish and he will eat for the rest of his life." |
Read it, learn it and love it! |
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8585 Location: 127.0.0.1
|
Posted: Wed Jan 09, 2008 2:49 am Post subject: |
|
|
Heres a quick example:
Put this in a module:
| Code: | Option Explicit
Private Declare Function GetPrivateProfileString Lib "KERNEL32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As Any, ByVal lpKeyName As Any, ByVal lpDefault As Any, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Function ReadKey(strSection As String, strKey As String) As String
Dim strPath As String
strPath = App.Path & "\variables.ini"
Dim strDefault As String
Dim strBuffer As String
strDefault = 0
strBuffer = Space$(255)
Call GetPrivateProfileString(strSection, strKey, strDefault, strBuffer, 255, strPath)
ReadKey = strBuffer
End Function
|
Then to use this function do something such as:
| Code: | Private Sub Form_Load()
Dim strKey As String
strKey = ReadKey("Default", "Text1")
Text1.Text = strKey
End Sub |
That will read the key 'Text1' inside the section 'Default' in your INI file. If you wish to change the ini path or name change this line in the module code:
| Code: | Dim strPath As String
strPath = App.Path & "\variables.ini" |
_________________
- Retired. |
|
| Back to top |
|
 |
hackerkts Expert Cheater
Reputation: 0
Joined: 21 Jan 2006 Posts: 160 Location: Singapore
|
Posted: Wed Jan 09, 2008 8:27 am Post subject: |
|
|
OMG! It's short and sweet, thanks!
Actually before I post this thread I did search for it, but I could only found a long winded class script.
Thanks again!
| Quote: | | Sorry, but you will have to wait 8787 seconds before you can give rep |
I own you 1
_________________
| Quote: | | "Give a man a fish and he will eat for a day. Teach a man to fish and he will eat for the rest of his life." |
Read it, learn it and love it! |
|
| Back to top |
|
 |
mer0x Advanced Cheater
Reputation: 0
Joined: 06 Jan 2008 Posts: 63
|
Posted: Wed Jan 09, 2008 3:10 pm Post subject: |
|
|
For writing..
| Code: |
Option Explicit
Private 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
Public Declare Function WriteKey(szSection As String, szKey As String, szString) As String
Dim szFileName As String
szFileName = App.Path & "\variables.ini"
Call WritePrivateProfileString(szSection, szKey, szString, szFileName)
End Function
|
Example:
| Code: |
Dim sSection as string
Dim sKey as string
sSection = "test"
sKey = "testkey"
call WriteKey sSection, sKey, 1
|
|
|
| Back to top |
|
 |
hackerkts Expert Cheater
Reputation: 0
Joined: 21 Jan 2006 Posts: 160 Location: Singapore
|
Posted: Wed Jan 09, 2008 7:59 pm Post subject: |
|
|
Thanks for that mer0x, but I don't think I will be too in to writing it to .ini file
I mainly will implement the reading values into flash trainer
_________________
| Quote: | | "Give a man a fish and he will eat for a day. Teach a man to fish and he will eat for the rest of his life." |
Read it, learn it and love it! |
|
| Back to top |
|
 |
|