|
-
Mar 30th, 2004, 11:29 PM
#1
Thread Starter
Junior Member
Reading ini file [Resolved]
hey 
I have looked over the forums and read lots of different ways to do this.. but to be honest i dont understand them at all.
What i have is an ini file with:
[List1]
1=text
2=text2
3=text44
to=from
a=good
ect ect
and what i want to do is specify the number/word in the ini file, read it.. and return with the text after the "=" in a textbox (only on the one line of course lol). i know this is probably easy for some, and i think you can use api for it. anyway any help at all would be greatly appreciated as i dont understand reading ini files at all
Last edited by Digit 0.1; Apr 6th, 2004 at 11:31 PM.
-
Mar 30th, 2004, 11:55 PM
#2
Here is an example.
VB Code:
'Ini file contents...
'[Settings]
'DBPath=C:\
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 Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Private Sub Command1_Click()
Dim lngI As Long
Dim lngSize As Long
Dim strText255 As String * 255
strText255 = ""
lngSize = Len(strText255)
lngI = GetPrivateProfileString("Settings", "DBPath", "", strText255, lngSize, "D:\Test.ini")
MsgBox Left$(strText255, lngI), vbOKOnly + vbInformation
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 31st, 2004, 12:16 AM
#3
Thread Starter
Junior Member
ah that works great
i understand how it works a bit more now lol.
hmm.. is there a faster way of doing this? Cause the example words great but the ini file i have may get bigger and i think it may take longer to read..
-
Mar 31st, 2004, 10:34 AM
#4
If you break it into "sections" the size of the file will not matter.
The "lpApplicationName" is the group, so if you have many small
relevant groups the size will not matter.
But if you have "[Settings]" and you have 100 keys below it then
I would think it would affect it.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 31st, 2004, 03:20 PM
#5
One of the games I am writing has an 8 page data file (*.txt) that I just use as a reference, but it's compressed, so I couldn't use it as an .ini file right off. Do you all think it would be a good idea for me to fully expand the file and use it as an .ini file? If so, I would need to know how to search for specific items to use in various parts of the program. It's another command I might like to have anyway..
-
Mar 31st, 2004, 06:39 PM
#6
Thread Starter
Junior Member
Last edited by Digit 0.1; Mar 31st, 2004 at 06:59 PM.
-
Mar 31st, 2004, 06:43 PM
#7
If you can't break it up into relevant sections then try something like ...
VB Code:
[Section1]
Key1=test1
Key2=test2
Key3=test3
[Section2]
Key1=test1
Key2=test2
Key3=test3
[Section3]
Key1=test1
Key2=test2
Key3=test3
'...
'...
'...
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 31st, 2004, 06:51 PM
#8
VB Code:
WritePrivateProfileString "Settings", "DBPath", "Testing, "D:\Test.ini"
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 31st, 2004, 07:03 PM
#9
Thread Starter
Junior Member
Originally posted by RobDog888
If you can't break it up into relevant sections then try something like ...
VB Code:
[Section1]
Key1=test1
Key2=test2
Key3=test3
[Section2]
Key1=test1
Key2=test2
Key3=test3
[Section3]
Key1=test1
Key2=test2
Key3=test3
'...
'...
'...
hmm yea that might work, what i have is a list of (so-called) ai and when someone enters say "hello" it will say "hey" back.
And what i do is basicly just read the whole ini for the "hello" string. hope that makes sence lol
Originally posted by RobDog888
WritePrivateProfileString "Settings", "DBPath", "Testing, "D:\Test.ini"
thanks easier then reading it lol
-
Mar 31st, 2004, 07:06 PM
#10
"Sounds" like you would be better off using a database to store
all of those AI responses. Would probably be faster also.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 31st, 2004, 07:26 PM
#11
Thread Starter
Junior Member
Originally posted by RobDog888
"Sounds" like you would be better off using a database to store
all of those AI responses. Would probably be faster also.
yep, thats exactly what my freind said to me aswell.. but databases sound too complicated to set up, i think ini is ok for now, (and when i say for now i mean for the next few days lol)
maybe i should look into making databases then
-
Apr 1st, 2004, 10:44 AM
#12
If you need any help designing the db post a new thread and we
will try to help you. It's not as complicated as you think.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 5th, 2004, 12:50 PM
#13
Thread Starter
Junior Member
Originally posted by RobDog888
If you need any help designing the db post a new thread and we
will try to help you. It's not as complicated as you think.
thanks i probably will once i feel i know as much as i can/want wiith ini reading and writing. i just want to get comfortable with them.
I do have a slight problem which i cant seem to fix..
when writing a 2 (or maybe more) digit number, it only writes the second one, i would do for example:
Code:
'amount changes, lets just say num is 1 and amount is 50 (should add to 51)
Dim Num as string
Num = Num + (amount)
msgbox num 'to make sure it adds correctly and it does
WritePrivateProfileString "settings", "num", (Num), App.Path & "\data\" & name & ".ini"
it seems to write fine.. but when i open the num again, it only recorded and wrote the last number "0" This is annoying as i cant figure out whats wrong, can anyone help?
-
Apr 5th, 2004, 01:06 PM
#14
Frenzied Member
Remove the ( ) around Num, not sure if that's what causing it, but you dont need them around the Variable.
WritePrivateProfileString "settings", "num", Num, App.Path & "\data\" & name & ".ini"
-
Apr 5th, 2004, 01:13 PM
#15
Since Num is a string try...
But since these are actually numeric values it will not add the way you want.
It will result in "150". Change the Num and amount to Integer or
Longs. Then ...
VB Code:
Num = Num + amount ' = 51
But then when you write to the ini file use the CStr() function to
change them to strings so the API can write to the ini file or you
will get a type mismatch error.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 5th, 2004, 01:29 PM
#16
Thread Starter
Junior Member
Originally posted by BrianS
Remove the ( ) around Num, not sure if that's what causing it, but you dont need them around the Variable.
WritePrivateProfileString "settings", "num", Num, App.Path & "\data\" & name & ".ini"
oh ok, thanks hmm didnt fix the problem though
Originally posted by RobDog888
Since Num is a string try...
But since these are actually numeric values it will not add the way you want.
It will result in "150". Change the Num and amount to Integer or
Longs. Then ...
VB Code:
Num = Num + amount ' = 51
But then when you write to the ini file use the CStr() function to
change them to strings so the API can write to the ini file or you
will get a type mismatch error.
i think im doing something wrong, i tried chaning both the ammount and num to integer and longs.. but when i do this vb crashes.. my code:
Code:
Private Function GiveCredits(ammount As String, email As String)
On Error Resume Next
Dim CredTot As Long
Dim FullCred As String
CredTot = CreditsCount(email)
MsgBox CredTot, , "credtot"
If CredTot <= "0" Then
WritePrivateProfileString "settings", "credits", (ammount), App.Path & "\userdata\" & email & ".ini"
Else
MsgBox ammount, , "ammount"
FullCred = CredTot + (ammount)
MsgBox FullCred, , "fullcred"
WritePrivateProfileString "settings", "credits", FullCred, App.Path & "\userdata\" & email & ".ini"
End If
End Function
ive probably made a mistake somewhere or done something wrong.. but i cant see it
But then when you write to the ini file use the CStr() function to
change them to strings so the API can write to the ini file or you
will get a type mismatch error
umm, sorry im not sure how to do this, could you elaborate please
-
Apr 5th, 2004, 01:34 PM
#17
What is CreditsCount? Try stepping through your code one line at
a time to find the offending line of code.
CStr:
VB Code:
WritePrivateProfileString "settings", "credits", CStr(ammount), App.Path & "\userdata\" & email & ".ini"
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 5th, 2004, 01:38 PM
#18
Thread Starter
Junior Member
oh.. credits count is to find the current ammount and that is:
Code:
Private Function CreditsCount(UserEmail As String)
Dim Cred As String
Dim lngI As Long
Dim lngSize As Long
Dim strText255 As String * 255
strText255 = ""
lngSize = Len(strText255)
lngI = GetPrivateProfileString("settings", "credits", "", strText255, lngSize, App.Path & "\userdata\" & UserEmail & ".ini")
Cred = Left$(strText255, lngI)
CreditsCount = Cred
End Function
Originally posted by RobDog888
CStr:
VB Code:
WritePrivateProfileString "settings", "credits", CStr(ammount), App.Path & "\userdata\" & email & ".ini"
ooh ok, thanks
-
Apr 5th, 2004, 01:39 PM
#19
Did that solve your issue?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 5th, 2004, 01:43 PM
#20
Thread Starter
Junior Member
well it solved the crashing when i tried it.. but it still gives me only the second digit, current code is:
Code:
Private Function GiveCredits(ammount As String, email As String)
On Error Resume Next
Dim CredTot As Long
Dim FullCred As Long
CredTot = CreditsCount(email)
MsgBox CredTot, , "credtot"
If CredTot <= "0" Then
WritePrivateProfileString "settings", "credits", CStr(ammount), App.Path & "\userdata\" & email & ".ini"
Else
MsgBox ammount, , "ammount"
FullCred = CredTot + (ammount)
MsgBox FullCred, , "fullcred"
WritePrivateProfileString "settings", "credits", CStr(FullCred), App.Path & "\userdata\" & email & ".ini"
End If
End Function
where i have ammount As String, maybe that should be ammount as integer?
-
Apr 5th, 2004, 01:45 PM
#21
The problem is in the function that generates the Num value.
Can you post it?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 5th, 2004, 01:51 PM
#22
Thread Starter
Junior Member
sure, this is what i have:
Code:
'game part
Private Function GuessNum(Player As String, nGuess As String)
Dim Guess As Long
Dim Roll As Long
Guess = nGuess
Roll = Int(Rnd * 10)
'MsgBox Guess
'MsgBox Roll
If Guess = Roll Then
GiveCredits "50", Player
End If
End Function
'give the credits part
Private Function GiveCredits(ammount As Integer, email As String)
On Error Resume Next
Dim CredTot As Long
Dim FullCred As Long
CredTot = CreditsCount(email)
MsgBox CredTot, , "credtot"
If CredTot <= "0" Then
WritePrivateProfileString "settings", "credits", CStr(ammount), App.Path & "\userdata\" & email & ".ini"
Else
MsgBox ammount, , "ammount"
FullCred = CredTot + (ammount)
MsgBox FullCred, , "fullcred"
WritePrivateProfileString "settings", "credits", CStr(FullCred), App.Path & "\userdata\" & email & ".ini"
End If
End Function
'check current credits
Private Function CreditsCount(UserEmail As String)
Dim Cred As String
Dim lngI As Long
Dim lngSize As Long
Dim strText255 As String * 255
strText255 = ""
lngSize = Len(strText255)
lngI = GetPrivateProfileString("settings", "credits", "", strText255, lngSize, App.Path & "\userdata\" & UserEmail & ".ini")
Cred = Left$(strText255, lngI)
CreditsCount = Cred
End Function
hope that makes sence
-
Apr 5th, 2004, 02:02 PM
#23
Worked fine for me when I made this change
VB Code:
GiveCredits "50", CStr(Player)
This is what I did to get the example to run
GuessNum_Click is a command button
VB 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 Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Private Sub Form_Load()
Player = "RobDog888"
End Sub
Private Sub GuessNum_Click()
Player = "RobDog888"
nGuess = 1
Dim Guess As Long
Dim Roll As Long
Guess = nGuess
Roll = Int(Rnd * 10)
'MsgBox Guess
'MsgBox Roll
If Guess = Roll Then
GiveCredits "50", CStr(Player)
Else
MsgBox "Wrong Guess!"
End If
End Sub
'give the credits part
Private Function GiveCredits(ammount As Integer, email As String)
On Error Resume Next
Dim CredTot As Long
Dim FullCred As Long
CredTot = CreditsCount(email)
MsgBox CredTot, , "credtot"
If CredTot <= "0" Then
WritePrivateProfileString "settings", "credits", CStr(ammount), App.Path & "\userdata\" & email & ".ini"
Else
MsgBox ammount, , "ammount"
FullCred = CredTot + (ammount)
MsgBox FullCred, , "fullcred"
WritePrivateProfileString "settings", "credits", CStr(FullCred), App.Path & "\userdata\" & email & ".ini"
End If
End Function
'check current credits
Private Function CreditsCount(UserEmail As String)
Dim Cred As String
Dim lngI As Long
Dim lngSize As Long
Dim strText255 As String * 255
strText255 = ""
lngSize = Len(strText255)
lngI = GetPrivateProfileString("settings", "credits", "", strText255, lngSize, App.Path & "\userdata\" & UserEmail & ".ini")
Cred = Left$(strText255, lngI)
CreditsCount = Cred
End Function
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 5th, 2004, 02:27 PM
#24
Thread Starter
Junior Member
Originally posted by RobDog888
Worked fine for me when I made this change
VB Code:
GiveCredits "50", CStr(Player)
This is what I did to get the example to run
GuessNum_Click is a command button
VB 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 Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Private Sub Form_Load()
Player = "RobDog888"
End Sub
Private Sub GuessNum_Click()
Player = "RobDog888"
nGuess = 1
Dim Guess As Long
Dim Roll As Long
Guess = nGuess
Roll = Int(Rnd * 10)
'MsgBox Guess
'MsgBox Roll
If Guess = Roll Then
GiveCredits "50", CStr(Player)
Else
MsgBox "Wrong Guess!"
End If
End Sub
'give the credits part
Private Function GiveCredits(ammount As Integer, email As String)
On Error Resume Next
Dim CredTot As Long
Dim FullCred As Long
CredTot = CreditsCount(email)
MsgBox CredTot, , "credtot"
If CredTot <= "0" Then
WritePrivateProfileString "settings", "credits", CStr(ammount), App.Path & "\userdata\" & email & ".ini"
Else
MsgBox ammount, , "ammount"
FullCred = CredTot + (ammount)
MsgBox FullCred, , "fullcred"
WritePrivateProfileString "settings", "credits", CStr(FullCred), App.Path & "\userdata\" & email & ".ini"
End If
End Function
'check current credits
Private Function CreditsCount(UserEmail As String)
Dim Cred As String
Dim lngI As Long
Dim lngSize As Long
Dim strText255 As String * 255
strText255 = ""
lngSize = Len(strText255)
lngI = GetPrivateProfileString("settings", "credits", "", strText255, lngSize, App.Path & "\userdata\" & UserEmail & ".ini")
Cred = Left$(strText255, lngI)
CreditsCount = Cred
End Function
i tried this in a new project and when i win, i always get a msgbox with "0" and doesnt write the ini.. so i dont think thats working for me either
i also tried changing the:
GiveCredits "50", (player) to
GiveCredits "50", CStr(Player
and still keep getting the single digit at the end.. this is annoying lol, whats even worse is i dont know what im doing wrong, and it seems to work fine for you lol
if i could get your code working, would i be able to do it then with different players and guesses cause thats what i need
-
Apr 5th, 2004, 02:39 PM
#25
Step through my code by pressing F8 once for each line you want
to advance. Check the values from the CreditsCount procedure.
I have a feeling that it is only taking a lenght of one from there.
Also, the length of UserEmail is ? in the CreditsCount procedure?
What OS and version are you running?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 6th, 2004, 11:30 PM
#26
Thread Starter
Junior Member
I went though my entire source last night and found what was wrong finally, what i didn’t see was that it actually 'did' write the correct value. But i had actually called the same function again in another part where i was first testing this, and it was writing.. then re-writing back again..
anyway, i understand it a whole lot better now
Thanks RobDog888! Really appreciate all the help! 
i know where to come if i need more help in the future lol
(which i will)
-
Apr 6th, 2004, 11:34 PM
#27
Glad to hear that you got it "[Resolved]" and that you are learning!
Always here to help.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|