elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía rápida para descarga de herramientas gratuitas de seguridad y desinfección


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  Otra duda con registros...
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] 2 Ir Abajo Respuesta Imprimir
Autor Tema: Otra duda con registros...  (Leído 4,488 veces)
ToNy_EsP

Desconectado Desconectado

Mensajes: 61


V.I.P Programmer


Ver Perfil
Otra duda con registros...
« en: 2 Junio 2009, 20:40 pm »

Hola a todos, pues me gustaría saber qué código poner para por ejemplo, explico:

Tenemos un form con 1 checkbox (checkbox1) con el Value = 0, abrimos el form1 y marcamos el Checkbox (value = 1) y cierras el programa. Bien, lo que quiero hacer es guardar en el registro o en algún lado de alguna manera, hacer que cuando el checkbox este marcado y se cierra el programa, al abrirse el programa aparezca el checkbox marcado, y si abres de nuevo el programa y desclickas el checkbox (value = 0) y cierras el programa, que al abrirlo de nuevo aparezca el checkbox1 desclickado.

Yo más o menos tengo una idea, pero no sé construir el código :S, más que nada porque no llevo mucho en VB.

Un saludo y gracias de antemano a toda la comunidad ElHacker  ;-) :laugh:


En línea


*Si pasas mucho tiempo pensando sobre una cosa, terminarás por no hacerla (Bruce Lee).
xkiz ™


Desconectado Desconectado

Mensajes: 1.252


Ver Perfil WWW
Re: Otra duda con registros...
« Respuesta #1 en: 2 Junio 2009, 20:44 pm »

un archivo de configuración.ini seria lo mejor
INI Expert


En línea

ToNy_EsP

Desconectado Desconectado

Mensajes: 61


V.I.P Programmer


Ver Perfil
Re: Otra duda con registros...
« Respuesta #2 en: 2 Junio 2009, 21:02 pm »

un archivo de configuración.ini seria lo mejor
INI Expert

Gracias por tu respuesta  :P pero es que el código no lo entiendo :S, nunca he controlado archivos .INI con VB.

Podrias explicarlo un poco por favor?

Gracias de antemano!!  ;-) :laugh:
En línea


*Si pasas mucho tiempo pensando sobre una cosa, terminarás por no hacerla (Bruce Lee).
YST


Desconectado Desconectado

Mensajes: 965


I'm you


Ver Perfil WWW
Re: Otra duda con registros...
« Respuesta #3 en: 2 Junio 2009, 21:35 pm »

Algunas api's que puedes utilizar para el manejo de .ini son:
GetPrivateProfileString
WriteProfileString
WritePrivateProfileString
etc..
En línea



Yo le enseñe a Kayser a usar objetos en ASM
xkiz ™


Desconectado Desconectado

Mensajes: 1.252


Ver Perfil WWW
Re: Otra duda con registros...
« Respuesta #4 en: 2 Junio 2009, 21:40 pm »

bueno, un ejemplo facil :
primero, crea un archivo.ini en el mismo directorio donde esta o va a estar tu exe, llamado config.ini:

Código
  1. [configuracion]
  2. SWidth=5000
  3. SHeight=7800
  4. SLeft=0
  5. STop=1500
  6. sCap=Hola Mundo

bueno ahora la parte de vb6.
1º agrega el modulo bas que esta en ese ejemplo del link que te pase.

en el Form1 pone un TextBox "text1"y agrega este codigo:

Código
  1. Dim INIFile As String
  2. Private Sub Form_Load()
  3. 'se le pasa la ruta del archivo ini para que lo lea
  4. INIFile = App.Path & "\config.ini"
  5.  
  6. Me.Left = GetKeyVal(INIFile, "configuracion", "SLeft")
  7. Me.Top = GetKeyVal(INIFile, "configuracion", "STop")
  8. Me.Width = GetKeyVal(INIFile, "configuracion", "SWidth")
  9. Me.Height = GetKeyVal(INIFile, "configuracion", "SHeight")
  10. Me.Caption = GetKeyVal(INIFile, "configuracion", "SCap")
  11. End Sub
  12.  
  13. Private Sub Form_Unload(Cancel As Integer)
  14. 'se guarda los valores
  15. Call AddToINI(INIFile, "configuracion", "SLeft", Me.Left)
  16. Call AddToINI(INIFile, "configuracion", "STop", Me.Top)
  17. Call AddToINI(INIFile, "configuracion", "SWidth", Me.Width)
  18. Call AddToINI(INIFile, "configuracion", "SHeight", Me.Height)
  19. Call AddToINI(INIFile, "configuracion", "SCap", Text1.Text)
  20. End Sub
  21.  

En línea

ToNy_EsP

Desconectado Desconectado

Mensajes: 61


V.I.P Programmer


Ver Perfil
Re: Otra duda con registros...
« Respuesta #5 en: 2 Junio 2009, 22:59 pm »

