Jump to content

VB2008 Not Reading INI's


Recommended Posts

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 Integer


Dim result As Integer = 0
Dim 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)
Next

Accordng 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


Thanks, but still no closer, it just seems that its totally ignoring something, yet ini file is laid out correct?

[WADS]

Cat1=Communications

Cat2=WebDev

Can'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 by Bullseye
Link to comment
Share on other sites

  • 4 weeks later...

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 Long

Function 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 by Bullseye
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...