Valhalla Legends Forums Archive | Battle.net Bot Development References | [VB]Parsing a Configuration File

AuthorMessageTime
Lenny
How would i setup the bot to read the config settings from a text file such as username password....?

the text file would look like this
[Settings]
Username=
Password=
and so on....
July 14, 2003, 4:24 AM
Nub
[code]
Dim strBlank$, BotTrigger$, BotName$, BotPass$
Close #1
Open App.Path & "\Config.txt" For input as #1
Input #1, strBlank
Input #1, strBlank
BotName = Right(strBlank, len(strBlank) - 9)
Input #1, strBlank
Botpass = Right(strBlank, len(strBlank) - 9)
Input #1, strBlank
BotTrigger = right(strBlank, len(strBlank) - 8)
Close #1
[/code]
Then server, master, ect...
July 14, 2003, 4:40 AM
Camel
[code]Option Explicit
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 Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Long
Const MaxValLength = 8196

Function GS(ByVal Section As String, ByVal Name As String, Optional Default As String, Optional File As String = "Users.INI") As String
Name = Replace(Name, "=", Chr(1))
Section = Replace(Section, "[", "!")
Section = Replace(Section, "]", "!")

GS = Space(MaxValLength)
GS = Left(GS, GetPrivateProfileString(Section, Name, Default, GS, Len(GS), App.Path & "\" & File))

GS = Replace(GS, Chr(1), vbCr)
GS = Replace(GS, Chr(2), """")
End Function

Sub SS(ByVal Section As String, ByVal Name As String, ByVal Value As String, Optional File As String = "Users.INI")
Name = Replace(Name, "=", Chr(1))
Section = Replace(Section, "[", "!")
Section = Replace(Section, "]", "!")

If Not IsNumeric(Value) Then
Value = Replace(Value, vbCrLf, vbCr)
Value = Replace(Value, vbCr, Chr(1))
Value = Replace(Value, """", Chr(2))
Value = """" & Value & """"
End If

WritePrivateProfileString Section, Name, Value, App.Path & "\" & File
End Sub[/code]

[code]Username = GS("Settings","Username")[/code]
July 14, 2003, 4:41 AM
WiLD
im sure i posted the how 2 read and write to/from a ini file or so on. try search though some preverse posts
July 14, 2003, 12:50 PM
Grok
[quote author=WiLD link=board=17;threadid=1905;start=0#msg14769 date=1058187049]
im sure i posted the how 2 read and write to/from a ini file or so on. try search though some preverse posts
[/quote]

I'm sure I posted a perfectly good INI class which does EVERYTHING for you.

Private INI as INIFile
INI.FileName = "C:\Program Files\BlahBot\config.ini"
INI.SectionName = "BotNet"
Cfg.BotNetServer = INI.ReadString("Server", "www.valhallalegends.com")
Cfg.BotNetDB = INI.ReadString("DefaultDBName", "[vL]")
Cfg.BotNetDBPW = INI.ReadString("DefaultDBPassword", "LokiThor")
Cfg.BotNetUser = INI.ReadString("UserName", "Grok")
Cfg.BotNetUserPW = INI.ReadString("UserPassword", "vålhållårules")

The INI class should be downloadable somewhere .. let me find link...

http://www.valhallalegends.com/pub/CINIFile.cls

Enjoy!
July 14, 2003, 4:58 PM

Search