Ver Mensaje Individual
  #2 (permalink)  
Antiguo 22/10/2012, 09:14
Avatar de lokoman
lokoman
 
Fecha de Ingreso: septiembre-2009
Mensajes: 502
Antigüedad: 14 años, 7 meses
Puntos: 47
Respuesta: manejo avanzado de cadena de caracteres

Hola!!
Aqui tienes una Sub:

Código vb:
Ver original
  1. Private Sub Divide_Archivo()
  2.     Dim Data, I As Double
  3.     Dim myArrayCampos() As String, myArrayValores() As String
  4.     Dim strTabla As String, strInsert As String, strCampo As String, strValor As String
  5.    
  6.     Open App.Path & "\test.txt" For Input As #1
  7.         Do While EOF(1) = False
  8.             Line Input #1, Data
  9.            
  10.             myArrayCampos() = Split(Mid(Data, InStr(1, Data, "{") + 1, _
  11.                             InStr(1, Data, "}") - InStr(1, Data, "{") - 1), "|")
  12.        
  13.             myArrayValores() = Split(Mid(Data, InStr(1, Data, "}") + 17, _
  14.                             (Len(Data)) - (InStr(1, Data, "}") + 17)), "|")
  15.        
  16.         Loop
  17.     Close #1
  18.    
  19. '=COMO ACCEDER A LOS CAMPOS======================================================
  20. '    For I = 0 To UBound(myArrayCampos)
  21. '        Debug.Print myArrayCampos(I)
  22. '    Next
  23.  
  24. '=COMO ACCEDER A LOS VALORES=====================================================
  25. '    For I = 0 To UBound(myArrayValores)
  26. '        Debug.Print myArrayValores(I)
  27. '    Next
  28.  
  29. '=GENERACION DE LA INSTRUCCION "INSERT"==========================================
  30.    strTabla = "TABLA_CLIENTES" 'NOMBRE DE LA TABLA
  31.    
  32.     strInsert = "INSERT INTO " & strTabla & " ("
  33.     For I = 0 To UBound(myArrayCampos)
  34.         strCampo = strCampo & myArrayCampos(I) & ","
  35.     Next
  36.     strCampo = Mid(strCampo, 1, Len(strCampo) - 1)
  37.    
  38.     strInsert = strInsert & strCampo & ") VALUES ("
  39.    
  40.     For I = 0 To UBound(myArrayValores)
  41.         If I = 1 Then
  42.             strValor = strValor & "'" & myArrayValores(I) & "',"
  43.         Else
  44.             strValor = strValor & myArrayValores(I) & ","
  45.         End If
  46.     Next
  47.     strValor = Mid(strValor, 1, Len(strValor) - 1)
  48.    
  49.     strInsert = strInsert & strValor & ")"
  50.    
  51. 'MOSTRAR LA INSTRUCCION "INSERT"
  52.    MsgBox strInsert
  53. End Sub
  54.  
  55. Private Sub cmd_Click()
  56.     Divide_Archivo
  57. End Sub