Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[request] how to let VB6 make a config/save file
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Haxory'
Grandmaster Cheater Supreme
Reputation: 92

Joined: 30 Jul 2007
Posts: 1900

PostPosted: Sat Dec 15, 2007 10:22 am    Post subject: [request] how to let VB6 make a config/save file Reply with quote

well here is my question:
how to let VB6 make a config/save file?

plz tell me i will +rep Exclamation Exclamation

_________________
you and me baby ain't nothing but mammals so lets do it like they do on the discovery channel
Back to top
View user's profile Send private message
AtheistCrusader
Grandmaster Cheater
Reputation: 6

Joined: 23 Sep 2006
Posts: 681

PostPosted: Sat Dec 15, 2007 10:26 am    Post subject: Reply with quote

Option Explicit

Public Function ReadIniValue(INIpath As String, KEY As String, Variable As String) As String
Dim NF As Integer
Dim Temp As String
Dim LcaseTemp As String
Dim ReadyToRead As Boolean

AssignVariables:
NF = FreeFile
ReadIniValue = ""
KEY = "[" & LCase$(KEY) & "]"
Variable = LCase$(Variable)

EnsureFileExists:
Open INIpath For Binary As NF
Close NF
SetAttr INIpath, vbArchive

LoadFile:
Open INIpath For Input As NF
While Not EOF(NF)
Line Input #NF, Temp
LcaseTemp = LCase$(Temp)
If InStr(LcaseTemp, "[") <> 0 Then ReadyToRead = False
If LcaseTemp = KEY Then ReadyToRead = True
If InStr(LcaseTemp, "[") = 0 And ReadyToRead = True Then
If InStr(LcaseTemp, Variable & "=") = 1 Then
ReadIniValue = Mid$(Temp, 1 + Len(Variable & "="))
Close NF: Exit Function
End If
End If
Wend
Close NF
End Function



IN MODULE1


Option Explicit

Public Function WriteIniValue(INIpath As String, PutKey As String, PutVariable As String, PutValue As String)
Dim Temp As String
Dim LcaseTemp As String
Dim ReadKey As String
Dim ReadVariable As String
Dim LOKEY As Integer
Dim HIKEY As Integer
Dim KEYLEN As Integer
Dim VAR As Integer
Dim VARENDOFLINE As Integer
Dim NF As Integer
Dim X As Integer

AssignVariables:
NF = FreeFile
ReadKey = vbCrLf & "[" & LCase$(PutKey) & "]" & Chr$(13)
KEYLEN = Len(ReadKey)
ReadVariable = Chr$(10) & LCase$(PutVariable) & "="

EnsureFileExists:
Open INIpath For Binary As NF
Close NF
SetAttr INIpath, vbArchive

LoadFile:
Open INIpath For Input As NF
Temp = Input$(LOF(NF), NF)
Temp = vbCrLf & Temp & "[]"
Close NF
LcaseTemp = LCase$(Temp)

LogicMenu:
LOKEY = InStr(LcaseTemp, ReadKey)
If LOKEY = 0 Then GoTo AddKey:
HIKEY = InStr(LOKEY + KEYLEN, LcaseTemp, "[")
VAR = InStr(LOKEY, LcaseTemp, ReadVariable)
If VAR > HIKEY Or VAR < LOKEY Then GoTo AddVariable:
GoTo RenewVariable:

AddKey:
Temp = Left$(Temp, Len(Temp) - 2)
Temp = Temp & vbCrLf & vbCrLf & "[" & PutKey & "]" & vbCrLf & PutVariable & "=" & PutValue
GoTo TrimFinalString:

AddVariable:
Temp = Left$(Temp, Len(Temp) - 2)
Temp = Left$(Temp, LOKEY + KEYLEN) & PutVariable & "=" & PutValue & vbCrLf & Mid$(Temp, LOKEY + KEYLEN + 1)
GoTo TrimFinalString:

RenewVariable:
Temp = Left$(Temp, Len(Temp) - 2)
VARENDOFLINE = InStr(VAR, Temp, Chr$(13))
Temp = Left$(Temp, VAR) & PutVariable & "=" & PutValue & Mid$(Temp, VARENDOFLINE)
GoTo TrimFinalString:

