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)
miércoles, 31 de octubre de 2018
número notación cientifica
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
Suscribirse a:
Entradas (Atom)