Principales respuestas
No se leen todos los datos de un archivo .ini

Pregunta
-
Hola, tengo este código:
Sub getgame() Try GameName.Text = GameNameText & GameList.Text tid = ini.GetKeyValue(GameList.Text, "tid") id = ini.GetKeyValue(GameList.Text, "id") gamelocation = ini.GetKeyValue(GameList.Text, "location") GameRegion.Text = GameRegionText & ini.GetKeyValue(GameList.Text, "region") ReleaseDate.Text = ReleaseDateText & ini.GetKeyValue(GameList.Text, "releasedate") If ini.GetKeyValue(GameList.Text, "runtime") = "true" Or ini.GetKeyValue(GameList.Text, "runtime") = "minimal" Then Requieres3dsruntime.Text = Requires3dsruntimeText & "minimal" Requieres3dsruntime.Visible = True ElseIf ini.GetKeyValue(GameList.Text, "runtime") = "kbd" Then Requieres3dsruntime.Text = Requires3dsruntimeText & "kbd" Requieres3dsruntime.Visible = True Else Requieres3dsruntime.Text = "" Requieres3dsruntime.Visible = False End If _Icon.Image = Image.FromFile("cache\" & GameList.Text & ".png") Download.Enabled = True Catch ex As Exception MsgBox(ex.ToString) End Try Label3.Text = tid & Environment.NewLine & id End Sub
Pero el resultado es este:
y el archivo es este:
[Rabi Laby 3]
tid=00040000000FCC00
id=JR3P
name=Rabi Laby 3
icon=https://raw.githubusercontent.com/acnleditor2/3dsgamesicons/master/Rabi Laby 3.icon.png
region=EUR
releasedate=2014
location=no comparto esto
runtime=minimal
[Tomodachi Life]
tid=000400000008C400
id=EC6P
name=Tomodachi Life
icon=https://raw.githubusercontent.com/acnleditor2/3dsgamesicons/master/Tomodachi Life.icon.png
region=EUR
releasedate=2013
location=no comparto esto
runtime=false
[Pokemon Mystery Dungeon Gates to Infinity]
tid=00040000000BA900
id=APDP
name=Pokemon Mystery Dungeon Gates to Infinity
icon=https://raw.githubusercontent.com/acnleditor2/3dsgamesicons/master/Pokemon Mystery Dungeon Gates to Infinity.icon.png
region=EUR
releasedate=2012
location=no comparto esto
runtime=minimal
[Kirby's Blowout Blast]
tid=0004000000196F00
id=JHUA
name=Kirby's Blowout Blast
icon=https://raw.githubusercontent.com/acnleditor2/3dsgamesicons/master/Kirby's Blowout Blast.icon.png
region=EUR
releasedate=2017
location=no comparto esto
runtime=true
[Nintendogs + Cats Golden Retriever & New Friends]
tid=0004000000030C00
id=ADAP
name=Nintendogs + Cats Golden Retriever & New Friends
icon=https://raw.githubusercontent.com/acnleditor2/3dsgamesicons/master/Nintendogs + Cats Golden Retriever & New Friends.icon.png
region=EUR
releasedate=2011
location=no comparto esto
runtime=false
[SUPER MARIO 3D LAND]
tid=0004000000053F00
id=AREP
name=SUPER MARIO 3D LAND
icon=https://raw.githubusercontent.com/acnleditor2/3dsgamesicons/master/SUPER MARIO 3D LAND.icon.png
region=EUR
releasedate=2011
location=no comparto esto
runtime=true
[2 Fast 4 Gnomz]
tid=00040000000BCE00
id=JT4P
name=2 Fast 4 Gnomz
icon=https://raw.githubusercontent.com/acnleditor2/3dsgamesicons/master/2 Fast 4 Gnomz.icon.PNG
region=EUR
releasedate=2012
location=no comparto esto
runtime=true
[Mutant Mudds Super Challenge]
tid=000400000018AC00
id=KMMP
name=Mutant Mudds Super Challenge
icon=https://raw.githubusercontent.com/acnleditor2/3dsgamesicons/master/Mutant Mudds Super Challenge.icon.png
region=EUR
releasedate=2015
location=no comparto esto
runtime=true
[35 Junior Games]
tid=00040000000C3200
id=AJCZ
name=35 Junior Games
icon=https://raw.githubusercontent.com/acnleditor2/3dsgamesicons/master/35 Junior Games.icon.PNG
region=EUR
releasedate=2013
location=no comparto esto
runtime=true
[Art of Balance TOUCH!]
tid=000400000008F000
id=JABP
name=Art of Balance TOUCH!
icon=https://raw.githubusercontent.com/acnleditor2/3dsgamesicons/master/Art of Balance TOUCH!.icon.PNG
region=EUR
releasedate=2012
location=no comparto esto
runtime=true
[Skater Cat]
tid=00040000000ECB00
id=JMYP
name=Skater Cat
icon=https://raw.githubusercontent.com/acnleditor2/3dsgamesicons/master/Skater Cat.icon.PNG
region=EUR
releasedate=2014
location=no comparto esto
runtime=true
[Mutant Mudds]
tid=00040002000A5401
id=JMDP
name=Mutant Mudds
icon=https://raw.githubusercontent.com/acnleditor2/3dsgamesicons/master/Mutant Mudds.icon.PNG
region=EUR
releasedate=2012
location=no comparto esto
runtime=true
[Word Search by POWGI]
tid=0004000000169300
id=KWBP
name=Word Search by POWGI
icon=https://raw.githubusercontent.com/acnleditor2/3dsgamesicons/master/Word Search by POWGI.icon.PNG
region=EUR
releasedate=2015
location=no comparto esto
runtime=true
[2048]
tid=0004000000143D00
id=JFEP
name=2048
icon=https://raw.githubusercontent.com/acnleditor2/3dsgamesicons/master/2048.icon.PNG
region=EUR
releasedate=2014
location=no comparto esto
runtime=true
[Picross e7]
tid=00040000001AD600
id=KPAP
name=Picross e7
icon=https://raw.githubusercontent.com/acnleditor2/3dsgamesicons/master/Picross e7.icon.png
region=EUR
releasedate=2016
location=no comparto esto
runtime=true
[Picross e6]
tid=000400000016E800
id=KP6P
name=Picross e6
icon=https://raw.githubusercontent.com/acnleditor2/3dsgamesicons/master/Picross e6.icon.png
region=EUR
releasedate=2014
location=no comparto esto
runtime=true
[Picross e5]
tid=000400000014D200
id=KPQP
name=Picross e5
icon=https://raw.githubusercontent.com/acnleditor2/3dsgamesicons/master/Picross e5.icon.png
region=EUR
releasedate=2014
location=no comparto esto
runtime=true
[Picross e4]
tid=000400000016E800
id=KP6P
name=Picross e4
icon=https://raw.githubusercontent.com/acnleditor2/3dsgamesicons/master/Picross e4.icon.png
region=EUR
releasedate=2013
location=no comparto esto
runtime=true
[Picross e3]
tid=0004000000102900
id=JETP
name=Picross e3
icon=https://raw.githubusercontent.com/acnleditor2/3dsgamesicons/master/Picross e3.icon.png
region=EUR
releasedate=2013
location=no comparto esto
runtime=true
[Picross e2]
tid=00040000000CBC00
id=JP2P
name=Picross e2
icon=https://raw.githubusercontent.com/acnleditor2/3dsgamesicons/master/Picross e2.icon.png
region=EUR
releasedate=2011
location=no comparto esto
runtime=true
[Picross e]
tid=00040000000A9200
id=JEXP
name=Picross e
icon=https://raw.githubusercontent.com/acnleditor2/3dsgamesicons/master/Picross e.icon.png
region=EUR
releasedate=2011
location=no comparto esto
runtime=true
[Miitopia]
tid=00040000001B4F00
id=ADQP
name=Miitopia
icon=https://raw.githubusercontent.com/acnleditor2/3dsgamesicons/master/Miitopia.icon.png
region=EUR
releasedate=2017
location=no comparto esto
runtime=falseAyuda!
Respuestas
-
Hola, puedes tener una clase que haga uso de kernrl32.dll y usar la función GetPrivateProfileString.
Un ejemplo de clase (para escribir o leer una clave del archivo .ini)
Class INIFile Private m_filePath As String <DllImport("kernel32")> _ Private Shared Function WritePrivateProfileString(section As String, key As String, val As String, filePath As String) As Long End Function <DllImport("kernel32")> _ Private Shared Function GetPrivateProfileString(section As String, key As String, def As String, retVal As StringBuilder, size As Integer, filePath As String) As Integer End Function Public Sub New(filePath As String) Me.m_filePath = filePath End Sub Public Sub Write(section As String, key As String, value As String) WritePrivateProfileString(section, key, value.ToLower(), Me.m_filePath) End Sub Public Function Read(section As String, key As String) As String Dim SB As New StringBuilder(255) Dim i As Integer = GetPrivateProfileString(section, key, "", SB, 255, Me.m_filePath) Return SB.ToString() End Function Public Property FilePath() As String Get Return Me.m_filePath End Get Set Me.m_filePath = value End Set End Property End Class
Luego el uso sería
Dim iniFile As New INIFile("tu ruta del .ini") iniFile.Write("tuSecccion", "clave", "valor") Console.WriteLine("el valor es:"+iniFile.Read("tuSeccion", "clave"))
Si se solucionó tu consulta no olvides marcar la respuesta. Si te ayudó, vótala como útil. Saludos
- Propuesto como respuesta Jorge TurradoMVP martes, 29 de agosto de 2017 20:59
- Marcado como respuesta Enrique M. MontejoModerator jueves, 31 de agosto de 2017 6:34
Todas las respuestas
-
Buenas compañero,
Podrías indicarnos también la clase a la que pertenece "ini" y su contenido? Puede ser un problema al indicar el path del fichero .ini, ya que el código parece correcto si efectivamente GameList.Text tiene la sección bien escrita.
Atte
No olvides votar si mi comentario te ha ayudado y marcarlo como respuesta si ha sido la solución!
- Propuesto como respuesta Moderador MModerator lunes, 28 de agosto de 2017 22:40
-
Hola, puedes tener una clase que haga uso de kernrl32.dll y usar la función GetPrivateProfileString.
Un ejemplo de clase (para escribir o leer una clave del archivo .ini)
Class INIFile Private m_filePath As String <DllImport("kernel32")> _ Private Shared Function WritePrivateProfileString(section As String, key As String, val As String, filePath As String) As Long End Function <DllImport("kernel32")> _ Private Shared Function GetPrivateProfileString(section As String, key As String, def As String, retVal As StringBuilder, size As Integer, filePath As String) As Integer End Function Public Sub New(filePath As String) Me.m_filePath = filePath End Sub Public Sub Write(section As String, key As String, value As String) WritePrivateProfileString(section, key, value.ToLower(), Me.m_filePath) End Sub Public Function Read(section As String, key As String) As String Dim SB As New StringBuilder(255) Dim i As Integer = GetPrivateProfileString(section, key, "", SB, 255, Me.m_filePath) Return SB.ToString() End Function Public Property FilePath() As String Get Return Me.m_filePath End Get Set Me.m_filePath = value End Set End Property End Class
Luego el uso sería
Dim iniFile As New INIFile("tu ruta del .ini") iniFile.Write("tuSecccion", "clave", "valor") Console.WriteLine("el valor es:"+iniFile.Read("tuSeccion", "clave"))
Si se solucionó tu consulta no olvides marcar la respuesta. Si te ayudó, vótala como útil. Saludos
- Propuesto como respuesta Jorge TurradoMVP martes, 29 de agosto de 2017 20:59
- Marcado como respuesta Enrique M. MontejoModerator jueves, 31 de agosto de 2017 6:34
-