Muchas gracias xKiz!!  ;-) ;D me funciona todo de lujo lo del INI, hice esta modificacion (hay una cosilla que no funciona :S):

En el archivo .INI:

Código
  1. [configuracion]
  2. Check3=1
  3.  

En el Form:

Código
  1. Private Sub Form_Initialize()
  2. INIFile = App.Path & "\config.ini"
  3. Check3.Value = GetKeyVal(INIFile, "configuracion", "Check3")
  4. End Sub
  5.  

En el Modulo2 (porque el modulo .bas 1 lo tenia ocupado :S:

Código
  1. 'Not thouroughly commented, comments desribe what each function does.
  2. 'Please see Form1 code to see how to call each function
  3.  
  4. Option Explicit
  5. 'APIs to access INI files and retrieve data
  6. 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
  7. Declare Function WritePrivateProfileString& Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal AppName$, ByVal KeyName$, ByVal keydefault$, ByVal FileName$)
  8.  
  9. Function GetKeyVal(ByVal FileName As String, ByVal Section As String, ByVal Key As String)
  10. 'Returns info from an INI file
  11. Dim RetVal As String, Worked As Integer
  12. If Dir(FileName) = "" Then MsgBox FileName & " not found.", vbCritical, "File Not Found": Exit Function
  13. RetVal = String$(255, 0)
  14. Worked = GetPrivateProfileString(Section, Key, "", RetVal, Len(RetVal), FileName)
  15. If Worked = 0 Then
  16.    GetKeyVal = ""
  17. Else
  18.    GetKeyVal = Left(RetVal, InStr(RetVal, Chr(0)) - 1)
  19. End If
  20. End Function
  21.  
  22. Function AddToINI(ByVal FileName As String, ByVal Section As String, ByVal Key As String, ByVal KeyValue As String) As Integer
  23. 'Add info to an INI file
  24. 'Function returns 1 if successful and 0 if unsuccessful
  25. WritePrivateProfileString Section, Key, KeyValue, FileName
  26. AddToINI = 1
  27. End Function
  28.  
  29. Function DeleteSection(ByVal FileName As String, ByVal Section As String) As Integer
  30. 'Delete an entire section and all it's keys from a given INI file
  31. 'Function returns 1 if successful and 0 if unsuccessful
  32. If Dir(FileName) = "" Then MsgBox FileName & " not found.", vbCritical, "File Not Found": Exit Function
  33. If Not SectionExists(FileName, Section) Then MsgBox "Section, " & Section & ", Not Found. ~(DeleteSection)" & vbCrLf & "Verify spelling and capitilization is correct.  Case-sensative.", vbInformation, "Section Not Found.": Exit Function
  34. WritePrivateProfileString Section, vbNullString, vbNullString, FileName
  35. DeleteSection = 1
  36. End Function
  37.  
  38. Function DeleteKey(ByVal FileName As String, ByVal Section As String, ByVal Key As String) As Integer
  39. 'Delete a key from an INI file
  40. 'Function returns 1 if successful and 0 if unsuccessful
  41. If Dir(FileName) = "" Then MsgBox FileName & " not found.", vbCritical, "File Not Found": Exit Function
  42. If Not SectionExists(FileName, Section) Then MsgBox "Section, " & Section & ", Not Found. ~(DeleteKey)" & vbCrLf & "Verify spelling and capitilization is correct.  Case-sensative.", vbInformation, "Section Not Found.": Exit Function
  43. If Not KeyExists(FileName, Section, Key) Then MsgBox "Key, " & Key & ", Not Found. ~(DeleteKey)" & vbCrLf & "Verify spelling and capitilization is correct.  Case-sensative.", vbInformation, "Key Not Found.": Exit Function
  44. WritePrivateProfileString Section, Key, vbNullString, FileName
  45. DeleteKey = 1
  46. End Function
  47.  
  48. Function DeleteKeyValue(ByVal FileName As String, ByVal Section As String, ByVal Key As String) As Integer
  49. 'Delete a key's value from an INI file
  50. 'Function returns 1 if successful and 0 if unsuccessful
  51. If Dir(FileName) = "" Then MsgBox FileName & " not found.", vbCritical, "File Not Found": Exit Function
  52. If Not SectionExists(FileName, Section) Then MsgBox "Section, " & Section & ", Not Found. ~(DeleteKeyValue)" & vbCrLf & "Verify spelling and capitilization is correct.  Case-sensative.", vbInformation, "Section Not Found.": Exit Function
  53. If Not KeyExists(FileName, Section, Key) Then MsgBox "Key, " & Key & ", Not Found. ~(DeleteKeyValue)" & vbCrLf & "Verify spelling and capitilization is correct.  Case-sensative.", vbInformation, "Key Not Found.": Exit Function
  54. WritePrivateProfileString Section, Key, "", FileName
  55. DeleteKeyValue = 1
  56. End Function
  57.  
  58. Public Function TotalSections(ByVal FileName As String) As Long
  59. 'Returns the total number of sections in a given INI file
  60. Dim Counter As Integer
  61. Dim InputData As String
  62. If Dir(FileName) = "" Then MsgBox FileName & " not found.", vbCritical, "File Not Found": Exit Function
  63. Open FileName For Input As #1
  64.  
  65. Do While Not EOF(1)
  66.    Line Input #1, InputData
  67.    If IsSection(InputData) Then Counter = Counter + 1
  68. Loop
  69. Close #1
  70. TotalSections = Counter
  71. End Function
  72.  
  73. Public Function TotalKeys(ByVal FileName As String) As Long
  74. 'Returns the total number of keys in a given INI file
  75. Dim Counter As Integer
  76. Dim InputData As String
  77. Dim Looper As Integer
  78. If Dir(FileName) = "" Then MsgBox FileName & " not found.", vbCritical, "File Not Found": Exit Function
  79. Open FileName For Input As #2
  80.  
  81. Do While Not EOF(2)
  82.    Line Input #2, InputData
  83.    If IsKey(InputData) Then Counter = Counter + 1
  84. Loop
  85. Close #2
  86. TotalKeys = Counter
  87. End Function
  88.  
  89. Public Function NumKeys(ByVal FileName As String, ByVal Section As String) As Integer
  90. 'Returns the total number of keys in 1 given section.
  91. Dim Counter As Integer
  92. Dim InputData As String
  93. Dim Looper As Integer
  94. Dim InZone As Boolean
  95. If Dir(FileName) = "" Then MsgBox FileName & " not found.", vbCritical, "File Not Found": Exit Function
  96. If Not SectionExists(FileName, Section) Then MsgBox "Section, " & Section & ", Not Found. ~(NumKeys)" & vbCrLf & "Verify spelling and capitilization is correct.  Case-sensative.", vbInformation, "Section Not Found.": Exit Function
  97. InZone = False
  98. Open FileName For Input As #3
  99.  
  100. Do While Not EOF(3)
  101.    Line Input #3, InputData
  102.    If InZone Then
  103.        If IsSection(InputData) Or EOF(3) Then
  104.            If EOF(3) Then
  105.                NumKeys = Counter + 1
  106.                Exit Do
  107.            Else
  108.                NumKeys = Counter
  109.                Exit Do
  110.            End If
  111.        Else
  112.            If IsKey(InputData) Then Counter = Counter + 1
  113.        End If
  114.    Else
  115.        If InputData = "[" & Section & "]" Then
  116.            InZone = True
  117.        End If
  118.    End If
  119. Loop
  120. Close #3
  121. End Function
  122.  
  123. Public Function RenameSection(ByVal FileName As String, ByVal SectionName As String, ByVal NewSectionName As String) As Integer
  124. 'Renames a section in a given INI file.
  125. 'Function returns 1 if successful and 0 if unsuccessful
  126. Dim TopKeys As String
  127. Dim BotKeys As String
  128. Dim Looper As Integer
  129. Dim InputData As String
  130. Dim InZone As Boolean
  131. Dim Key1 As String, Key2 As String
  132. If Dir(FileName) = "" Then MsgBox FileName & " not found.", vbCritical, "File Not Found": Exit Function
  133. If Not SectionExists(FileName, SectionName) Then MsgBox "Section, " & SectionName & ", Not Found. ~(RenameSection)" & vbCrLf & "Verify spelling and capitilization is correct.  Case-sensative.", vbInformation, "Section Not Found.": RenameSection = 0: Exit Function
  134. If SectionExists(FileName, NewSectionName) Then MsgBox NewSectionName & " allready exists.  ~(RenameSection)", vbInformation, "Duplicate Section": RenameSection = 0: Exit Function
  135. Open FileName For Input As #4
  136.  
  137. Do While Not EOF(4)
  138.    Line Input #4, InputData
  139.    If InZone Then
  140.        If BotKeys = "" Then BotKeys = InputData Else BotKeys = BotKeys & vbCrLf & InputData
  141.        If EOF(4) Then
  142.            Close #4
  143.            Kill FileName
  144.            Open FileName For Append As #5
  145.            If TopKeys <> "" Then Print #5, TopKeys
  146.            Print #5, "[" & NewSectionName & "]" & vbCrLf & BotKeys
  147.            Close #5
  148.            RenameSection = 1
  149.            Exit Function
  150.        End If
  151.    Else
  152.        If InputData = "[" & SectionName & "]" Then
  153.            InZone = True
  154.        Else
  155.            If TopKeys = "" Then TopKeys = InputData Else TopKeys = TopKeys & vbCrLf & InputData
  156.        End If
  157.    End If
  158. Loop
  159. Close #4
  160. End Function
  161.  
  162. Public Function RenameKey(ByVal FileName As String, ByVal Section As String, ByVal KeyName As String, ByVal NewKeyName As String) As Integer
  163. 'Renames a key in a given INI file
  164. 'Function returns 1 if successful and 0 if unsuccessful
  165. Dim KeyVal As String
  166. If Dir(FileName) = "" Then MsgBox FileName & " not found.", vbCritical, "File Not Found": RenameKey = 0: Exit Function
  167. If Not SectionExists(FileName, Section) Then MsgBox "Section, " & Section & ", Not Found. ~(RenameKey)" & vbCrLf & "Verify spelling and capitilization is correct.  Case-sensative.", vbInformation, "Section Not Found.": RenameKey = 0: Exit Function
  168. If Not KeyExists(FileName, Section, KeyName) Then MsgBox "Key, " & KeyName & ", Not Found. ~(RenameKey)" & vbCrLf & "Verify spelling and capitilization is correct.  Case-sensative.", vbInformation, "Key Not Found.": RenameKey = 0: Exit Function
  169. If KeyExists(FileName, Section, NewKeyName) Then MsgBox NewKeyName & " allready exists in the section, " & Section & ".  ~(RenameKey)", vbInformation, "Duplicate Key.": RenameKey = 0: Exit Function
  170. KeyVal = GetKeyVal(FileName, Section, KeyName)
  171. DeleteKey FileName, Section, KeyName
  172. AddToINI FileName, Section, NewKeyName, KeyVal
  173. RenameKey = 1
  174. End Function
  175.  
  176. Public Function GetKey(ByVal FileName As String, ByVal Section As String, ByVal KeyIndexNum As Integer) As String
  177. 'This function returns the name of a key which is identified by it's IndexNumber.
  178. 'The Section is identified as Text - GetKey2 identifies Section by it's IndexNumber
  179. 'IndexNumbers begin at 0 and increment up
  180. Dim Counter As Integer
  181. Dim InputData As String
  182. Dim InZone As Boolean
  183. Dim Looper As Integer
  184. Dim KeyName As String
  185. If Dir(FileName) = "" Then MsgBox FileName & " not found.", vbCritical, "File Not Found": Exit Function
  186. If Not SectionExists(FileName, Section) Then MsgBox "Section, " & Section & ", Not Found. ~(GetKey)" & vbCrLf & "Verify spelling and capitilization is correct.  Case-sensative.", vbInformation, "Section Not Found.": Exit Function
  187. If NumKeys(FileName, Section) - 1 < KeyIndexNum Then MsgBox KeyIndexNum & ", not a valid Key Index Number. ~(GetKey)", vbInformation, "Invalid Index Number.": Exit Function
  188.  
  189. Counter = -1
  190. Open FileName For Input As #6
  191. Do While Not EOF(6)
  192.    Line Input #6, InputData
  193.    If InZone Then
  194.        If IsKey(InputData) Then
  195.            Counter = Counter + 1
  196.            If Counter = KeyIndexNum Then
  197.                For Looper = 1 To Len(InputData)
  198.                    If Mid(InputData, Looper, 1) = "=" Then
  199.                        GetKey = KeyName
  200.                        Exit Do
  201.                    Else
  202.                        KeyName = KeyName & Mid(InputData, Looper, 1)
  203.                    End If
  204.                Next Looper
  205.            End If
  206.        End If
  207.    Else
  208.        If InputData = "[" & Section & "]" Then InZone = True
  209.    End If
  210. Loop
  211. Close #6
  212. End Function
  213.  
  214. Public Function GetKey2(ByVal FileName As String, ByVal SectionIndexNum As Integer, ByVal KeyIndexNum As Integer) As String
  215. 'This function returns the name of a key which is identified by it's IndexNumber.
  216. 'The Section is identified by it's IndexNumber
  217. 'IndexNumbers begin at 0 and increment up
  218. Dim Counter As Integer
  219. Dim Counter2 As Integer
  220. Dim InputData As String
  221. Dim InZone As Boolean
  222. Dim Looper As Integer
  223. Dim KeyName As String
  224. If Dir(FileName) = "" Then MsgBox FileName & " not found.", vbCritical, "File Not Found": Exit Function
  225. If TotalSections(FileName) - 1 < SectionIndexNum Then MsgBox SectionIndexNum & ", not a valid Section Index Number. ~(GetKey2)", vbInformation, "Invalid Index Number.": Exit Function
  226. If NumKeys(FileName, GetSection(FileName, SectionIndexNum)) - 1 < KeyIndexNum Then MsgBox KeyIndexNum & ", not a valid Key Index Number. ~(GetKey2)", vbInformation, "Invalid Index Number.": Exit Function
  227. Counter = -1
  228. Counter2 = -1
  229. Open FileName For Input As #7
  230. Do While Not EOF(7)
  231.    Line Input #7, InputData
  232.    If InZone Then
  233.        If IsKey(InputData) Then
  234.            Counter = Counter + 1
  235.            If Counter = KeyIndexNum Then
  236.                For Looper = 1 To Len(InputData)
  237.                    If Mid(InputData, Looper, 1) = "=" Then
  238.                        GetKey2 = KeyName
  239.                        Exit Do
  240.                    Else
  241.                        KeyName = KeyName & Mid(InputData, Looper, 1)
  242.                    End If
  243.                Next Looper
  244.            End If
  245.        End If
  246.    Else
  247.        If IsSection(InputData) Then Counter2 = Counter2 + 1
  248.        If Counter2 = SectionIndexNum Then InZone = True
  249.    End If
  250. Loop
  251. Close #7
  252. End Function
  253.  
  254. Public Function GetSection(ByVal FileName As String, ByVal SectionIndexNum As Integer) As String
  255. 'Returns a section name which is identified by it's indexnumber
  256. 'IndexNumbers begin at 0 and increment up
  257. Dim InputData As String
  258. Dim Counter As Integer
  259. If Dir(FileName) = "" Then MsgBox FileName & " not found.", vbCritical, "File Not Found": Exit Function
  260. If TotalSections(FileName) - 1 < SectionIndexNum Then MsgBox SectionIndexNum & ", not a valid Section Index Number. ~(GetSection)", vbInformation, "Invalid Index Number.": Exit Function
  261. Counter = -1
  262. Open FileName For Input As #8
  263. Do While Not EOF(8)
  264.    Line Input #8, InputData
  265.    If IsSection(InputData) Then
  266.        Counter = Counter + 1
  267.        InputData = Right(InputData, Len(InputData) - 1)
  268.        InputData = Left(InputData, Len(InputData) - 1)
  269.        If Counter = SectionIndexNum Then GetSection = InputData: Exit Do
  270.    End If
  271. Loop
  272. Close #8
  273. End Function
  274.  
  275. Public Function IsKey(ByVal TextLine As String) As Boolean
  276. 'This function determines whether or not a line of text is a valid Key (ex. "This=key")
  277. 'This returns True or False
  278. Dim Looper As Integer
  279. For Looper = 1 To Len(TextLine)
  280.    If Mid(TextLine, Looper, 1) = "=" Then IsKey = True: Exit Function
  281. Next Looper
  282. IsKey = False
  283. End Function
  284.  
  285. Public Function IsSection(ByVal TextLine As String) As Boolean
  286. 'This function determines whether or not a line of text is a
  287. 'valid section (ex. "[section]")
  288. 'This return's True or False
  289. Dim FirstChar As String, LastChar As String
  290. If TextLine = "" Then Exit Function
  291. FirstChar = Mid(TextLine, 1, 1)
  292. LastChar = Mid(TextLine, Len(TextLine), 1)
  293. If FirstChar = "[" And LastChar = "]" Then IsSection = True Else IsSection = False
  294. End Function
  295.  
  296. Public Function KeyExists(ByVal FileName As String, ByVal Section As String, ByVal Key As String) As Boolean
  297. 'This function determines if a key exists in a given section
  298. 'The Section is identified as Text - KeyExists2 identifies Section by its IndexNumber
  299. 'This returns True or False
  300. Dim InZone As Boolean
  301. Dim InputData As String
  302. Dim Looper As Integer
  303. If Dir(FileName) = "" Then MsgBox FileName & " not found.", vbCritical, "File Not Found": Exit Function
  304. If Not SectionExists(FileName, Section) Then MsgBox "Section, " & Section & ", Not Found. ~(KeyExists)" & vbCrLf & "Verify spelling and capitilization is correct.  Case-sensative.", vbInformation, "Section Not Found.": Exit Function
  305. Open FileName For Input As #9
  306. Do While Not EOF(9)
  307.    Line Input #9, InputData
  308.    If InZone Then
  309.        If IsKey(InputData) Then
  310.            If Left(InputData, Len(Key)) = Key Then
  311.                KeyExists = True
  312.                Exit Do
  313.            End If
  314.        ElseIf IsSection(InputData) Then
  315.            KeyExists = False
  316.            Exit Do
  317.        End If
  318.    Else
  319.        If InputData = "[" & Section & "]" Then InZone = True
  320.    End If
  321. Loop
  322. Close #9
  323. End Function
  324.  
  325. Public Function KeyExists2(ByVal FileName As String, ByVal SectionIndexNum As Integer, ByVal Key As String) As Boolean
  326. 'This function determines if a key exists in a given section
  327. 'The Section is identified by its IndexNumber
  328. 'IndexNumbers begin at 0 and increment up
  329. 'This returns True or False
  330. Dim InZone As Boolean
  331. Dim InputData As String
  332. Dim Looper As Integer
  333. Dim Counter As Integer
  334. If Dir(FileName) = "" Then MsgBox FileName & " not found.", vbCritical, "File Not Found": Exit Function
  335. If TotalSections(FileName) - 1 < SectionIndexNum Then MsgBox SectionIndexNum & ", not a valid Section Index Number. ~(KeyExists2)", vbInformation, "Invalid Index Number.": Exit Function
  336. Counter = -1
  337. Open FileName For Input As #10
  338. Do While Not EOF(10)
  339.    Line Input #10, InputData
  340.    If InZone Then
  341.        If IsKey(InputData) Then
  342.            If Left(InputData, Len(Key)) = Key Then
  343.                KeyExists2 = True
  344.                Exit Do
  345.            End If
  346.        ElseIf IsSection(InputData) Then
  347.            KeyExists2 = False
  348.            Exit Do
  349.        End If
  350.    Else
  351.        If IsSection(InputData) Then Counter = Counter + 1
  352.        If Counter = SectionIndexNum Then InZone = True
  353.    End If
  354. Loop
  355. Close #10
  356. End Function
  357.  
  358. Public Function SectionExists(ByVal FileName As String, ByVal Section As String)
  359. 'This determines if a section exists in a given INI file
  360. 'This returns True or False
  361. If Dir(FileName) = "" Then MsgBox FileName & " not found.", vbCritical, "File Not Found": Exit Function
  362. Dim InputData As String
  363. Open FileName For Input As #11
  364. Do While Not EOF(11)
  365.    Line Input #11, InputData
  366.    If "[" & Section & "]" = InputData Then SectionExists = True: Exit Do
  367.    SectionExists = False
  368. Loop
  369. Close #11
  370. End Function
  371.  
  372. Public Function GetSectionIndex(ByVal FileName As String, ByVal Section As String) As Integer
  373. 'This function is used to get the IndexNumber for a given Section
  374. If Dir(FileName) = "" Then MsgBox FileName & " not found.", vbCritical, "File Not Found": Exit Function
  375. If Not SectionExists(FileName, Section) Then MsgBox "Section, " & Section & ", Not Found. ~(GetSectionIndex)" & vbCrLf & "Verify spelling and capitilization is correct.  Case-sensative.", vbInformation, "Section Not Found.": Exit Function
  376. Dim InputData As String
  377. Dim Counter As Integer
  378. Counter = -1
  379. Open FileName For Input As #12
  380. Do While Not EOF(12)
  381.    Line Input #12, InputData
  382.    If IsSection(InputData) Then Counter = Counter + 1
  383.    If "[" & Section & "]" = InputData Then GetSectionIndex = Counter
  384. Loop
  385. Close #12
  386. End Function
  387.  
  388. Public Function GetKeyIndex(ByVal FileName As String, ByVal Section As String, ByVal Key As String) As Integer
  389. 'This function returns the IndexNumber of a key in a given Section
  390. 'The Section is identified as Text - GetKeyIndex2, Section is
  391. 'identified by it's IndexNumber
  392. 'IndexNumbers start at 0 and increment up
  393. If Dir(FileName) = "" Then MsgBox FileName & " not found.", vbCritical, "File Not Found": Exit Function
  394. If Not SectionExists(FileName, Section) Then MsgBox "Section, " & Section & ", Not Found. ~(GetKeyIndex)" & vbCrLf & "Verify spelling and capitilization is correct.  Case-sensative.", vbInformation, "Section Not Found.": Exit Function
  395. If Not KeyExists(FileName, Section, Key) Then MsgBox "Key, " & Key & ", Not Found. ~(GetKetIndex)" & vbCrLf & "Verify spelling and capitilization is correct.  Case-sensative.", vbInformation, "Key Not Found.": Exit Function
  396. Dim InputData As String
  397. Dim InZone As Boolean
  398. Dim Counter As Integer
  399. Counter = -1
  400. Open FileName For Input As #13
  401. Do While Not EOF(13)
  402.    Line Input #13, InputData
  403.    If InZone Then
  404.        If IsKey(InputData) Then
  405.            Counter = Counter + 1
  406.            If Left(InputData, Len(Key)) = Key Then
  407.                GetKeyIndex = Counter
  408.                Exit Do
  409.            End If
  410.        ElseIf IsSection(InputData) Then
  411.            Exit Do
  412.        End If
  413.    Else
  414.        If "[" & Section & "]" = InputData Then InZone = True
  415.    End If
  416. Loop
  417. Close #13
  418. End Function
  419.  
  420. Public Function GetKeyIndex2(ByVal FileName As String, ByVal SectionIndexNum As Integer, ByVal Key As String) As Integer
  421. 'This function returns the IndexNumber of a key in a given Section
  422. 'The Section is identified by it's IndexNumber
  423. 'IndexNumbers start at 0 and increment up
  424. If Dir(FileName) = "" Then MsgBox FileName & " not found.", vbCritical, "File Not Found": Exit Function
  425. If TotalSections(FileName) - 1 < SectionIndexNum Then MsgBox SectionIndexNum & ", not a valid Section Index Number. ~(GetKeyIndex2)", vbInformation, "Invalid Index Number.": Exit Function
  426. If Not KeyExists(FileName, GetSection(FileName, SectionIndexNum), Key) Then MsgBox "Key, " & Key & ", Not Found. ~(GetKetIndex2)" & vbCrLf & "Verify spelling and capitilization is correct.  Case-sensative.", vbInformation, "Key Not Found.": Exit Function
  427. Dim InputData As String
  428. Dim Counter As Integer
  429. Dim Counter2 As Integer
  430. Dim InZone As Boolean
  431. Counter = -1
  432. Counter2 = -1
  433. Open FileName For Input As #14
  434. Do While Not EOF(14)
  435.    Line Input #14, InputData
  436.    If InZone Then
  437.        If IsKey(InputData) Then
  438.            Counter = Counter + 1
  439.            If Left(InputData, Len(Key)) = Key Then
  440.                GetKeyIndex2 = Counter
  441.                Exit Do
  442.            End If
  443.        ElseIf IsSection(InputData) Then
  444.            Exit Do
  445.        End If
  446.    Else
  447.        If IsSection(InputData) Then Counter2 = Counter2 + 1
  448.        If Counter2 = SectionIndexNum Then InZone = True
  449.    End If
  450. Loop
  451. Close #14
  452. End Function
  453.  

