PDA

Click to See Complete Forum and Search --> : Great INI Problem


VBrazil
Nov 25th, 1999, 08:33 AM
I got a really weird problem while using ini's, and there it is: In a form to get prices and calculate them, i added this line to make the total price appear in this manner: Amount X unit price = total price

Line of code:
lstTotal.AddItem (txtQuantidade.Text & " X " & Trim(Temp) & " = " & txtQuantidade * Trim(Temp))

Here is the complete command code

Dim ret As Long
Dim Temp As String * 50
Dim lpAppName As String, lpKeyName As String, lpDefault As String, lpFileName As String

lpAppName = "Precos"
lpKeyName = txtNome.Text
lpDefault = "c:\Util\Lojas\preview.ini"
lpFileName = "c:\Util\Lojas\preview.ini"

ret = GetPrivateProfileString(lpAppName, lpKeyName, lpDefault, Temp, Len(Temp), lpFileName)

If ret = 0 Then
Beep
ElseIf txtQuantidade = "1" Then
lstUnitario.AddItem Trim(Temp)
lstTotal.AddItem ("1 X " & Trim(Temp))
lstProduto.AddItem txtNome.Text
lstQuantidade.AddItem txtQuantidade.Text
Text1.Text = Text1.Text + Trim(Temp)
ElseIf txtQuantidade = "0" Then
MsgBox "Quantidade é igual a 0!!", vbOKOnly, "Erro de Compreensão"
Else
lstUnitario.AddItem Trim(Temp)
lstTotal.AddItem (txtQuantidade.Text & " X " & Trim(Temp) & " = " & txtQuantidade * Trim(Temp))
lstProduto.AddItem txtNome.Text
lstQuantidade.AddItem txtQuantidade.Text
Text1.Text = Text1.Text + (txtQuantidade * Trim(Temp))
End If

Last question: If the Key name I specified to the INI doesn't exists, how could I get to the project say that it not exist? It get a weird bug, saying that the price is the path to the ini.

Very,Very Thanks


------------------
--Alex

Serge
Nov 26th, 1999, 05:57 AM
It happens because you use this:

lpDefault = "c:\Util\Lojas\preview.ini"


Then you use this variable in the GetPrivateProfile API. It means that if it doesn't find the Key it will return lpDefault (which in your case the path to the INI file instead of the value)



------------------

Serge

Software Developer
Serge_Dymkov@vertexinc.com
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)