Valhalla Legends Forums Archive | Battle.net Bot Development | Setup

AuthorMessageTime
ChR0NiC
I need some help with the setup/config part of my bot. I need to get my form to save what was entered in the setup form in a config file. This is vb. My setup form contains:
UserName
Password
Server
CD Key
D2 CDKey

The rest of the stuff is on another form which I dont need at this time. Please help anyone??  :-[
March 21, 2003, 3:29 AM
Grok
Sure no problem.  Learn about reading and writing disk files from your computer language's help files, or online help web pages.

Once you know how to read and write disk files, you can save your variables.

That's the easy way.  Someday you could use the registry.  It's different, somewhat harder for your skill level, but has some pros and cons.
March 21, 2003, 9:08 AM
MrRaza
Dont forget about INI files.......
March 21, 2003, 10:26 AM
Eibro
[quote]Dont forget about INI files.......[/quote]"Once you know how to read and write disk files, you can save your variables." How are INI files any different?
March 21, 2003, 11:24 AM
Tuberload
Their are API functions available for reading/writing to INI files.
March 21, 2003, 2:04 PM
Grok
He's just starting out, which is why I suggested using only VB functions to read/write files.

When beginner gets more experience he can learn techniques like using API calls.
March 21, 2003, 2:36 PM
Tuberload
One other point of interest, if you do not even understand the basics concepts involved with programming in VB I would not recommend a binary bot as your learning project.

On the subject of my last point, I was pointing out the difference between INI files and file reading/writing
March 21, 2003, 2:43 PM
Camel
[quote]He's just starting out, which is why I suggested using only VB functions to read/write files.

When beginner gets more experience he can learn techniques like using API calls.[/quote]
i think the get and set profile(registry) and privateprofile(ini file) functions are much easier to use, especially as a beginner, than reading the file because there's zero parsing involved
March 21, 2003, 3:00 PM
Skywing
[quote author=Camel link=board=17;threadid=506;start=0#msg3523 date=1048258803]
[quote]He's just starting out, which is why I suggested using only VB functions to read/write files.

When beginner gets more experience he can learn techniques like using API calls.[/quote]
i think the get and set profile(registry) and privateprofile(ini file) functions are much easier to use, especially as a beginner, than reading the file because there's zero parsing involved
[/quote]IIRC, the INI file functions are optimized for dealing with medium-to-small sized files, and try to cache changes in memory. They'll work fine for small things like configuration data, but I wouldn't recommend using them for, say, a user database.
March 22, 2003, 6:35 PM
iago
Better yet, if you're using VB use this pair of functions:
sub savesetting(AppName as String, Section as String, Key as String, Setting as String)
and
function getsetting(AppName as String, Section as String, Key as String, [Default]) As String

Make the AppName constant for your program, Section can be changed or can stay the same, then Key is like a variable name and Setting is its value. getsetting returns the "setting" specified for that key.

It makes use of a small piece of the registry, but it super nice for being lazy. It all goes in "KEY_LOCAL_MACHINE/VB and VBA applications/AppName/Section/Key = setting", iirc.
March 22, 2003, 10:15 PM
Stealth
Sequential access files are good to know anyways..

[code] Dim f As Integer 'file number
Dim filepath As String 'path to the file you want to open
Dim s() As String 'array to hold retrieved values

f = FreeFile 'assign to a free Windows file access number


Open filepath For Input As #f 'open the file to retrieve records
'assuming you have specified the filepath

If LOF(f) < 2 Then
'respond to the problem that the user has a blank text file
'not doing this step will cause runtime error 62 if the file is empty
End If

ReDim s(0) 'prepare the array
Do
Line Input #f, s(UBound(s)) 'retrieve a line of text
'and assign it to the topmost array position
ReDim Preserve s(0 To UBound(s) + 1) 'add another position to the array

Loop While Not EOF(f) 'repeat the above code until you've reached the end of the file

Close #f 'free the filenumber up for windows usage

'you can now use the s() array for whatever you want, pass it byref to
'a connection subroutine, whatever.[/code]

And to write text to a sequential access file:

[code] Dim f As Integer 'filenumber
Dim filepath As String 'path to file

Open filepath For Output As #f 'open the file for output; this will overwrite any existing
'file with the same name.
'once again assuming you have specified filepath.

Print #f, strOfYourChoosing 'this step can be repeated for as many
'configuration fields as you want to write.
'one line is written each time you use the print command.

Close #f 'always put away your toys![/code]

hope that helps somehow. it's kind of sloppy, but it's easy to code and understand.. ini files are much cleaner for future use, but this should serve your basic purposes... plus knowing how to use sequential access files might come in handy in the future ;)

Edit: LOF, not LenB :-\
March 25, 2003, 6:15 AM
MrRaza
Ill give you some more hints if you like. There are 10 different functions for INI files that do similar things. Five of them we dont need to know as of now, the other five are
[code]
GetPrivateProfileInt - Retrieves the integer value of an individual key.
GetPrivateProfileSection - Retrieves all key values in a given section.
GetPrivateProfileString - Retrieves the string value of an individual key.
WritePrivateProfileSection - Updates all keys in a given section, or creates a new section.
WritePrivateProfileString - Updates or Creates an individual key value. Can also be used to delete a key or a section.


You might also want to note that their are different functions for retireving an integer and string valyes for individual keys. That is because all key values are actually stored as strings. So when you want to grab an integer value, the string is converted to a numeric value. "8732ab" would cause GetPrivateProfileInt function to convert that as an integer value of "8732". Each of the ten API functions have different syntax. PM if you want some more information.[/code]
March 31, 2003, 1:13 AM

Search