Al iniciar el form se pone el check3 clickado, pero cuando lo desclicko y cierro el form y lo vuelvo a abrir el check3 sigue clickado :S, no se guarda :S. Un saludo y muchas gracias!

¿Alguien sabe por qué no funciona?
En línea


*Si pasas mucho tiempo pensando sobre una cosa, terminarás por no hacerla (Bruce Lee).
xkiz ™


Desconectado Desconectado

Mensajes: 1.252


Ver Perfil WWW
Re: Otra duda con registros...
« Respuesta #6 en: 2 Junio 2009, 23:12 pm »

en Form_Unload es donde se guardan los valores, osea vos lo tomas al iniciar la aplicacion, pero te falta guardar el valor, seria asi

Código
  1. Private Sub Form_Unload(Cancel As Integer)
  2.  
  3. ' 1º parametro es el archivo INI
  4. ' 2º parametro es la secion donde esta la clave. (en este case "configuracion"
  5. ' 3º parametro es la clave donde va a guardar el valor
  6. ' 4º parametro es el nuevo valor
  7.  
  8. Call AddToINI(INIFile, "configuracion", "Check3", Check3.Value)
  9. End Sub
En línea

carlitrosss6

Desconectado Desconectado

Mensajes: 18


You know you're right.


Ver Perfil
Re: Otra duda con registros...
« Respuesta #7 en: 3 Junio 2009, 01:15 am »