TrimFinalString:
Temp = Mid$(Temp, 2)
Do Until InStr(Temp, vbCrLf & vbCrLf & vbCrLf) = 0
Temp = Replace(Temp, vbCrLf & vbCrLf & vbCrLf, vbCrLf & vbCrLf)
Loop

Do Until Right$(Temp, 1) > Chr$(13)
Temp = Left$(Temp, Len(Temp) - 1)
Loop

Do Until Left$(Temp, 1) > Chr$(13)
Temp = Mid$(Temp, 2)
Loop

OutputAmendedINIFile:
Open INIpath For Output As NF
Print #NF, Temp
Close NF

End Function



IN MODULE2..




Then you call it like this
WriteIniValue App.Path & "\MyTest.ini", "Default", "Text1", Text1.Text
to write

Text1.Text = ReadIniValue(App.Path & "\Settings.ini", "Data", "name")

to read
Back to top
View user's profile Send private message
Haxory'
Grandmaster Cheater Supreme
Reputation: 92

Joined: 30 Jul 2007
Posts: 1900

PostPosted: Sat Dec 15, 2007 10:43 am    Post subject: Reply with quote

im having some errors
(!!!!!! indicate errors)
WriteIniValue !!!!! App.Path & "\MyTest.ini", "Default", "Text1", Text1.Text


Text1.Text = ReadIniValue(App.Path & "\Settings.ini", "Data", "name")

_________________
you and me baby ain't nothing but mammals so lets do it like they do on the discovery channel
Back to top
View user's profile Send private message
dnsi0
I post too much
Reputation: 0

Joined: 04 Jan 2007
Posts: 2674

PostPosted: Sat Dec 15, 2007 11:03 am    Post subject: Reply with quote

Or create a delphi lib and use vb to link to it.
Back to top
View user's profile Send private message
Haxory'
Grandmaster Cheater Supreme
Reputation: 92

Joined: 30 Jul 2007
Posts: 1900

PostPosted: Sat Dec 15, 2007 11:07 am    Post subject: Reply with quote

i dun have delphi since i didnt get me new 80 mb harddisk

(i ran out space)

_________________
you and me baby ain't nothing but mammals so lets do it like they do on the discovery channel
Back to top
View user's profile Send private message
pimpstonie
Advanced Cheater
Reputation: 0

Joined: 27 Sep 2007
Posts: 70

PostPosted: Sat Dec 15, 2007 11:17 am    Post subject: Reply with quote

Here you go. Hope you have WINRAR.
If you can't see the download:
http://forum.cheatengine.org/download.php?id=25581



The Extension 'rar' was deactivated by an board admin, therefore this Attachment is not displayed.



Last edited by pimpstonie on Sun Dec 16, 2007 10:37 am; edited 1 time in total
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sat Dec 15, 2007 7:45 pm    Post subject: Reply with quote

@masterkert3: You should really use the API instead of writing your own parser to read and write to INI files. Just easier to use in the long run and less of a worry for errors.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
dnsi0
I post too much
Reputation: 0

Joined: 04 Jan 2007
Posts: 2674

PostPosted: Sat Dec 15, 2007 8:58 pm    Post subject: Reply with quote

What API??? I don't know that api.

Im gonna use the API viewer brb.

Edit: Cant find windows api for that all I found was RegRead... Etc
ANd I do remember delphi having that TIniRead Class.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sun Dec 16, 2007 12:44 am    Post subject: Reply with quote

GetPrivateProfileString
WritePrivateProfileString

Heres a quick toss-together example. Put this code into a module:

Code:
Option Explicit

Private Declare Function WritePrivateProfileString Lib "KERNEL32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Private Declare Function GetPrivateProfileString Lib "KERNEL32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As Any, ByVal lpKeyName As Any, ByVal lpDefault As Any, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

'//
'// INI File Name
'//
Private Const cINIFile = "testing.ini"

