Bullseye Posted April 27, 2008 Share Posted April 27, 2008 I need to read from a ini file so under good old vb6 ..Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Object, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As IntegerDim result As Integer = 0Dim current_category As String = ""Dim category_name As String = ""Dim tmp_cat As String = ""For category_counter = 1 To number_of_categories category_name = "Cat" & CStr(category_counter) result = GetPrivateProfileString("WADS", category_name, "UNKNOWN", tmp_cat, 255, app_path & "wads.cfg") current_category = Left$(tmp_cat, result)NextAccordng to watch window, I'm not getting anything back from tmp_cat, yet result says it received 7 characters, but it should be 14, for Communications.I even changed the category_name value to "Cat1", same result.Daft thing is, GetPrivateProfileInt is working correctly, with almost the same basic params, GetPrivateProfileInt("WADS", "AdminPass", 0, app_path & "wads.cfg").Any clues, why vb2008 is being a b***h?By the way, incase your wondering, app_path is "c:\vb2008\projects\wads\" so no errors there. Link to comment Share on other sites More sharing options...
Yzöwl Posted April 27, 2008 Share Posted April 27, 2008 VB6 longs are now .NET integers (a long in .net is 64 bits not 32 bits as in vb6)Take a look here and see if that helps you. Link to comment Share on other sites More sharing options...
Bullseye Posted April 27, 2008 Author Share Posted April 27, 2008 (edited) Thanks, but still no closer, it just seems that its totally ignoring something, yet ini file is laid out correct?[WADS]Cat1=CommunicationsCat2=WebDevCan't think that using the for/next loop as a counter to add a number on the end of CAT can be the problem.category_name = "Cat" & CStr(category_counter) .. Watch comes back as Cat1,Cat2 ...... Edited April 27, 2008 by Bullseye Link to comment Share on other sites More sharing options...
Bullseye Posted May 25, 2008 Author Share Posted May 25, 2008 (edited) Got it working, went back to vb6 ...Public 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 LongFunction Read_Ini_String(section_name As String, key_name As String, file_name As String) As String Dim result_buffer_length As Long Dim result_buffer As String * 256 result_buffer_length = GetPrivateProfileString(section_name, key_name, "UNKNOWN", result_buffer, 256, file_name) Read_Ini_String = (Left$(result_buffer, result_buffer_length))End Function Edited May 25, 2008 by Bullseye Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now