Si es algo simple,como los valores de los checkbox,no tiene mucha utilidad usar archivos INI.

Aca hice un còdigo que puedes usar,los nombres de los checkbox son tal cual los crea VB (check1,2,3,4):

Este codigo crea un archivo cualquiera (en este caso,configuracion.cfg)y guarda la configuraciòn ahi,despuès lo lee y separa los datos.

Código:

Dim i
Dim sConfig As String
Dim sDelim As String
Dim sTemp As String
Dim sDatos() As String

Private Sub Form_Load()

i = FreeFile 'para abrir el configuracion.cfg
sConfig = App.Path & "\" & "configuracion.cfg" 'nuestro archivo de configuracion
sDelim = "++/++/++" 'asi separamos los valores de cada check

If Not Existe(sConfig) Then FileCopy App.Path & "\" & App.EXEName & ".exe", sConfig 'si no existe nuestro archivo,lo creamos

LeerDatos

End Sub

'verifica si un archivo existe
Public Function Existe(sArchivo As String) As Boolean
On Error Resume Next
If Dir(sArchivo) <> "" Then Existe = True Else Existe = False
End Function

'al momento de cerrar,guardamos nuestro archivo.
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

 Open sConfig For Output As #i
 Print #i, sDelim & CStr(Check1.Value) & sDelim & CStr(Check2.Value) & sDelim & CStr(Check3.Value) & sDelim & CStr(Check4.Value)
 Close #i