'//
'// Read Section Key
'//
Public Function ReadSectionKey(strSection As String, strKey As String) As String
    Dim strReturn   As String
    Dim strFile     As String
   
    strFile = App.Path & "/" & cINIFile
    strReturn = String(255, Chr(0))
    ReadSectionKey = Left(strReturn, GetPrivateProfileString(strSection, ByVal strKey, "", strReturn, Len(strReturn), strFile))
End Function

'//
'// Write Section Key
'//
Public Function WriteSectionKey(strSection As String, strKey As String, strNewVal As String) As Boolean
    Dim dwReturn    As Long
    Dim strFile     As String
   
    strFile = App.Path & "/" & cINIFile
    dwReturn = WritePrivateProfileString(strSection, strKey, strNewVal, strFile)
    WriteSectionKey = CBool(dwReturn)
End Function



Then change the following line to the name of your INI file:

Code:
Private Const cINIFile = "testing.ini"


Next, to use the code you would do the following. Lets use this example ini for this:

Code:
[READING]
Key1= 0
Key2= Hello!
Key3= 12345

[WRITING]
Key1=
Key2=
Key3=


So we have two sections, READING and WRITING each with 3 keys. So to read the keys we can do:

Code:
    Dim strKeyVal1 As String
    Dim strKeyVal2 As String
    Dim strKeyVal3 As String
   
    strKeyVal1 = ReadSectionKey("READING", "Key1")
    strKeyVal2 = ReadSectionKey("READING", "Key2")
    strKeyVal3 = ReadSectionKey("READING", "Key3")


And an example to write new values:

Code:
    Call WriteSectionKey("WRITING", "Key1", "New value for key 1")
    Call WriteSectionKey("WRITING", "Key2", "New value for key 2")
    Call WriteSectionKey("WRITING", "Key3", "New value for key 3")



If the key does not exist when you are writing it, it will create it automatically. Same goes for the section as well. If reading fails, the return will be empty.

This has no error handling and so on so like I said, basic toss together example that I just wrote.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Haxory'
Grandmaster Cheater Supreme
Reputation: 92

Joined: 30 Jul 2007
Posts: 1900

PostPosted: Sun Dec 16, 2007 4:44 am    Post subject: Reply with quote

What buttons/textboxes do i need ?
_________________
you and me baby ain't nothing but mammals so lets do it like they do on the discovery channel
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sun Dec 16, 2007 9:44 am    Post subject: Reply with quote

haxory' wrote:
What buttons/textboxes do i need ?


Depends on how you plan to use the INI file. You might not need any at all. Read the values into variables if anything then use the variable as needed.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Haxory'
Grandmaster Cheater Supreme
Reputation: 92

Joined: 30 Jul 2007
Posts: 1900

PostPosted: Mon Dec 17, 2007 8:01 am    Post subject: Reply with quote

im not following
_________________
you and me baby ain't nothing but mammals so lets do it like they do on the discovery channel
Back to top
View user's profile Send private message
Pseudo Xero
I post too much
Reputation: 0

Joined: 16 Feb 2007
Posts: 2607

PostPosted: Mon Dec 17, 2007 8:05 am    Post subject: Reply with quote

haxory' wrote:
im not following

Rolling Eyes
Back to top
View user's profile Send private message
Haxory'
Grandmaster Cheater Supreme
Reputation: 92

Joined: 30 Jul 2007
Posts: 1900

PostPosted: Mon Dec 17, 2007 8:14 am    Post subject: Reply with quote

if its so Rolling Eyes Rolling Eyes Rolling Eyes Rolling Eyes
you may help me

_________________
you and me baby ain't nothing but mammals so lets do it like they do on the discovery channel
Back to top
View user's profile Send private message
Pseudo Xero
I post too much
Reputation: 0

Joined: 16 Feb 2007
Posts: 2607

PostPosted: Mon Dec 17, 2007 8:19 am    Post subject: Reply with quote

haxory' wrote:
if its so Rolling Eyes Rolling Eyes Rolling Eyes Rolling Eyes
you may help me

He means you can use variables (Like dim ____ as string) to save data, temporarily.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites