|
8531
|
Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets)
|
en: 17 Agosto 2013, 20:03 pm
|
Una función para abreviar cantidades de dinero al estilo americano. PD: He preguntado a gente americana como son las abreviaturas para cifras más grandes de un Trillón pero al parecer no existen abreviaturas Standards, así que me las he inventado un poco basándome en el nombre de las cantidades. http://ell.stackexchange.com/questions/9123/money-abbreviationsEDITO: Corregido la ubicación del caracter del dolar, parece ser que se pone a la izquierda de la cantidad, no a la derecha. #Region " Money Abbreviation " ' [ Money Abbreviation Function ] ' ' // By Elektro H@cker ' ' Examples : ' ' MsgBox(Money_Abbreviation(1000)) ' Result: 1 K ' MsgBox(Money_Abbreviation(1000000)) ' Result: 1 M ' MsgBox(Money_Abbreviation(1500000, False)) ' Result: 1,5 M Private Function Money_Abbreviation(ByVal Quantity As Object, _ Optional ByVal Rounded As Boolean = True) As String Dim Abbreviation As String = String.Empty Select Case Quantity.GetType() Case GetType(Int16), GetType(Int32), GetType(Int64) Quantity = FormatNumber(Quantity, TriState.False) Case Else Quantity = FormatNumber(Quantity, , TriState.False) End Select Select Case Quantity.ToString.Count(Function(character As Char) character = Convert.ToChar(".")) Case 0 : Return String.Format("${0}", Quantity) Case 1 : Abbreviation = "k" Case 2 : Abbreviation = "M" Case 3 : Abbreviation = "B" Case 4 : Abbreviation = "Tr." Case 5 : Abbreviation = "Quad." Case 6 : Abbreviation = "Quint." Case 7 : Abbreviation = "Sext." Case 8 : Abbreviation = "Sept." Case Else Return String.Format("${0}", Quantity) End Select Return IIf(Rounded, _ String.Format("{0} {1}", StrReverse(StrReverse(Quantity).Substring(StrReverse(Quantity).LastIndexOf(".") + 1)), Abbreviation), _ String.Format("{0} {1}", StrReverse(StrReverse(Quantity).Substring(StrReverse(Quantity).LastIndexOf(".") - 1)), Abbreviation)) End Function #End Region
Contar la cantidad de coincidencias de un caracter dentro de un string. #Region " Count Character " ' [ Count Character Function ] ' ' // By Elektro H@cker ' ' Examples : ' MsgBox(Count_Character("Elektro", "e")) ' Result: 1 ' MsgBox(Count_Character("Elektro", "e", True)) ' Result: 2 Public Function Count_Character(ByVal str As String, ByVal character As Char, _ Optional ByVal IgnoreCase As Boolean = False) As Integer Return IIf(IgnoreCase, _ str.ToLower.Count(Function(c As Char) c = Convert.ToChar(character.ToString.ToLower)), _ str.Count(Function(c As Char) c = character)) End Function #End Region
|
|
|
8532
|
Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets)
|
en: 17 Agosto 2013, 19:17 pm
|
Una función para convertir entre tasas de transferencia de telecomunicaciones y tasas de transferencia de datos, es decir, entre Bp/s y B/s. PD: En este snippet @IkillNukes me ha ayudado con los cálculos matemáticos de las enumeraciones, que me daban ciertos problemas. #Region " Telecommunication Bitrate To DataStorage Bitrate " ' [ Base64 To String Function ] ' ' // By Elektro H@cker & IKillNukes ' ' Examples : ' ' MsgBox(Telecommunication_Bitrate_To_DataStorage_Bitrate(365, _ ' Telecommunications_Bitrates.Kilobips, _ ' DataStorage_Bitrates.Kilobytes)) ' Result: 45 ' ' MsgBox(Telecommunication_Bitrate_To_DataStorage_Bitrate(365, _ ' Telecommunications_Bitrates.Kilobips, _ ' DataStorage_Bitrates.Kilobytes)) ' Result: 45,625 Private Enum Telecommunications_Bitrates As Long Bips = 1 ' bit/s Kilobips = 1000 ' bit/s Megabips = 1000000 ' bit/s Gigabips = 1000000000 ' bit/s Terabips = 1000000000000 ' bit/s End Enum Private Enum DataStorage_Bitrates As Long Bytes = 8 ' bits Kilobytes = 8000 ' bits Megabytes = 8000000 ' bits Gigabytes = 8000000000 ' bits Terabytes = 8000000000000 ' bits End Enum Private Function Telecommunication_Bitrate_To_DataStorage_Bitrate( _ ByVal BitRate As Single, _ ByVal Telecommunications_Bitrates As Telecommunications_Bitrates, _ ByVal DataStorage_Bitrates As DataStorage_Bitrates, _ Optional ByVal Rounded As Boolean = True ) As Single Return IIf(Rounded, _ (BitRate * Telecommunications_Bitrates) \ DataStorage_Bitrates, _ (BitRate * Telecommunications_Bitrates) / DataStorage_Bitrates) End Function #End Region
|
|
|
8533
|
Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets)
|
en: 17 Agosto 2013, 05:48 am
|
Convierte una fecha a formato de fecha Unix #Region " DateTime To Unix " ' [ DateTime To Unix Function ] ' ' Examples : ' ' MsgBox(DateTime_To_Unix(DateTime.Parse("01/01/2013 12:00:00"))) ' Result: 1357041600 Public Function DateTime_To_Unix(ByVal DateTime As DateTime) As Long Return DateDiff(DateInterval.Second, #1/1/1970#, DateTime) End Function #End Region
Convierte formato de fecha Unix a Fecha normal. #Region " Unix To DateTime " ' [ Unix To DateTime Function ] ' ' Examples : ' ' MsgBox(Unix_To_DateTime(1357041600)) ' Result: 01/01/2013 12:00:00 Public Function Unix_To_DateTime(ByVal UnixTime As Long) As DateTime Return DateAdd(DateInterval.Second, UnixTime, #1/1/1970#) End Function #End Region
|
|
|
8537
|
Programación / Scripting / Re: como puedo enviar unos archivos de manera automatica a mi correo por Cmd
|
en: 16 Agosto 2013, 14:48 pm
|
Batch no dispone de ningún comando para emails, debes recurrir a aplicaciones de terceros o en su defecto a cualquier otro lenguaje que no sea Batch. Puedes registrarte de forma gratuita aquí y utilizar la aplicación commandline que ofrecen, para usarla en Batch: https://www.zeta-uploader.com/es , lo llevo usando años, lo bueno es que usan un server dedicado así que no es necesario enviarlo desde una cuenta de correo original y no hay limite (al menos no un limite pequeño) de tamaño. ...O puedes googlear un poco para ver ejemplos de códigos para enviar emails usando VBS, por ejemplo. Para lo de la hora debes crear una tarea programada en tu PC -> SCHTASKSSaludos
|
|
|
8538
|
Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets)
|
en: 16 Agosto 2013, 04:19 am
|
Unos tips que he codeado sobre el manejo de una lista de Tuplas, de una lista de FIleInfo, y sobre la utilización de algunas extensiones de LINQ: PD: Es muy bueno aprender todos estos métodos para dejar en el olvido a los FOR. List(Of Tuple) ' Create the list: Dim TupleList As New List(Of Tuple(Of String, Boolean, Integer)) ' From {Tuple.Create("Hello world", True, 1)} ' Add an Item: TupleList.Add(Tuple.Create("Elektro", False, 0)) TupleList.Add(Tuple.Create("H@cker", True, 1)) ' Order the TupleList by a Tuple item: TupleList = TupleList.OrderBy(Function(Tuple) Tuple.Item3).ToList ' Sort the TupleList by a Tuple item: TupleList.Sort( _ Function(Comparer_A As Tuple(Of String, Boolean, Integer), _ Comparer_B As Tuple(Of String, Boolean, Integer)) _ Comparer_A.Item3.CompareTo(Comparer_B.Item3)) ' Filter the list by items equals as "True" in their Tuple second item: TupleList = TupleList.Where(Function(Tuple) Tuple.Item2 = True).ToList ' Display a Tuple item from a list item: MsgBox(TupleList.Item(0).Item2) ' Looping the list: For Each Item As Tuple(Of String, Boolean, Integer) In TupleList MsgBox(Item.Item1) Next
List(Of FileInfo) ' Create the list: Dim Files As List (Of IO. FileInfo) = IO. Directory. GetFiles("C:\", "*") _ .Select(Function(ToFileInfo) New IO.FileInfo(ToFileInfo)).ToList ' Add an Item: Files. Add(New IO. FileInfo("C:\Windows\Notepad.exe")) ' Order the list by a file property: ' Sort the list by a file property: Function(Comparer_A As IO.FileInfo, Comparer_B As IO.FileInfo) _ Comparer_A.Extension.CompareTo(Comparer_B.Extension)) ' Filter the list by files containing "note" word in their filename: ' Display a file property from a list item: MsgBox(Files. Item(0). FullName) ' Looping the list: Next
|
|
|
8539
|
Programación / .NET (C#, VB.NET, ASP) / Re: ¿ Se puede hacer esta consulta de fechas ?
|
en: 16 Agosto 2013, 02:13 am
|
La ciencia de "1 mes" no es exacta, son todo promedios, Google dice que son 30 días como ha dicho Novlucker, pero la Wikipedia dice que son 29, y nosotros cuando decimos un mes (al menos yo) pensamos en 30 días sin tener el cuenta el més en el que estamos, pero cuando decimos "el próximos més" pensamos en el día 1 del siguiente més, en fín por todo esto creo que no hay que comerse mucho la cabeza para intentar calcular al milímetro los meses. Así que aquí dejo el code funcional para VB que me ha proporcionado una persona, el code funciona con la fecha problemática que ha comentado @ostrede y también con los horarios: #Region " Date Difference " ' Date Difference ' ' Examples : ' ' MsgBox(DateDifference(DateTime.Parse("01/03/2013"), DateTime.Parse("10/04/2013"))) ' Result: 1 Months, 1 Weeks, 2 Days, 0 Hours, 0 Minutes and 0 Seconds ' MsgBox(DateDifference(DateTime.Parse("01/01/2013 14:00:00"), DateTime.Parse("02/01/2013 15:00:30"))) ' Result: 0 Months, 0 Weeks, 1 Days, 1 Hours, 0 Minutes and 30 Seconds Private Function DateDifference(ByVal Date1 As DateTime, ByVal Date2 As DateTime) As String Dim Time As TimeSpan Dim MonthDiff As Integer, WeekDiff As Integer Do Until Date1 > Date2 Date1 = Date1.AddMonths(1) MonthDiff += 1 Loop MonthDiff -= 1 Date1 = Date1.AddMonths(-1) Time = (Date2 - Date1) WeekDiff = (Time.Days \ 7) Time = (Time - TimeSpan.FromDays(WeekDiff * 7)) Return String.Format("{0} Months, {1} Weeks, {2} Days, {3} Hours, {4} Minutes and {5} Seconds", _ MonthDiff, WeekDiff, Time.Days, Time.Hours, Time.Minutes, Time.Seconds) End Function #End Region
¿Tema solucionado? xD. Saludos
|
|
|
8540
|
Programación / .NET (C#, VB.NET, ASP) / Re: ¿ Se puede hacer esta consulta de fechas ?
|
en: 15 Agosto 2013, 22:50 pm
|
EleKtro H@cker, sin probarla, esa función no es correcta  ¿Qué pasa si le paso como parámetros las fechas "01/01/2013 14:00:00" y "02/01/2013 13:00:30"? Saludos Es verdad no me di cuenta, malditas "horas" xD Bueno todo tiene solución, entonces hay que substraer en lugar de restar: Dim HourDiff As Long = Date2.Subtract(Date1).Hours Dim MinuteDiff As Long = Date2.Subtract(Date1).Minutes Dim SecondDiff As Long = Date2.Subtract(Date1).Seconds Dim MilliDiff As Long = Date2.Subtract(Date1).Milliseconds
Llevo un lio tremendo para sacar la fecha con eficacia (por ejemplo entre meses como febrero con 28 días), el valor de las semanas se resiste, pero nadie tiene la solución: http://stackoverflow.com/questions/18259835/function-to-get-a-custom-date-differenceSaludos!
|
|
|
|
|
|
|