End Sub

Function LeerDatos()

On Error Resume Next
Dim n
'abrimos nuestro archivo para leerlo.
Open sConfig For Input As #i
 While Not EOF(i)
  Input #i, sTemp 'todo se guarda aqui
 Wend
Close #i

'separamos todo en un array
sDatos = Split(sTemp, sDelim)
'y asignamos los valores
Check1.Value = sDatos(1)
Check2.Value = sDatos(2)
Check3.Value = sDatos(3)
Check4.Value = sDatos(4)
 
End Function

Saludos! ;D
« Última modificación: 3 Junio 2009, 01:17 am por carlitrosss6 » En línea

Arriba Mèxico!!
43H4FH44H45H4CH49H56H45H
Wiki

Desconectado Desconectado

Mensajes: 502



Ver Perfil
Re: Otra duda con registros...
« Respuesta #8 en: 3 Junio 2009, 13:53 pm »

Podria utilizarse tb SaveSetting y GetSetting (siempre que se tenga permisos para escribir en el registro) asi:
Código
  1. Private Sub Form_Load()
  2. Dim valor As Integer
  3. valor = Val(GetSetting("Programa", "Prueba", "valor", "0"))
  4. If valor = 0 Then
  5. Check1.Value = 0
  6. Else
  7. Check1.Value = 1
  8. End If
  9. End Sub

