• Welcome to Valhalla Legends Archive.
 

Setup

Started by ChR0NiC, March 20, 2003, 09:29 PM

Previous topic - Next topic

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??  :-[

Grok

#1
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.

MrRaza

#2
Dont forget about INI files.......

Eibro

#3
QuoteDont forget about INI files.......
"Once you know how to read and write disk files, you can save your variables." How are INI files any different?
Eibro of Yeti Lovers.

Tuberload

#4
Their are API functions available for reading/writing to INI files.
Quote"Pray not for lighter burdens, but for stronger backs." -- Teddy Roosevelt
"Your forefathers have given you freedom, so good luck, see you around, hope you make it" -- Unknown

Grok

#5
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.

Tuberload

#6
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
Quote"Pray not for lighter burdens, but for stronger backs." -- Teddy Roosevelt
"Your forefathers have given you freedom, so good luck, see you around, hope you make it" -- Unknown

Camel

#7
QuoteHe'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.
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

Skywing

Quote from: Camel on March 21, 2003, 09:00 AM
QuoteHe'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.
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
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.

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.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Stealth

#10
Sequential access files are good to know anyways..

   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.


And to write text to a sequential access file:

   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!


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  :-\
- Stealth
Author of StealthBot

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

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.