Skip to content
MPGHThe Dark Arts
/
RegisterLog in
Forum
Community
What's NewLatest posts across the boardTrendingHottest threads right nowSubscribedThreads you follow
Discussion
GeneralIntroductionsEntertainmentDebate FortFlaming & Rage
Board
News & AnnouncementsMPGH TimesSuggestions & HelpGiveaways
More Sections
Art & Graphic DesignProgrammingHackingCryptocurrency
Hacks & Cheats
Games
ValorantCS2 / CS:GOCall of Duty / WarzoneFortniteApex LegendsEscape From Tarkov
+14 moreLeague of LegendsGTA VMinecraftRustROTMGBattlefieldTroveBattleOnCombat ArmsCrossFireBlackshotRuneScapeDayZDead by Daylight
Resources
Game Hacking TutorialsReverse EngineeringGeneral Game HackingAnti-CheatConsole Game Hacking
Tools
Game Hacking ToolsTrainers & CheatsHack/Release NewsNew
Submit a release →Share your cheat, tool, or config with the community.
AINEW
AI Tools
General & DiscussionPrompt EngineeringLLM JailbreaksHotAI Agents & AutomationLocal / Open Models
AI × Gaming
AI Aimbots & VisionML Anti-CheatGame Bots & Automation
Create
AI Coding / Vibe CodingAI Art & MediaAI Voice & TTS
The AI frontier →Where game hacking meets modern machine learning. Jump in.
Marketplace
Buy & Sell
SellingBuyingTradingUser Services
Trust & Safety
Middleman LoungeMarketplace TalkVouch Copy Profiles
Money
Cryptocurrency TalkCurrency ExchangeWork & Job Offers
Start selling →List accounts, services, and goods. Use the middleman to trade safe.
MPGH The Dark Arts

A community for offensive security research, reverse engineering, and AI.

Community

ForumMarketplaceSearch

Account

RegisterLog in

Legal

Privacy PolicyForum RulesHelp & FAQ
© 2026 MPGH · All rights reserved.Built by the community, for the community. For educational purposes onlyContent is shared for security research and education — we don't condone illegal use. You're responsible for complying with applicable laws. Use at your own risk.
Home › Forum › Programming › Visual Basic Programming › [Tutorial/Snippet][VB6] Reading and writing INI Files

[Tutorial/Snippet][VB6] Reading and writing INI Files

Posts 1–7 of 7 · Page 1 of 1
That0n3Guy
That0n3Guy
[Tutorial/Snippet][VB6] Reading and writing INI Files
Purpose: Saving settings, etc.

Setting it up

  • Create a new module
  • Name it something along the lines of "SaveSets"
  • Add the following code to your module:


Code:
Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyName As Any, ByVal lsString As Any, ByVal lplFilename As String) As Long
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Check As String

Public Function Load(Section As String, Key As String) As String 
Dim lngResult As Long 
Dim strFileName 
Dim strResult As String * 300
strFileName = App.Path & "\settings.ini" 
lngResult = GetPrivateProfileString(Section, Key, strFileName, strResult, Len(strResult), strFileName) 
Check = App.Path & "\sets.ini" 
Load = Trim(strResult) 
End Function

Public Function Save(Section As String, Key As String, Content As String)
Dim lngResult As Long
Dim strFileName
strFileName = App.Path & "\settings.ini"
lngResult = WritePrivateProfileString(Section, Key, Content, strFileName)
End Function
  • Now, change where it says "settings.ini" to file name of which you want to read and write.
  • All of the rest of the code will stay the same, you shouldn't have much of a reason to chance it.


Using it

Saving

To save something, write the following under the code for your button or whatever it is your saving from.

Code:
Call Save("Section", "Label", "Value")
Now start to fill this out. Right now that would output the following:

Code:
[Section]
Label = Value
Knowing that, replace section, label, and value with whatever you want to save.

Loading

To load something, put the following code for when you want to load:

Code:
Call Load("Section", "Label")
or, to assign the value it loaded to a variable,

Code:
MyVariable = Load("Section", "Label")
This works the same way as above and needs to have the same values for section and label or else it will NOT work.

If you need anymore help, just post saying so and I'll do my best to help.
#1 · 16y ago
FA
FatCat00
just what i need for my app. thanx a bunch
Edit: Some Problems in the code? @_@'
#2 · edited 16y ago · 16y ago
Zoom
Zoom
Thanks for this usefull tut..
#3 · 16y ago
That0n3Guy
That0n3Guy
Quote Originally Posted by FatCat00 View Post
just what i need for my app. thanx a bunch
Edit: Some Problems in the code? @_@'
Where do you see any problems in the code?
#4 · 16y ago
FA
FatCat00
The words in red are the error i get i try to fix them but i think i made it worse?
Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyName As Any, ByVal lsString As Any, ByVal lplFilename As String) As Long
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Check As String

Public Function Load(Section As String, Key As String) As String
Dim lngResult As Long
Dim strFileName
Dim strResult As String * 300
strFileName = App.Path & "\settings.ini"
lngResult = GetPrivateProfileString(Section, Key, strFileName, strResult, Len(strResult), strFileName)
Check = App.Path & "\sets.ini"
Load = Trim(strResult)
End Function

Public Function Save(Section As String, Key As String, Content As String)
Dim lngResult As Long
Dim strFileName
strFileName = App.Path & "\settings.ini"
lngResult = WritePrivateProfileString(Section, Key, Content, strFileName)
End Function
#5 · 16y ago
That0n3Guy
That0n3Guy
Quote Originally Posted by FatCat00 View Post
The words in red are the error i get i try to fix them but i think i made it worse?
What are you coding in? This was made strictly for VB6, I don't do any of the other VBs.
#6 · 16y ago
WT
wtfiwantthatname
Quote Originally Posted by FatCat00 View Post
The words in red are the error i get i try to fix them but i think i made it worse?

Those errors are from vb.net in .net you cant do string * 300 to create a strign with 300 characters. try using strResult = space(300)


For app.path use Application.ExecutablePath.

For the length of strResult you can use len() or strResult.length.


P.S ; I Forgot to mention that long in VB is equal to an integer in vb.net. Also for you API declarations you need to marshal the variables that are declared as any.
#7 · 16y ago
Posts 1–7 of 7 · Page 1 of 1

Post a Reply

Similar Threads

  • [Help]Reading and Writing to .txt files on the internetBy treeham in Visual Basic Programming
    6Last post 16y ago
  • [TUT]How to read and write to a text fileBy XORxHACK in Java
    18Last post 16y ago
  • Reading and Writing FloatBy hack_tr in Visual Basic Programming
    2Last post 15y ago
  • need help!? read and write (txt)By GER-Domi. in Visual Basic Programming
    5Last post 16y ago
  • Reading from an INI fileBy Credzis in C++/C Programming
    0Last post 18y ago

Tags for this Thread

#files#ini#reading#tutorial or snippetvb6#writing