Código
  1. Private Sub Form_Unload(Cancel As Integer)
  2. If Check1.Value = 0 Then
  3. SaveSetting "Programa", "Prueba", "valor", "0"
  4. Else
  5. SaveSetting "Programa", "Prueba", "valor", "1"
  6. End If
  7. End Sub

Mas info en el MSDN.
En línea


-R IP
:0100
-A 100 
2826:0100 MOV AH,09
2826:0102 MOV DX,109
2826:0105 INT 21
2826:0105 MOV AH,08
2826:0105 INT 21
2826:0107 INT 20
2826:0109 DB 'MI NICK ES CODELIVE.$' 
2826:0127 
-R BX
:0000
-R CX
:20
-N CODELIVE.COM
-W
ToNy_EsP

Desconectado Desconectado

Mensajes: 61


V.I.P Programmer


Ver Perfil
Re: Otra duda con registros...
« Respuesta #9 en: 3 Junio 2009, 16:29 pm »

Si es algo simple,como los valores de los checkbox,no tiene mucha utilidad usar archivos INI.

Aca hice un còdigo que puedes usar,los nombres de los checkbox son tal cual los crea VB (check1,2,3,4):

Este codigo crea un archivo cualquiera (en este caso,configuracion.cfg)y guarda la configuraciòn ahi,despuès lo lee y separa los datos.

