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....
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
Then server, master, ect...
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
Username = GS("Settings","Username")
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 from: WiLD on July 14, 2003, 07:50 AM
im sure i posted the how 2 read and write to/from a ini file or so on. try search though some preverse posts
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!