Dim array As Byte() = Convert.FromBase64String("AQAB")
Dim hex As String = BitConverter.ToString(array).Replace("-", String.Empty)
Dim n As Integer = Val("&H" & hex)
Dim n1 As Integer = Val("&H" & BitConverter.ToString(Convert.FromBase64String("AQAB")).Replace("-", String.Empty))
fuente1
fuente2
miércoles, 19 de diciembre de 2018
buscar y reemplazar saltos de línea y retorno en notepad
miércoles, 5 de diciembre de 2018
Atributos certificado
CN
: CommonNameOU
: OrganizationalUnitO
: OrganizationL
: LocalityS
: StateOrProvinceNameC
: CountryName
miércoles, 28 de noviembre de 2018
día de la semana
Dim i As Integer = DateTime.Now.DayOfWeek
cambiar db_owner a dbo
ejemplo:
tabla: db_owner.clientes
ALTER SCHEMA dbo TRANSFER db_owner.clientes
tabla: dbo.clientes
tabla: db_owner.clientes
ALTER SCHEMA dbo TRANSFER db_owner.clientes
tabla: dbo.clientes
martes, 27 de noviembre de 2018
jueves, 22 de noviembre de 2018
nombre del archivo
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Dim nombre As String = "DTE(id_DTE)100.xyz(0001).xml"
Dim nombre As String = "DTE(tipo_DTE)(folio).(x)xml"
Dim x As New ArrayList
Dim dato As String = ""
Dim n As Integer = nombre.Length ' 28
Dim j As Integer = 0
Dim k As Integer = 0
For i As Integer = 0 To nombre.Length - 1
If nombre(i) = "(" Then
For j = i To nombre.Length - 1
dato += nombre(j)
If nombre(j) = ")" Then
x.Add(dato)
dato = ""
i = j
Exit For
End If
Next
Else
For k = i To nombre.Length - 1
If nombre(k) = "(" Then
x.Add(dato)
i = k - 1
dato = ""
Exit For
Else
dato += nombre(k)
i = k
If i = nombre.Length - 1 Then
x.Add(dato)
i = k
dato = ""
Exit For
End If
End If
Next
End If
Next
MessageBox.Show("!")
End Sub
End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Dim nombre As String = "DTE(id_DTE)100.xyz(0001).xml"
Dim nombre As String = "DTE(tipo_DTE)(folio).(x)xml"
Dim x As New ArrayList
Dim dato As String = ""
Dim n As Integer = nombre.Length ' 28
Dim j As Integer = 0
Dim k As Integer = 0
For i As Integer = 0 To nombre.Length - 1
If nombre(i) = "(" Then
For j = i To nombre.Length - 1
dato += nombre(j)
If nombre(j) = ")" Then
x.Add(dato)
dato = ""
i = j
Exit For
End If
Next
Else
For k = i To nombre.Length - 1
If nombre(k) = "(" Then
x.Add(dato)
i = k - 1
dato = ""
Exit For
Else
dato += nombre(k)
i = k
If i = nombre.Length - 1 Then
x.Add(dato)
i = k
dato = ""
Exit For
End If
End If
Next
End If
Next
MessageBox.Show("!")
End Sub
End Class
miércoles, 14 de noviembre de 2018
xmloptions
Imports System.Xml
Public Class Form1
Public archivo As String = "cfg.xml"
Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
Dim doc As New XmlDocument
doc.Load(archivo)
Dim tablas As XmlNodeList = doc.SelectNodes("/Data/TCV/tabla") ' cargar tablas
Dim campos As XmlNodeList = doc.SelectNodes("/Data/TCV/campo/id") ' cargar todos los campos
For Each x As XmlNode In campos
MessageBox.Show(x.InnerXml)
Next
End Sub
Private Sub btnvervar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnvervar.Click
Dim campo As String = "test2"
Dim doc As New XmlDocument
doc.Load(archivo)
Dim nodes As XmlNodeList = doc.SelectNodes("/Data/TCV")
For Each x As XmlNode In nodes
Dim nodevar As XmlNodeList = x.SelectNodes("campo/id")
For Each node As XmlNode In nodevar
If node.InnerXml = campo Then
Dim var As XmlNodeList = node.ParentNode.SelectNodes("variables/var")
For Each elem As XmlNode In var
MessageBox.Show(elem.InnerXml)
Next
Exit For
End If
Next
Next
End Sub
Private Sub btneliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btneliminar.Click
Dim tabla As String = "DoctosFE"
Dim doc As New XmlDocument
doc.Load(archivo)
Dim xpath As String = "/Data/TCV[tabla=""" & tabla & """]"
Dim del As XmlElement = doc.SelectSingleNode(xpath)
del.ParentNode.RemoveChild(del)
doc.Save(archivo)
End Sub
Public Class Form1
Public archivo As String = "cfg.xml"
Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
Dim doc As New XmlDocument
doc.Load(archivo)
Dim tablas As XmlNodeList = doc.SelectNodes("/Data/TCV/tabla") ' cargar tablas
Dim campos As XmlNodeList = doc.SelectNodes("/Data/TCV/campo/id") ' cargar todos los campos
For Each x As XmlNode In campos
MessageBox.Show(x.InnerXml)
Next
End Sub
Private Sub btnvervar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnvervar.Click
Dim campo As String = "test2"
Dim doc As New XmlDocument
doc.Load(archivo)
Dim nodes As XmlNodeList = doc.SelectNodes("/Data/TCV")
For Each x As XmlNode In nodes
Dim nodevar As XmlNodeList = x.SelectNodes("campo/id")
For Each node As XmlNode In nodevar
If node.InnerXml = campo Then
Dim var As XmlNodeList = node.ParentNode.SelectNodes("variables/var")
For Each elem As XmlNode In var
MessageBox.Show(elem.InnerXml)
Next
Exit For
End If
Next
Next
End Sub
Private Sub btneliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btneliminar.Click
Dim tabla As String = "DoctosFE"
Dim doc As New XmlDocument
doc.Load(archivo)
Dim xpath As String = "/Data/TCV[tabla=""" & tabla & """]"
Dim del As XmlElement = doc.SelectSingleNode(xpath)
del.ParentNode.RemoveChild(del)
doc.Save(archivo)
End Sub
martes, 13 de noviembre de 2018
transformar de arraylist a array
Dim array As new Arraylist
array.ToArray(GetType(System.String))
array.ToArray(GetType(System.String))
editar eliminar nodos xml
Imports System.Xml
Public Class Form1
Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
Dim doc As New XmlDocument
doc.Load("archivo.xml")
'For Each node As XmlNode In doc.GetElementsByTagName("tcv")
' 'MessageBox.Show(node.OuterXml)
' If node.Name = "folio" Then
' MessageBox.Show("!")
' End If
'Next
Dim nodes As XmlNodeList = doc.SelectNodes("data/tcv")
For Each node As XmlNode In nodes
'MessageBox.Show("TAbla:" & node("tabla").InnerText & " " & "campo:" & node("campo").InnerText)
Dim str As String = node.OuterXml
'Dim x As XmlElement = node.ParentNode
doc.LoadXml(str)
Dim varnodes As XmlNode = doc.SelectSingleNode("tcv/variables")
'MessageBox.Show(node.OuterXml)
Next
'doc.Save("archivo.xml")
End Sub
End Class
<?xml version="1.0" encoding="utf-8"?>
<data>
<tcv>
<tabla>hist_DTE</tabla>
<campo>tipo_DTE</campo>
<var1>mitipodte=33</var1>
</tcv>
<tcv>
<tabla>DTE_recibos</tabla>
<campo>folio</campo>
<variables>
<var>foliodeldte=68976</var>
<var>foliodeldte=68976</var>
</variables>
</tcv>
</data>
Public Class Form1
Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
Dim doc As New XmlDocument
doc.Load("archivo.xml")
'For Each node As XmlNode In doc.GetElementsByTagName("tcv")
' 'MessageBox.Show(node.OuterXml)
' If node.Name = "folio" Then
' MessageBox.Show("!")
' End If
'Next
Dim nodes As XmlNodeList = doc.SelectNodes("data/tcv")
For Each node As XmlNode In nodes
'MessageBox.Show("TAbla:" & node("tabla").InnerText & " " & "campo:" & node("campo").InnerText)
Dim str As String = node.OuterXml
'Dim x As XmlElement = node.ParentNode
doc.LoadXml(str)
Dim varnodes As XmlNode = doc.SelectSingleNode("tcv/variables")
'MessageBox.Show(node.OuterXml)
Next
'doc.Save("archivo.xml")
End Sub
End Class
<?xml version="1.0" encoding="utf-8"?>
<data>
<tcv>
<tabla>hist_DTE</tabla>
<campo>tipo_DTE</campo>
<var1>mitipodte=33</var1>
</tcv>
<tcv>
<tabla>DTE_recibos</tabla>
<campo>folio</campo>
<variables>
<var>foliodeldte=68976</var>
<var>foliodeldte=68976</var>
</variables>
</tcv>
</data>
lunes, 12 de noviembre de 2018
Editar nodo xml
Public Sub guardar_conex(ByVal conex As String)
Dim nodo As String = "Data/Conex"
Dim doc As New XmlDocument
doc.Load(archivo.config)
doc.SelectSingleNode(nodo).InnerText = conex
doc.Save(archivo.config)
End Sub
Dim nodo As String = "Data/Conex"
Dim doc As New XmlDocument
doc.Load(archivo.config)
doc.SelectSingleNode(nodo).InnerText = conex
doc.Save(archivo.config)
End Sub
jueves, 8 de noviembre de 2018
extraer datos entre parentesis
Dim x As String = "campo()"
x = x.Split("(")(1)
x = x.TrimEnd(")")
x = x.Split("(")(1)
x = x.TrimEnd(")")
extraer dato entre paréntesis
dato(12345,5678)
Dim x() As String = dato.Split(New String() {"(", ")"}, StringSplitOptions.RemoveEmptyEntries)
R: 12345,5678
fuente
Obtener nombre de la base de datos
Public Function obtener_base_de_datos(ByVal conex As String) As String
Dim data() As String = conex.Split(";")
Return Array.Find(data, Function(x) x.ToString.Contains("Catalog")).Split("=")(1).Trim
End Function
Dim data() As String = conex.Split(";")
Return Array.Find(data, Function(x) x.ToString.Contains("Catalog")).Split("=")(1).Trim
End Function
cómo saber si una tabla existe
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = N'tabla'
miércoles, 7 de noviembre de 2018
Matchcollection to array
Dim matches As MatchCollection = Regex.Matches(query, "(?<=from|join|FROM|JOIN)(\s+\w+\b)")
Dim tablas() As String = matches.Cast(Of Match).Select(Function(y As Match) y.Value).ToArray
Dim tablas() As String = matches.Cast(Of Match).Select(Function(y As Match) y.Value).ToArray
regex matches to array
Dim matches As System.Text.RegularExpressions.MatchCollection = System.Text.RegularExpressions.Regex.Matches(query, "(?<=from|join|FROM|JOIN)(\s+\w+\b)")
Dim matches() As System.Text.RegularExpressions.Match = System.Text.RegularExpressions.Regex.Matches(query, "(?<=from|join|FROM|JOIN)(\s+\w+\b)").Cast(Of System.Text.RegularExpressions.Match)().ToArray
For Each m As System.Text.RegularExpressions.Match In System.Text.RegularExpressions.Regex.Matches(query, "(?<=from|join|FROM|JOIN)(\s+\w+\b)")
MsgBox(m.Value)
Next
Otro ejemplo
Dim lista_match As MatchCollection = Regex.Matches(query, "(?<=from|join|FROM|JOIN)(\s+\w+\b)")
Dim x() As String = lista_match.Cast(Of Match).Select(Function(y As Match) y.Value).ToArray
Para extraer una sola tabla
Dim tabla_sql As String = System.Text.RegularExpressions.Regex.Match(query, "(?<=from|join|FROM|JOIN)(\s+\w+\b)").Value.Trim
fuente
Dim matches() As System.Text.RegularExpressions.Match = System.Text.RegularExpressions.Regex.Matches(query, "(?<=from|join|FROM|JOIN)(\s+\w+\b)").Cast(Of System.Text.RegularExpressions.Match)().ToArray
For Each m As System.Text.RegularExpressions.Match In System.Text.RegularExpressions.Regex.Matches(query, "(?<=from|join|FROM|JOIN)(\s+\w+\b)")
MsgBox(m.Value)
Next
Otro ejemplo
Dim lista_match As MatchCollection = Regex.Matches(query, "(?<=from|join|FROM|JOIN)(\s+\w+\b)")
Dim x() As String = lista_match.Cast(Of Match).Select(Function(y As Match) y.Value).ToArray
Para extraer una sola tabla
Dim tabla_sql As String = System.Text.RegularExpressions.Regex.Match(query, "(?<=from|join|FROM|JOIN)(\s+\w+\b)").Value.Trim
fuente
lunes, 5 de noviembre de 2018
valores de columna y verificar si hay valores fuera de rango
errores base de datos y reparar
DBCC CHECKDB ([nombre_base_de_datos])
base de datos en modo single user o multi user
SELECT user_access_desc FROM sys.databases WHERE name = 'nombre_base_de_datos'
fuente1
fuente2
miércoles, 31 de octubre de 2018
número notación cientifica
Dim number As Double = 0.000009
Dim defaulnumber As String = number.ToString
Dim numerFromString As String = number.ToString("N6")
Dim numberFromStringFormat As String = String.Format("{0:F6}", number)
Dim defaulnumber As String = number.ToString
Dim numerFromString As String = number.ToString("N6")
Dim numberFromStringFormat As String = String.Format("{0:F6}", number)
martes, 30 de octubre de 2018
Dataset
Dim ds As DataSet = get_dataset()
Public Function get_dataset() As DataSet
Dim con As New SqlConnection(conex)
Dim adapter As SqlDataAdapter = Nothing
Dim ds As New DataSet()
Dim query As String = "query sql"
con.Open()
Using cmd As New SqlCommand(query, con)
cmd.Parameters.Add("@parametro1", SqlDbType.VarChar).Value = ""
cmd.Parameters.Add("@parametro2", SqlDbType.VarChar).Value = ""
adapter = New SqlDataAdapter(cmd)
adapter.Fill(ds)
End Using
con.Close()
Return ds
End Function
Public Function get_dataset() As DataSet
Dim con As New SqlConnection(conex)
Dim adapter As SqlDataAdapter = Nothing
Dim ds As New DataSet()
Dim query As String = "query sql"
con.Open()
Using cmd As New SqlCommand(query, con)
cmd.Parameters.Add("@parametro1", SqlDbType.VarChar).Value = ""
cmd.Parameters.Add("@parametro2", SqlDbType.VarChar).Value = ""
adapter = New SqlDataAdapter(cmd)
adapter.Fill(ds)
End Using
con.Close()
Return ds
End Function
lunes, 29 de octubre de 2018
Check ListBox
https://www.youtube.com/watch?v=VSpvB8KmCBQ
Array vacío (nada)
If array Is Nothing then
End If
End If
Eliminar registro array
Dim variables() As String ={"a","b"}
Dim eliminar As String = "a"
variables = variables.Where(Function(x) x <> eliminar ).ToArray
fuente
Dim eliminar As String = "a"
variables = variables.Where(Function(x) x <> eliminar ).ToArray
fuente
jueves, 25 de octubre de 2018
mensajes error sql
select * from master.dbo.sysmessages
select * from master.dbo.sysmessages where error=102
select * from master.dbo.sysmessages where msglangid=3082
select @@LANGID
SELECT name, alias
FROM sys.syslanguages
SELECT * FROM sys.syslanguages
fuente
fuente2
select * from master.dbo.sysmessages where error=102
select * from master.dbo.sysmessages where msglangid=3082
select @@LANGID
SELECT name, alias
FROM sys.syslanguages
SELECT * FROM sys.syslanguages
fuente
fuente2
Descargar dlls
https://www.zhaodll.co/
http://www.zhaodll.com/
http://www.zhaodll.com/
Schema.ScriptDom
X:\Program Files\Microsoft Visual Studio 10.0\VSTSDB
Microsoft.Data.Schema.ScriptDom.dll
Microsoft.Data.Schema.ScriptDom.Sql.dll
Microsoft.Data.Schema.ScriptDom.dll
Microsoft.Data.Schema.ScriptDom.Sql.dll
sqldbtype enum
Public Function value_Type(ByVal sql_dbtype As String) As Integer
Select Case sql_dbtype
Case "bigint"
Return 0
Case "binary"
Return 1
Case "bit"
Return 2
Case "char"
Return 3
Case "date"
Return 31
Case "datetime"
Return 4
Case "datetime2"
Return 33
Case "datetimeoffset"
Return 34
Case "decimal"
Return 5
Case "float"
Return 6
Case "image"
Return 7
Case "int"
Return 8
Case "money"
Return 9
Case "nchar"
Return 10
Case "ntext"
Return 11
Case "nvarchar"
Return 12
Case "real"
Return 13
Case "smalldatetime"
Return 15
Case "smallint"
Return 16
Case "smallmoney"
Return 17
Case "structured"
Return 30
Case "text"
Return 18
Case "time"
Return 32
Case "timestamp"
Return 19
Case "tinyint"
Return 20
Case "udt"
Return 29
Case "uniqueidentifier"
Return 14
Case "varbinary"
Return 21
Case "varchar"
Return 22
Case "variant"
Return 23
Case "xml"
Return 25
Case Else
Return -1
End Select
End Function
fuente
Select Case sql_dbtype
Case "bigint"
Return 0
Case "binary"
Return 1
Case "bit"
Return 2
Case "char"
Return 3
Case "date"
Return 31
Case "datetime"
Return 4
Case "datetime2"
Return 33
Case "datetimeoffset"
Return 34
Case "decimal"
Return 5
Case "float"
Return 6
Case "image"
Return 7
Case "int"
Return 8
Case "money"
Return 9
Case "nchar"
Return 10
Case "ntext"
Return 11
Case "nvarchar"
Return 12
Case "real"
Return 13
Case "smalldatetime"
Return 15
Case "smallint"
Return 16
Case "smallmoney"
Return 17
Case "structured"
Return 30
Case "text"
Return 18
Case "time"
Return 32
Case "timestamp"
Return 19
Case "tinyint"
Return 20
Case "udt"
Return 29
Case "uniqueidentifier"
Return 14
Case "varbinary"
Return 21
Case "varchar"
Return 22
Case "variant"
Return 23
Case "xml"
Return 25
Case Else
Return -1
End Select
End Function
fuente
Tipo de dato INFORMATION_SCHEMA.COLUMNS
TABLE_CATALOG | nvarchar(128) | Table qualifier. |
TABLE_SCHEMA | nvarchar(128) | Name of schema that contains the table. |
TABLE_NAME | nvarchar(128) | Table name. |
COLUMN_NAME | nvarchar(128) | Column name. |
ORDINAL_POSITION | int | Column identification number.
Note: In SQL Server 2005, these column IDs are consecutive numbers.
|
COLUMN_DEFAULT | nvarchar(4000) | Default value of the column. |
IS_NULLABLE | varchar(3) | Nullability of the column. If this column allows for NULL, this column returns YES. Otherwise, NO is returned. |
DATA_TYPE | nvarchar(128) | System-supplied data type. |
CHARACTER_MAXIMUM_LENGTH | int | Maximum length, in characters, for binary data, character data, or text and image data.
-1 for xml and large-value type data. Otherwise, NULL is returned. For more information, see Data Types (Transact-SQL).
|
CHARACTER_OCTET_LENGTH | int | Maximum length, in bytes, for binary data, character data, or text and image data.
-1 for xml and large-value type data. Otherwise, NULL is returned.
|
NUMERIC_PRECISION | tinyint | Precision of approximate numeric data, exact numeric data, integer data, or monetary data. Otherwise, NULL is returned. |
NUMERIC_PRECISION_RADIX | smallint | Precision radix of approximate numeric data, exact numeric data, integer data, or monetary data. Otherwise, NULL is returned. |
NUMERIC_SCALE | int | Scale of approximate numeric data, exact numeric data, integer data, or monetary data. Otherwise, NULL is returned. |
DATETIME_PRECISION | smallint | Subtype code for datetime and SQL-92 interval data types. For other data types, NULL is returned. |
CHARACTER_SET_CATALOG | nvarchar(128) | Returns master. This indicates the database in which the character set is located, if the column is character data or textdata type. Otherwise, NULL is returned. |
CHARACTER_SET_SCHEMA | nvarchar(128) | Always returns NULL. |
CHARACTER_SET_NAME | nvarchar(128) | Returns the unique name for the character set if this column is character data or text data type. Otherwise, NULL is returned. |
COLLATION_CATALOG | nvarchar(128) | Always returns NULL. |
COLLATION_SCHEMA | nvarchar(128) | Always returns NULL. |
COLLATION_NAME | nvarchar(128) | Returns the unique name for the collation if the column is character data or text data type. Otherwise, NULL is returned. |
DOMAIN_CATALOG | nvarchar(128) | If the column is an alias data type, this column is the database name in which the user-defined data type was created. Otherwise, NULL is returned. |
DOMAIN_SCHEMA | nvarchar(128) | If the column is a user-defined data type, this column returns the name of the schema of the user-defined data type. Otherwise, NULL is returned. |
DOMAIN_NAME | nvarchar(128) | If the column is a user-defined data type, this column is the name of the user-defined data type. Otherwise, NULL is returned. |
Nombre de las columnas DataRow
For Each dr As DataRow In ds.Tables(0).Rows
MessageBox.Show(dr.Table.Columns(0).ColumnName)
Next
' Verificar si existen registros
If ds.Tables(0).Rows.Count > 0 Then
End If
MessageBox.Show(dr.Table.Columns(0).ColumnName)
Next
' Verificar si existen registros
If ds.Tables(0).Rows.Count > 0 Then
End If
martes, 23 de octubre de 2018
Asignar web service dinámico
ws.Url = "url...wsdl"
lunes, 22 de octubre de 2018
Crear archivo
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim txt As New List(Of String)
Dim config() As String = {"10,4,3,33",
"10,10,10,2018-12-12",
"2,8,20,venta al x mayor",
"5,4,13,otra línea",
"7,1,5,razón social",
"8,7,7, dirección",
"1,9,12,correo electrónico"}
Dim linea As String = ""
Dim fila As Integer = 0
Dim columna As Integer = 0
Dim largo As Integer = 0
Dim dato As String
For Each x In config
fila = x.Split(",")(0)
columna = x.Split(",")(1)
largo = x.Split(",")(2)
dato = x.Split(",")(3)
x = x.Split(",")(0)
' Crear línea
Dim n As Integer = txt.Count
For i As Integer = n To x - 1
txt.Add("")
Next
' Crear dato
Dim c As Char = Nothing
Dim tmp_dato As String = ""
If txt(x - 1) = "" Then
dato = dato.PadRight(largo)
For i As Integer = 0 To largo - 1
tmp_dato = tmp_dato & dato(i)
Next
For j As Integer = 0 To columna - 1
linea = linea & " "
Next
linea = linea & tmp_dato
txt(x - 1) = linea
Else
'Dim largo_linea As Integer = linea.Length
Dim existe As Boolean = False
For i As Integer = 0 To linea.Length - 1
If i = columna Then
existe = True
End If
Next
If existe = False Then
End If
Dim pause As String = ""
End If
Next
txt.Clear()
End Sub
End Class
versión2
Imports System.Text
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim txt As New List(Of String)
Dim config() As String = {"1,1,5,33",
"2,8,7,98545456",
"3,2,10,2018-10-22",
"5,4,13,otra línea",
"7,1,5,razón social",
"8,7,7,dirección",
"9,9,21,correo electrónico",
"14,56,100,esto es una prueba",
"100,1,4,fin"}
' "9,91,20,correo electrónico",
Dim linea As String = ""
Dim fila As Integer = 0
Dim columna As Integer = 0
Dim largo As Integer = 0
Dim dato As String
For Each x In config
fila = x.Split(",")(0)
columna = x.Split(",")(1)
largo = x.Split(",")(2)
dato = x.Split(",")(3)
x = x.Split(",")(0)
' Crear línea
Dim n As Integer = txt.Count
For i As Integer = n To x - 1
txt.Add("")
Next
' Crear dato
Dim c As Char = Nothing
Dim tmp_dato As String = ""
If txt(x - 1) = "" Then
dato = dato.PadRight(largo)
For i As Integer = 0 To largo - 1
tmp_dato = tmp_dato & dato(i) ' parte de 1,2...
Next
If columna = 1 Then
linea = linea & ""
Else
For j As Integer = 0 To columna - 1
linea = linea & " "
Next
End If
Dim tmp As String = ""
Dim k As Integer = 0
If columna = 1 Then
tmp = linea & tmp_dato
Else
For Each c In linea
If k = columna - 1 Then
tmp = tmp & tmp_dato
Exit For
Else
tmp = tmp & c
End If
k += 1
Next
End If
'Dim bytes As Byte() = System.Text.Encoding.Default.GetBytes(tmp)
'tmp = System.Text.Encoding.UTF8.GetString(bytes)
'tmp = Encoding.GetEncoding("ISO-8859-1").GetString(Encoding.Convert(Encoding.UTF8, Encoding.GetEncoding("ISO-8859-1"), Encoding.UTF8.GetBytes(tmp)))
Dim n1 As Integer = tmp.Length
n1 = New System.Globalization.StringInfo(tmp).LengthInTextElements
'linea = linea & tmp_dato
linea = tmp
txt(x - 1) = linea
linea = ""
Else
linea = txt(x - 1)
Dim total As Integer = columna + largo
Dim largo_linea As Integer = linea.Length
If largo_linea < total Then
For i As Integer = largo_linea To total - 1
linea = linea & " "
Next
dato = dato.PadRight(largo)
For i As Integer = 0 To largo - 1
tmp_dato = tmp_dato & dato(i)
Next
' Agregar dato
Dim tmp As String = Nothing
Dim k As Integer = 0
For Each c In linea
If k = columna - 1 Then
tmp = tmp & tmp_dato
Exit For
Else
tmp = tmp & c
End If
k += 1
Next
txt(x - 1) = tmp
End If
linea = ""
Dim pause As String = ""
End If
Next
' archivo
System.IO.File.WriteAllLines("archivo.txt", txt.ToArray, System.Text.Encoding.UTF8)
'System.IO.File.WriteAllLines("archivo.txt", txt.ToArray, System.Text.Encoding.GetEncoding("ISO-8859-1"))
txt.Clear()
MessageBox.Show("Fin!")
End Sub
'https://stackoverflow.com/questions/14057434/how-can-i-transform-string-to-utf-8-in-c
'https://stackoverflow.com/questions/11055122/counting-special-utf-8-character
End Class
versión 3
Imports System.Text
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim txt As New List(Of String)
Dim config() As String = {"1,1,20,TipoDTE:33",
"2,1,10,Folio :5778",
"3,1,20,FchEmis:2018-10-22",
"4,1,20,FchVenc:2018-10-22",
"5,4,13,otra línea",
"7,1,5,razón social",
"8,7,7,dirección",
"9,9,21,correo electrónico",
"10,34,10,******",
"11,56,100,esto es una prueba",
"12,36,45,juan perez",
"13,1,4,fin",
"14,105,10,Descuento",
"14,119,10,precio",
"15,23,14,."}
'(fila,columna,largo,dato,True/False,)
Dim linea As String = ""
Dim fila As Integer = 0
Dim columna As Integer = 0
Dim largo As Integer = 0
Dim dato As String
For Each x In config
fila = x.Split(",")(0)
columna = x.Split(",")(1)
largo = x.Split(",")(2)
dato = x.Split(",")(3)
x = x.Split(",")(0)
' Crear línea
Dim n As Integer = txt.Count
For i As Integer = n To x - 1
txt.Add("")
Next
' Crear dato
Dim c As Char = Nothing
Dim tmp_dato As String = ""
If txt(x - 1) = "" Then
dato = dato.PadRight(largo)
For i As Integer = 0 To largo - 1
tmp_dato = tmp_dato & dato(i) ' parte de 1,2...
Next
If columna = 1 Then
linea = linea & ""
Else
For j As Integer = 0 To columna - 1
linea = linea & " "
Next
End If
Dim tmp As String = ""
Dim k As Integer = 0
If columna = 1 Then
tmp = linea & tmp_dato
Else
For Each c In linea
If k = columna - 1 Then
tmp = tmp & tmp_dato
Exit For
Else
tmp = tmp & c
End If
k += 1
Next
End If
'linea = linea & tmp_dato
linea = tmp
txt(x - 1) = linea
linea = ""
Else
linea = txt(x - 1)
Dim total As Integer = columna + largo
Dim largo_linea As Integer = linea.Length
If largo_linea < total Then
For i As Integer = largo_linea To total - 1
linea = linea & " "
Next
dato = dato.PadRight(largo)
For i As Integer = 0 To largo - 1
tmp_dato = tmp_dato & dato(i)
Next
' Agregar dato
Dim tmp As String = Nothing
Dim k As Integer = 0
For Each c In linea
If k = columna - 1 Then
tmp = tmp & tmp_dato
Exit For
Else
tmp = tmp & c
End If
k += 1
Next
txt(x - 1) = tmp
End If
linea = ""
Dim pause As String = ""
End If
Next
' archivo
System.IO.File.WriteAllLines("archivo.txt", txt.ToArray, System.Text.Encoding.GetEncoding(1252))
'System.IO.File.WriteAllLines("archivo.txt", txt.ToArray, System.Text.Encoding.GetEncoding("ISO-8859-1"))
txt.Clear()
MessageBox.Show("Fin!")
End Sub
'https://stackoverflow.com/questions/14057434/how-can-i-transform-string-to-utf-8-in-c
'https://stackoverflow.com/questions/11055122/counting-special-utf-8-character
End Class
versión4
Imports System.Text
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim txt As New List(Of String)
Dim config() As String = {"1,30,10,TipoDTE:33",
"2,5,20,Folio :5778",
"1,1,20,FchEmis:2018-10-22",
"4,108,40,hola",
"4,98,10,chao",
"4,1,97,."}
'"4,1,20,FchVenc:2018-10-22",
'"5,4,13,otra línea",
'"7,1,5,razón social",
'"8,7,7,dirección",
'"9,9,21,correo electrónico",
'"10,34,10,******",
'"11,56,100,esto es una prueba",
'"12,36,45,juan perez",
'"13,1,4,fin",
'"14,105,10,Descuento",
'"14,119,10,precio",
'"15,23,14,."}
'(fila,columna,largo,dato,True/False,)
Dim linea As String = ""
Dim fila As Integer = 0
Dim columna As Integer = 0
Dim largo As Integer = 0
Dim dato As String
For Each x In config
fila = x.Split(",")(0)
columna = x.Split(",")(1)
largo = x.Split(",")(2)
dato = x.Split(",")(3)
x = x.Split(",")(0)
' Crear línea
Dim n As Integer = txt.Count
For i As Integer = n To x - 1
txt.Add("")
Next
' Crear dato
Dim c As Char = Nothing
Dim tmp_dato As String = ""
If txt(x - 1) = "" Then
dato = dato.PadRight(largo)
For i As Integer = 0 To largo - 1
tmp_dato = tmp_dato & dato(i) ' parte de 1,2...
Next
If columna = 1 Then
linea = linea & ""
Else
For j As Integer = 0 To columna - 1
linea = linea & " "
Next
End If
Dim tmp As String = ""
Dim k As Integer = 0
If columna = 1 Then
tmp = linea & tmp_dato
Else
For Each c In linea
If k = columna - 1 Then
tmp = tmp & tmp_dato
Exit For
Else
tmp = tmp & c
End If
k += 1
Next
End If
'linea = linea & tmp_dato
linea = tmp
txt(x - 1) = linea
linea = ""
Else
linea = txt(x - 1)
Dim total As Integer = columna + largo
Dim largo_linea As Integer = linea.Length
If largo_linea < total Then
For i As Integer = largo_linea To total - 1
linea = linea & " "
Next
dato = dato.PadRight(largo)
For i As Integer = 0 To largo - 1
tmp_dato = tmp_dato & dato(i)
Next
' Agregar dato
Dim tmp As String = Nothing
Dim k As Integer = 0
For Each c In linea
If k = columna - 1 Then
tmp = tmp & tmp_dato
Exit For
Else
tmp = tmp & c
End If
k += 1
Next
txt(x - 1) = tmp
Else
' ya existe una línea con suficiente espacio
dato = dato.PadRight(largo)
For i As Integer = 0 To largo - 1
tmp_dato = tmp_dato & dato(i)
Next
Dim tmp As String = Nothing
'Dim k As Integer = 0
'Dim j As Integer = 0
Dim z As Integer = 0
Dim tmp_linea() As Char = linea.ToCharArray
For i As Integer = 0 To linea.Length - 1
If i = columna - 1 Then
For j As Integer = i To i + largo - 1
tmp_linea(j) = tmp_dato(z)
z += 1
Next
End If
If z = largo Then
Exit For
End If
Next
txt(x - 1) = New String(tmp_linea)
Dim pause2 As String = ""
End If
linea = ""
Dim pause As String = ""
End If
Next
' archivo
System.IO.File.WriteAllLines("archivo.txt", txt.ToArray, System.Text.Encoding.GetEncoding(1252))
'System.IO.File.WriteAllLines("archivo.txt", txt.ToArray, System.Text.Encoding.GetEncoding("ISO-8859-1"))
txt.Clear()
MessageBox.Show("Fin!")
End Sub
'https://stackoverflow.com/questions/14057434/how-can-i-transform-string-to-utf-8-in-c
'https://stackoverflow.com/questions/11055122/counting-special-utf-8-character
End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim txt As New List(Of String)
Dim config() As String = {"10,4,3,33",
"10,10,10,2018-12-12",
"2,8,20,venta al x mayor",
"5,4,13,otra línea",
"7,1,5,razón social",
"8,7,7, dirección",
"1,9,12,correo electrónico"}
Dim linea As String = ""
Dim fila As Integer = 0
Dim columna As Integer = 0
Dim largo As Integer = 0
Dim dato As String
For Each x In config
fila = x.Split(",")(0)
columna = x.Split(",")(1)
largo = x.Split(",")(2)
dato = x.Split(",")(3)
x = x.Split(",")(0)
' Crear línea
Dim n As Integer = txt.Count
For i As Integer = n To x - 1
txt.Add("")
Next
' Crear dato
Dim c As Char = Nothing
Dim tmp_dato As String = ""
If txt(x - 1) = "" Then
dato = dato.PadRight(largo)
For i As Integer = 0 To largo - 1
tmp_dato = tmp_dato & dato(i)
Next
For j As Integer = 0 To columna - 1
linea = linea & " "
Next
linea = linea & tmp_dato
txt(x - 1) = linea
Else
'Dim largo_linea As Integer = linea.Length
Dim existe As Boolean = False
For i As Integer = 0 To linea.Length - 1
If i = columna Then
existe = True
End If
Next
If existe = False Then
End If
Dim pause As String = ""
End If
Next
txt.Clear()
End Sub
End Class
versión2
Imports System.Text
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim txt As New List(Of String)
Dim config() As String = {"1,1,5,33",
"2,8,7,98545456",
"3,2,10,2018-10-22",
"5,4,13,otra línea",
"7,1,5,razón social",
"8,7,7,dirección",
"9,9,21,correo electrónico",
"14,56,100,esto es una prueba",
"100,1,4,fin"}
' "9,91,20,correo electrónico",
Dim linea As String = ""
Dim fila As Integer = 0
Dim columna As Integer = 0
Dim largo As Integer = 0
Dim dato As String
For Each x In config
fila = x.Split(",")(0)
columna = x.Split(",")(1)
largo = x.Split(",")(2)
dato = x.Split(",")(3)
x = x.Split(",")(0)
' Crear línea
Dim n As Integer = txt.Count
For i As Integer = n To x - 1
txt.Add("")
Next
' Crear dato
Dim c As Char = Nothing
Dim tmp_dato As String = ""
If txt(x - 1) = "" Then
dato = dato.PadRight(largo)
For i As Integer = 0 To largo - 1
tmp_dato = tmp_dato & dato(i) ' parte de 1,2...
Next
If columna = 1 Then
linea = linea & ""
Else
For j As Integer = 0 To columna - 1
linea = linea & " "
Next
End If
Dim tmp As String = ""
Dim k As Integer = 0
If columna = 1 Then
tmp = linea & tmp_dato
Else
For Each c In linea
If k = columna - 1 Then
tmp = tmp & tmp_dato
Exit For
Else
tmp = tmp & c
End If
k += 1
Next
End If
'Dim bytes As Byte() = System.Text.Encoding.Default.GetBytes(tmp)
'tmp = System.Text.Encoding.UTF8.GetString(bytes)
'tmp = Encoding.GetEncoding("ISO-8859-1").GetString(Encoding.Convert(Encoding.UTF8, Encoding.GetEncoding("ISO-8859-1"), Encoding.UTF8.GetBytes(tmp)))
Dim n1 As Integer = tmp.Length
n1 = New System.Globalization.StringInfo(tmp).LengthInTextElements
'linea = linea & tmp_dato
linea = tmp
txt(x - 1) = linea
linea = ""
Else
linea = txt(x - 1)
Dim total As Integer = columna + largo
Dim largo_linea As Integer = linea.Length
If largo_linea < total Then
For i As Integer = largo_linea To total - 1
linea = linea & " "
Next
dato = dato.PadRight(largo)
For i As Integer = 0 To largo - 1
tmp_dato = tmp_dato & dato(i)
Next
' Agregar dato
Dim tmp As String = Nothing
Dim k As Integer = 0
For Each c In linea
If k = columna - 1 Then
tmp = tmp & tmp_dato
Exit For
Else
tmp = tmp & c
End If
k += 1
Next
txt(x - 1) = tmp
End If
linea = ""
Dim pause As String = ""
End If
Next
' archivo
System.IO.File.WriteAllLines("archivo.txt", txt.ToArray, System.Text.Encoding.UTF8)
'System.IO.File.WriteAllLines("archivo.txt", txt.ToArray, System.Text.Encoding.GetEncoding("ISO-8859-1"))
txt.Clear()
MessageBox.Show("Fin!")
End Sub
'https://stackoverflow.com/questions/14057434/how-can-i-transform-string-to-utf-8-in-c
'https://stackoverflow.com/questions/11055122/counting-special-utf-8-character
End Class
versión 3
Imports System.Text
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim txt As New List(Of String)
Dim config() As String = {"1,1,20,TipoDTE:33",
"2,1,10,Folio :5778",
"3,1,20,FchEmis:2018-10-22",
"4,1,20,FchVenc:2018-10-22",
"5,4,13,otra línea",
"7,1,5,razón social",
"8,7,7,dirección",
"9,9,21,correo electrónico",
"10,34,10,******",
"11,56,100,esto es una prueba",
"12,36,45,juan perez",
"13,1,4,fin",
"14,105,10,Descuento",
"14,119,10,precio",
"15,23,14,."}
'(fila,columna,largo,dato,True/False,)
Dim linea As String = ""
Dim fila As Integer = 0
Dim columna As Integer = 0
Dim largo As Integer = 0
Dim dato As String
For Each x In config
fila = x.Split(",")(0)
columna = x.Split(",")(1)
largo = x.Split(",")(2)
dato = x.Split(",")(3)
x = x.Split(",")(0)
' Crear línea
Dim n As Integer = txt.Count
For i As Integer = n To x - 1
txt.Add("")
Next
' Crear dato
Dim c As Char = Nothing
Dim tmp_dato As String = ""
If txt(x - 1) = "" Then
dato = dato.PadRight(largo)
For i As Integer = 0 To largo - 1
tmp_dato = tmp_dato & dato(i) ' parte de 1,2...
Next
If columna = 1 Then
linea = linea & ""
Else
For j As Integer = 0 To columna - 1
linea = linea & " "
Next
End If
Dim tmp As String = ""
Dim k As Integer = 0
If columna = 1 Then
tmp = linea & tmp_dato
Else
For Each c In linea
If k = columna - 1 Then
tmp = tmp & tmp_dato
Exit For
Else
tmp = tmp & c
End If
k += 1
Next
End If
'linea = linea & tmp_dato
linea = tmp
txt(x - 1) = linea
linea = ""
Else
linea = txt(x - 1)
Dim total As Integer = columna + largo
Dim largo_linea As Integer = linea.Length
If largo_linea < total Then
For i As Integer = largo_linea To total - 1
linea = linea & " "
Next
dato = dato.PadRight(largo)
For i As Integer = 0 To largo - 1
tmp_dato = tmp_dato & dato(i)
Next
' Agregar dato
Dim tmp As String = Nothing
Dim k As Integer = 0
For Each c In linea
If k = columna - 1 Then
tmp = tmp & tmp_dato
Exit For
Else
tmp = tmp & c
End If
k += 1
Next
txt(x - 1) = tmp
End If
linea = ""
Dim pause As String = ""
End If
Next
' archivo
System.IO.File.WriteAllLines("archivo.txt", txt.ToArray, System.Text.Encoding.GetEncoding(1252))
'System.IO.File.WriteAllLines("archivo.txt", txt.ToArray, System.Text.Encoding.GetEncoding("ISO-8859-1"))
txt.Clear()
MessageBox.Show("Fin!")
End Sub
'https://stackoverflow.com/questions/14057434/how-can-i-transform-string-to-utf-8-in-c
'https://stackoverflow.com/questions/11055122/counting-special-utf-8-character
End Class
versión4
Imports System.Text
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim txt As New List(Of String)
Dim config() As String = {"1,30,10,TipoDTE:33",
"2,5,20,Folio :5778",
"1,1,20,FchEmis:2018-10-22",
"4,108,40,hola",
"4,98,10,chao",
"4,1,97,."}
'"4,1,20,FchVenc:2018-10-22",
'"5,4,13,otra línea",
'"7,1,5,razón social",
'"8,7,7,dirección",
'"9,9,21,correo electrónico",
'"10,34,10,******",
'"11,56,100,esto es una prueba",
'"12,36,45,juan perez",
'"13,1,4,fin",
'"14,105,10,Descuento",
'"14,119,10,precio",
'"15,23,14,."}
'(fila,columna,largo,dato,True/False,)
Dim linea As String = ""
Dim fila As Integer = 0
Dim columna As Integer = 0
Dim largo As Integer = 0
Dim dato As String
For Each x In config
fila = x.Split(",")(0)
columna = x.Split(",")(1)
largo = x.Split(",")(2)
dato = x.Split(",")(3)
x = x.Split(",")(0)
' Crear línea
Dim n As Integer = txt.Count
For i As Integer = n To x - 1
txt.Add("")
Next
' Crear dato
Dim c As Char = Nothing
Dim tmp_dato As String = ""
If txt(x - 1) = "" Then
dato = dato.PadRight(largo)
For i As Integer = 0 To largo - 1
tmp_dato = tmp_dato & dato(i) ' parte de 1,2...
Next
If columna = 1 Then
linea = linea & ""
Else
For j As Integer = 0 To columna - 1
linea = linea & " "
Next
End If
Dim tmp As String = ""
Dim k As Integer = 0
If columna = 1 Then
tmp = linea & tmp_dato
Else
For Each c In linea
If k = columna - 1 Then
tmp = tmp & tmp_dato
Exit For
Else
tmp = tmp & c
End If
k += 1
Next
End If
'linea = linea & tmp_dato
linea = tmp
txt(x - 1) = linea
linea = ""
Else
linea = txt(x - 1)
Dim total As Integer = columna + largo
Dim largo_linea As Integer = linea.Length
If largo_linea < total Then
For i As Integer = largo_linea To total - 1
linea = linea & " "
Next
dato = dato.PadRight(largo)
For i As Integer = 0 To largo - 1
tmp_dato = tmp_dato & dato(i)
Next
' Agregar dato
Dim tmp As String = Nothing
Dim k As Integer = 0
For Each c In linea
If k = columna - 1 Then
tmp = tmp & tmp_dato
Exit For
Else
tmp = tmp & c
End If
k += 1
Next
txt(x - 1) = tmp
Else
' ya existe una línea con suficiente espacio
dato = dato.PadRight(largo)
For i As Integer = 0 To largo - 1
tmp_dato = tmp_dato & dato(i)
Next
Dim tmp As String = Nothing
'Dim k As Integer = 0
'Dim j As Integer = 0
Dim z As Integer = 0
Dim tmp_linea() As Char = linea.ToCharArray
For i As Integer = 0 To linea.Length - 1
If i = columna - 1 Then
For j As Integer = i To i + largo - 1
tmp_linea(j) = tmp_dato(z)
z += 1
Next
End If
If z = largo Then
Exit For
End If
Next
txt(x - 1) = New String(tmp_linea)
Dim pause2 As String = ""
End If
linea = ""
Dim pause As String = ""
End If
Next
' archivo
System.IO.File.WriteAllLines("archivo.txt", txt.ToArray, System.Text.Encoding.GetEncoding(1252))
'System.IO.File.WriteAllLines("archivo.txt", txt.ToArray, System.Text.Encoding.GetEncoding("ISO-8859-1"))
txt.Clear()
MessageBox.Show("Fin!")
End Sub
'https://stackoverflow.com/questions/14057434/how-can-i-transform-string-to-utf-8-in-c
'https://stackoverflow.com/questions/11055122/counting-special-utf-8-character
End Class
viernes, 19 de octubre de 2018
ordenar lista de tuplas
Versión 1
Dim elem As New List(Of String)
Dim a As Integer
Dim b As Integer
Dim temp As String
Dim c As Integer = -1
For i As Integer = 0 To elem.Count - 1
c += 1
For j As Integer = c To elem.Count - 1
a = elem(i).Split(",")(0)
b = elem(j).Split(",")(0)
If b < a Then
temp = elem(i)
elem(i) = elem(j)
elem(j) = temp
End If
Next
Next
elem.Clear()
Versión 2
Dim elem As New List(Of String)
Dim sep As Char = ","
Dim a As Integer
Dim b As Integer
Dim temp As String
Dim c As Integer = -1
For i As Integer = 0 To elem.Count - 1
c += 1
For j As Integer = c To elem.Count - 1
a = elem(i).Split(sep)(0)
b = elem(j).Split(sep)(0)
If b < a Then
temp = elem(i)
elem(i) = elem(j)
elem(j) = temp
ElseIf b = a Then
a = elem(i).Split(sep)(1)
b = elem(j).Split(sep)(1)
If b < a Then
temp = elem(i)
elem(i) = elem(j)
elem(j) = temp
End If
End If
Next
Next
elem.Clear()
opciones datagrid
Me.DataGridView.Rows.Clear()
Me.DataGridView..Columns.Clear()
Me.DataGridView..Refresh()
Me.DataGridView..Columns.Clear()
Me.DataGridView..Refresh()
miércoles, 17 de octubre de 2018
Certificación regex Casos
If System.Text.RegularExpressions.Regex.IsMatch(linea, "^((CASO[ ]{1,})\d+-1)+$") Then
End If
Dim x As String = "^(CASO[ ]{1,}" & numero_de_atencion & "-1)" & "+$"
fuente
End If
Dim x As String = "^(CASO[ ]{1,}" & numero_de_atencion & "-1)" & "+$"
fuente
martes, 16 de octubre de 2018
sql conexión
Try
Dim query As String =""
Dim con As New SqlConnection(conex)
con.Open
Using cmd As New SqlCommand(query, con)
cmd.Parameters.Add("@id", SqlDbType.Char).Value = ""
cmd.ExecuteNonQuery()
End Using
con.Close
Catch ex As Exception
End Try
Dim query As String =""
Dim con As New SqlConnection(conex)
con.Open
Using cmd As New SqlCommand(query, con)
cmd.Parameters.Add("@id", SqlDbType.Char).Value = ""
cmd.ExecuteNonQuery()
End Using
con.Close
Catch ex As Exception
End Try
martes, 9 de octubre de 2018
Resetear combobox
ComboBox.ResetText()
Repartir folios
Private Sub btnRepartirFolios_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRepartirFolios.Click
Dim lista As New ArrayList
Dim folios As Integer = 76
Dim porcentaje As Integer
Dim sucursales() As String = File.ReadAllLines("suc.txt")
Dim cantidad_sucursales As Integer = sucursales.Length
Dim restante As Integer = folios
Dim total_folios As Integer
Dim p As Integer
For Each x In sucursales
p = x.Split(";")(0)
porcentaje = Math.Truncate(folios * (p / 100))
If p > 0 AndAlso porcentaje = 0 Then
porcentaje = 1
End If
restante = restante - porcentaje
lista.Add(porcentaje)
total_folios = total_folios + porcentaje
porcentaje = 0
Next
If restante >= 0 Then
While restante > 0
restante -= 1
End While
End If
lista.Sort()
lista.Reverse()
Dim pause As String = ""
End Sub
Dim lista As New ArrayList
Dim folios As Integer = 76
Dim porcentaje As Integer
Dim sucursales() As String = File.ReadAllLines("suc.txt")
Dim cantidad_sucursales As Integer = sucursales.Length
Dim restante As Integer = folios
Dim total_folios As Integer
Dim p As Integer
For Each x In sucursales
p = x.Split(";")(0)
porcentaje = Math.Truncate(folios * (p / 100))
If p > 0 AndAlso porcentaje = 0 Then
porcentaje = 1
End If
restante = restante - porcentaje
lista.Add(porcentaje)
total_folios = total_folios + porcentaje
porcentaje = 0
Next
If restante >= 0 Then
While restante > 0
restante -= 1
End While
End If
lista.Sort()
lista.Reverse()
Dim pause As String = ""
End Sub
miércoles, 3 de octubre de 2018
Dejar aplicación en administrador de tareas
Imports System.Reflection
Private Declare Function ShowWindow Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal nCmdShow As Integer) As Boolean
Public Shared Sub HideWindow()
Dim SW_HIDE As Integer = 0
For Each pr As Process In Process.GetProcesses
If pr.ProcessName.Contains("AcroRd32") Then
'Int32 hWnd = pr.MainWindowHandle.ToInt32();
ShowWindow(pr.MainWindowHandle, SW_HIDE)
End If
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
HideWindow()
End Sub
fuente
Private Declare Function ShowWindow Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal nCmdShow As Integer) As Boolean
Public Shared Sub HideWindow()
Dim SW_HIDE As Integer = 0
For Each pr As Process In Process.GetProcesses
If pr.ProcessName.Contains("AcroRd32") Then
'Int32 hWnd = pr.MainWindowHandle.ToInt32();
ShowWindow(pr.MainWindowHandle, SW_HIDE)
End If
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
HideWindow()
End Sub
fuente
martes, 2 de octubre de 2018
RECHAZO- CAF Vencido
(CAF-3-517) RECHAZO- CAF Vencido : (Firma_DTE[AAAA-MM-DD] - CAF[AAAA-MM-DD]) > 18 meses. A partir del 01.07.2018 el plazo será de 6 meses
lunes, 1 de octubre de 2018
Función validar números
Public Function validateNumeric(ByVal cod As String) As Boolean
Return System.Text.RegularExpressions.Regex.IsMatch(cod, "^[0-9]+$")
End Function
Return System.Text.RegularExpressions.Regex.IsMatch(cod, "^[0-9]+$")
End Function
martes, 25 de septiembre de 2018
Sacar xmlns
Public Function cleanXmlns(ByVal str As String) As String
Dim root As XElement = XElement.Parse(str)
root.DescendantsAndSelf.Attributes.Where(Function(x) x.IsNamespaceDeclaration).Remove()
For Each el As XElement In root.DescendantsAndSelf()
el.Name = el.Name.LocalName
Next
Return root.ToString
End Function
Dim root As XElement = XElement.Parse(str)
root.DescendantsAndSelf.Attributes.Where(Function(x) x.IsNamespaceDeclaration).Remove()
For Each el As XElement In root.DescendantsAndSelf()
el.Name = el.Name.LocalName
Next
Return root.ToString
End Function
viernes, 21 de septiembre de 2018
Existe registro en una tabla
jueves, 13 de septiembre de 2018
Encoding e Indentar xml
Dim xml_test As New XmlDocument
xml_test.LoadXml(xml)
Dim setting As New XmlWriterSettings
setting.Indent = True
setting.Encoding = System.Text.Encoding.GetEncoding("ISO-8859-1")
Dim out As XmlWriter = XmlWriter.Create("archivo.xml", setting)
xml_test.Save(out)
out.Close()
xml_test.LoadXml(xml)
Dim setting As New XmlWriterSettings
setting.Indent = True
setting.Encoding = System.Text.Encoding.GetEncoding("ISO-8859-1")
Dim out As XmlWriter = XmlWriter.Create("archivo.xml", setting)
xml_test.Save(out)
out.Close()
miércoles, 12 de septiembre de 2018
Leer un archivo xml en una sola línea
Dim xml As String = File.ReadAllText("archivo.xml")
viernes, 7 de septiembre de 2018
String cabecera xml
Dim header As String = "<?xml version=""1.0"" encoding=""UTF-8""?>"
Dim ISO8859 As String = "<?xml version=""1.0"" encoding=""ISO-8859-1""?>"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim nombre_xml As String = "archivo.xml"
'Dim root As String = "<DATA></DATA>"
Dim xml As New XmlDocument
Dim node As XmlNode = xml.CreateXmlDeclaration("1.0", "UTF-8", Nothing)
xml.InnerXml = node.OuterXml & "<data><conex></conex><creacion>" & Now.ToString("yyyy-MM-ddTHH:mm:ss") & "</creacion><actualizacion></actualizacion></data>"
Dim settings As New XmlWriterSettings
settings.Indent = True
Dim out As XmlWriter = XmlWriter.Create(nombre_xml, settings)
xml.Save(out)
out.Close()
'xml.Save(nombre_xml)
MessageBox.Show("fin!")
End Sub
Dim ISO8859 As String = "<?xml version=""1.0"" encoding=""ISO-8859-1""?>"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim nombre_xml As String = "archivo.xml"
'Dim root As String = "<DATA></DATA>"
Dim xml As New XmlDocument
Dim node As XmlNode = xml.CreateXmlDeclaration("1.0", "UTF-8", Nothing)
xml.InnerXml = node.OuterXml & "<data><conex></conex><creacion>" & Now.ToString("yyyy-MM-ddTHH:mm:ss") & "</creacion><actualizacion></actualizacion></data>"
Dim settings As New XmlWriterSettings
settings.Indent = True
Dim out As XmlWriter = XmlWriter.Create(nombre_xml, settings)
xml.Save(out)
out.Close()
'xml.Save(nombre_xml)
MessageBox.Show("fin!")
End Sub
Crear archivo xml
Dim nombre_xml As String = "archivo.xml"
Dim xml As New XmlDocument
Dim node As XmlNode = xml.CreateXmlDeclaration("1.0", "UTF-8", Nothing)
xml.InnerXml = node.OuterXml & "<DATA>hola</DATA>"
xml.Save(nombre_xml)
Dim xml As New XmlDocument
Dim node As XmlNode = xml.CreateXmlDeclaration("1.0", "UTF-8", Nothing)
xml.InnerXml = node.OuterXml & "<DATA>hola</DATA>"
xml.Save(nombre_xml)
jueves, 6 de septiembre de 2018
martes, 4 de septiembre de 2018
Ejemplo query en archivo xml con LIKE
SELECT * FROM tabla WHERE dte LIKE '%' + @dte AND folio LIKE '%' + @folio AND cliente=@rut
viernes, 31 de agosto de 2018
Renombrar archivo
Microsoft.VisualBasic.FileIO.FileSystem.RenameFile(ruta del archivo y el nombre, nombre_nuevo)
My.Computer.FileSystem.RenameFile("C:\Test.txt", "SecondTest.txt")
fuente
fuente2
My.Computer.FileSystem.RenameFile("C:\Test.txt", "SecondTest.txt")
fuente
fuente2
jueves, 30 de agosto de 2018
transformar query de varias lineas en una sola
xml reemplazar parentesis angulares
lunes, 27 de agosto de 2018
Carpeta respaldo
Public Function folderBkp(ByVal ruta As String) As String
Dim newFolder As String = Now.ToString("yyyy") & "\" & Now.ToString("MM") & "\" & Now.ToString("dd")
ruta = ruta & "\" & newFolder
If Not Directory.Exists(ruta) Then
Directory.CreateDirectory(ruta)
End If
Return ruta
End Function
Public Function folderBkp(ByVal ruta As String) As String
ruta = ruta & "\" & Now.ToString("yyyy") & "\" & Now.ToString("MM") & "\" & Now.ToString("dd")
If Not Directory.Exists(ruta) Then
Directory.CreateDirectory(ruta)
End If
Return ruta
End Function
Dim newFolder As String = Now.ToString("yyyy") & "\" & Now.ToString("MM") & "\" & Now.ToString("dd")
ruta = ruta & "\" & newFolder
If Not Directory.Exists(ruta) Then
Directory.CreateDirectory(ruta)
End If
Return ruta
End Function
Public Function folderBkp(ByVal ruta As String) As String
ruta = ruta & "\" & Now.ToString("yyyy") & "\" & Now.ToString("MM") & "\" & Now.ToString("dd")
If Not Directory.Exists(ruta) Then
Directory.CreateDirectory(ruta)
End If
Return ruta
End Function
jueves, 23 de agosto de 2018
Abrir un archivo xml XDocument
Dim doc As XDocument = XDocument.Load("C:\archivo.xml")
Dim xmldoc As New XmlDocument
xmldoc.LoadXml(doc.ToString)
Dim xmldoc As New XmlDocument
xmldoc.LoadXml(doc.ToString)
Remover comentarios un xml
Dim xmlregex As String = Regex.Replace(xnode.OuterXml, "<!--.*?-->", String.Empty, RegexOptions.Singleline)
martes, 21 de agosto de 2018
formato fecha
fechaInicial = DateTime.Now.AddMonths(-1).ToString("yyyyMMdd")
fechaFinal = DateTime.Now.ToString("yyyyMMdd")
fechaFinal = DateTime.Now.ToString("yyyyMMdd")
xml sql <>
Reemplazar en xml < > por !=
jueves, 9 de agosto de 2018
Recorrer ComboBox
For Each c As Object In ComboBox.Items
Message.Box(CStr(c))
Next
Message.Box(CStr(c))
Next
miércoles, 8 de agosto de 2018
Agregar combobox DataGrid
dgv.Rows.Add()
Dim rowIndex As Integer = 0
Dim colIndex As Integer = 0
For rowIndex = 0 To dgv.Rows.Count - 1
Dim comboBoxCell As New DataGridViewComboBoxCell
comboBoxCell.Items.Add("Clear Force")
comboBoxCell.Items.Add("this works")
comboBoxCell.Items.Add("well")
comboBoxCell.Value = "Clear Force"
dgv(1, rowIndex) = comboBoxCell
Next
dgv(1, 1).Value = "well"
fuente
Dim rowIndex As Integer = 0
Dim colIndex As Integer = 0
For rowIndex = 0 To dgv.Rows.Count - 1
Dim comboBoxCell As New DataGridViewComboBoxCell
comboBoxCell.Items.Add("Clear Force")
comboBoxCell.Items.Add("this works")
comboBoxCell.Items.Add("well")
comboBoxCell.Value = "Clear Force"
dgv(1, rowIndex) = comboBoxCell
Next
dgv(1, 1).Value = "well"
fuente
Etiquetas:
ComboBox,
DataGridViewComboBoxColumn
jueves, 26 de julio de 2018
cmd.exe windows 10
-Administrador de tareas
-Archivo
-Ejecutar nueva tarea
-Abrir: cmd.exe
Se encuentra en C:\Windows\System32\cmd.exe
-Archivo
-Ejecutar nueva tarea
-Abrir: cmd.exe
Se encuentra en C:\Windows\System32\cmd.exe
martes, 24 de julio de 2018
Mostrar contraseña TextBox
Public Class clave
Private passChar As Char = "?"
Private Sub clave_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TBclave.PasswordChar = passChar
End Sub
Private Sub CBclave_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CBclave.CheckedChanged
If CBclave.Checked Then
TBclave.PasswordChar = ""
Else
TBclave.PasswordChar = passChar
End If
End Sub
End Class
Etiquetas:
TextBox,
UseSystemPasswordChar
Suscribirse a:
Entradas (Atom)