Código
  1.  
  2. Dim i
  3. Dim sConfig As String
  4. Dim sDelim As String
  5. Dim sTemp As String
  6. Dim sDatos() As String
  7.  
  8. Private Sub Form_Load()
  9.  
  10. i = FreeFile 'para abrir el configuracion.cfg
  11. sConfig = App.Path & "\" & "configuracion.cfg" 'nuestro archivo de configuracion
  12. sDelim = "++/++/++" 'asi separamos los valores de cada check
  13.  
  14. If Not Existe(sConfig) Then FileCopy App.Path & "\" & App.EXEName & ".exe", sConfig 'si no existe nuestro archivo,lo creamos
  15.  
  16. LeerDatos
  17.  
  18. End Sub
  19.  
  20. 'verifica si un archivo existe
  21. Public Function Existe(sArchivo As String) As Boolean
  22. On Error Resume Next
  23. If Dir(sArchivo) <> "" Then Existe = True Else Existe = False
  24. End Function
  25.  
  26. 'al momento de cerrar,guardamos nuestro archivo.
  27. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  28.  
  29. Open sConfig For Output As #i
  30. Print #i, sDelim & CStr(Check1.Value) & sDelim & CStr(Check2.Value) & sDelim & CStr(Check3.Value) & sDelim & CStr(Check4.Value)
  31. Close #i
  32.  
  33. End Sub
  34.  
  35. Function LeerDatos()
  36.  
  37. On Error Resume Next
  38. Dim n
  39. 'abrimos nuestro archivo para leerlo.
  40. Open sConfig For Input As #i
  41. While Not EOF(i)
  42.  Input #i, sTemp 'todo se guarda aqui
  43. Wend
  44. Close #i
  45.  
  46. 'separamos todo en un array
  47. sDatos = Split(sTemp, sDelim)
  48. 'y asignamos los valores
  49. Check1.Value = sDatos(1)
  50. Check2.Value = sDatos(2)
  51. Check3.Value = sDatos(3)
  52. Check4.Value = sDatos(4)
  53.  
  54. End Function
  55.  

