Reading an INI file

J

jcrouse

I'm reading an INI file and all is working fine. However, when I turn Option
Explicit "On" (it's currently "Off"), I get errors. Here is my pertinent
code:



Dim lpAppName As String

Dim lpKeyName As String

Dim lpDefault As String

Dim lpReturnedString As New System.Text.StringBuilder(256)

Dim lpNsize As Integer

Dim lpFileName As String



Private Declare Auto Function GetPrivateProfileString Lib "kernel32" _

(ByVal lpAppName As String, _

ByVal lpKeyName As String, _

ByVal lpDefault As String, _

ByVal lpReturnedString As System.Text.StringBuilder, _

ByVal lpNsize As Integer, _

ByVal lpFileName As String) As Integer





lpAppName = strParentName

lpDefault = ""

lpReturnedString = New System.Text.StringBuilder(256)

lpNsize = 256

lpFileName = Application.StartupPath & "\controls.ini"



lpKeyName = "P1_JOYSTICK_UP"

GetPrivateProfileString(lpAppName, lpKeyName, lpDefault, lpReturnedString,
lpNsize, lpFileName)

If lpReturnedString.ToString() <> "" Then

lbl1.Visible = True

lbl1.Text = lpReturnedString.ToString()

End If



It doesn't like the lpReturnedString parameter in the
GetPrivateProfileString function(not sure if the verbage is correct there).
What do I need to do to turn Option Strict "On" or should I not worry about
it?



Thanks,

John
 
C

Cor Ligthert

John,

I have been strugling with your problem about making faster the painting of
the labels. I told you I am not a painter (I do not like it working with all
those different pointers in differnt places on different layers) The
chalenge of course is not getting it working however making it faste.

Doing that I more and more got the idea why is John using labels instead of
picture boxes. Did you try that already. Without any expirience in that I
have he thouht that that maybe would make things much more easier to set as
picture in the box and than that probably would make moving easier.

So before I (or you) try that, did you had a reason for that?

Your problem in this message is probably that the declare is in the middle
of a procedure, in a procedure you can only declare with Dim, so just put it
outside the procedure, looks as well much nicer.

Another thing when most of use show code, we do not directly past from the
designer in the message. We past it first in a textbox. That makes that you
can see the code in one screen and gives you as sender more change on an
answer because the problem is easier and faster to see.

I hope this helps?

Cor
 
J

jcrouse

I always paste my code in MS Word first. I have no idea why it posts the way
it does. I've even checked the paragraph formatting/Line spacing and
everything looks good. Next time I'll try and paste into Notepad and see
what happens. As far as Pic Box. No I have not tried that. I'll look into
it. I am also going to try a test in VB6 to see if there is any difference.

Later,
John
 
C

Cor Ligthert

Herfried,

What has this answer to do with a "private" declaration inside a function?

Cor
 
H

Herfried K. Wagner [MVP]

* "Cor Ligthert said:
What has this answer to do with a "private" declaration inside a function?

It's a replacement that will make dealing with INI files easier.
 
C

Cor Ligthert

What has this answer to do with a "private" declaration inside a
function?
It's a replacement that will make dealing with INI files easier.

Than tell that in the message because that was not the question.

This is confusing even for me, who knows that you drops this with every
qeustion about a INI, I had the plan for looking for a link on that on
Google this morning using your name and INI, but saw it was not the
question.

Cor
 
H

Herfried K. Wagner [MVP]

* "Cor Ligthert said:
Your problem in this message is probably that the declare is in the middle
of a procedure, in a procedure you can only declare with Dim, so just put it
outside the procedure, looks as well much nicer.

This cannot be the case, because the code works with 'Option Strict'
turned off.
 
C

Cor Ligthert

Herfried,

Where is John talking about Option Strict?

Although I look mostly (when it is not 5 pages) mostly also to the code.

You think that can works fine with Option Strict Off and option Explicit On?

Cor
 
H

Herfried K. Wagner [MVP]

* "Cor Ligthert said:
Where is John talking about Option Strict?

Ooops. Typo. I wanted to type 'Option Explicit'.
Although I look mostly (when it is not 5 pages) mostly also to the code.

You think that can works fine with Option Strict Off and option Explicit On?

No. If you put the declare into a method's body, the code should not
compile at all, independent from the settings for 'Option Strict' and
'Option Explicit'.
 
C

Cor Ligthert

Herfried,
No. If you put the declare into a method's body, the code should not
compile at all, independent from the settings for 'Option Strict' and
'Option Explicit'.

Did I say that,

When John (the OP) says so it does.

:)))))

I showed you now a typical Herfried answer,

:)

However you are right, but it was in his code, so removing would be the this
first thing to do.
Maybe he changed something and did not notice it or something and did it
gave an error assuming it was the option explictit which he changed in the
same time.

Cor
 
H

Herfried K. Wagner [MVP]

* "Cor Ligthert said:
Did I say that,

When John (the OP) says so it does.

I assume that John has composed the code the way it showed up in the
post especially for the purpose of this post. It's not an 1:1 copy of
his code, I think.
 
H

Herfried K. Wagner [MVP]

* "Cor Ligthert said:
In future I will deal with you in the context of this message from you.

There are things where commenting doesn't make sense. When I don't
quote parts of the message this is /always/ (remember /always/)
intentional.

SCNR
 
C

Cor Ligthert

In future I will deal with you in the context of this message from you.
There are things where commenting doesn't make sense. When I don't
quote parts of the message this is /always/ (remember /always/)
intentional.
Bla bla...
 
C

Cor Ligthert

In future I will deal with you in the context of this message from
you.
"If you can't imitate him, don't copy him."
(Yogi Berra)

Do you understand that sentence?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top