Saludos! ;D

Acabo de probar tu code pero al iniciar la aplicacion me aparece un error: "Run-time-Error 57 File Not Found" y un botón con End, y no me deja de iniciarla :S.

Puse todo bien (los checks, el code...)

Gracias por todo, por cierto xkiz, es que se me olvidó de postear aqui el code de al cerrarse la aplicación :p :S, pero lo tenia puesto también y no va :S, osea, no se quedan guardados los valores, si se arrancan bien pero no se guardan. Probe tambien a meter el code de guardado en el .INI en un timer con interval 1 para que fuese guardando todos los valores constantemente, pero tampoco va...:S

Y 43H4FH44H45H4CH49H56H45H, es que el programa puede correr en una cuenta de usuario que no sea la de Administrador :S, asi que no me vale :SS

Muchas gracias a todos por vuestro interes, me estais ayudando muchisimo.

Un Saludo a la comunidad ElHacker.net  ;)
En línea


*Si pasas mucho tiempo pensando sobre una cosa, terminarás por no hacerla (Bruce Lee).
Páginas: [1] 2 Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[Duda] Registros
ASM
xv0 0 2,307 Último mensaje 25 Octubre 2012, 17:24 pm
por xv0
Duda sobre registros en C++
Programación C/C++
seryioo 1 1,583 Último mensaje 7 Septiembre 2015, 16:51 pm
por ivancea96
[DUDA] Pares de registros
ASM
integeroverflow 5 3,323 Último mensaje 6 Marzo 2017, 17:34 pm
por xv0
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines