|
9791
|
Programación / .NET (C#, VB.NET, ASP) / Re: [APORTE] Snippets (ACTUALIZADO 12/01/2013) Posteen aquí sus snippets!!
|
en: 12 Enero 2013, 23:30 pm
|
Set_PC_State ' // By Elektro H@cker ' USAGE: ' ' Set_PC_State(RESET) ' Set_PC_State(SUSPEND, 30, "I'm suspending your system.") ' Set_PC_State(LOG_OFF) ' Set_PC_State(HIBERN) ' Set_PC_State(ABORT) #Region " Set PC State " Const RESET As String = " -R " Const SUSPEND As String = " -S " Const LOG_OFF As String = " -L " Const HIBERN As String = " -H " Const ABORT As String = " -A " Private Function Set_PC_State(ByVal PowerState_Action As String, Optional ByVal TimeOut As Integer = 1, Optional ByVal COMMENT As String = "") Dim Shutdown_Command As New ProcessStartInfo Shutdown_Command.FileName = "Shutdown.exe" Try If PowerState_Action = ABORT Or PowerState_Action = HIBERN Or PowerState_Action = LOG_OFF Then Shutdown_Command.Arguments = PowerState_Action ' Windows don't allow TimeOut or Comment options for HIBERN, LOG_OFF or ABORT actions. ElseIf PowerState_Action = RESET Or PowerState_Action = SUSPEND Then If Not COMMENT = "" Then If COMMENT.Length > 512 Then COMMENT = COMMENT.Substring(0, 512) ' Only 512 chars are allowed for comment Shutdown_Command.Arguments = PowerState_Action & " -T " & TimeOut & " /C " & COMMENT Else Shutdown_Command.Arguments = PowerState_Action & " -T " & TimeOut End If Shutdown_Command.WindowStyle = ProcessWindowStyle.Hidden Process.Start(Shutdown_Command) Return True End If Catch ex As Exception Return ex.Message End Try Return Nothing ' Invalid argument End Function #End Region
Día local:Dim Today as string = My.Computer.Clock.LocalTime.DayOfWeek ' In English language Dim Today as string = System.Globalization.DateTimeFormatInfo.CurrentInfo.GetDayName(Date.Today.DayOfWeek) ' In system language
String is URL? ' USAGE: ' ' If String_Is_URL("http://google.com") Then MsgBox("Valid url!") Else MsgBox("Invalid url!") #Region " String Is URL Function " Private Function String_Is_URL(ByVal STR As String) Dim URL_Pattern As String = "^(http|https):/{2}[a-zA-Z./&\d_-]+" Dim URL_RegEx As New System.Text.RegularExpressions.Regex(URL_Pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase Or System.Text.RegularExpressions.RegexOptions.ExplicitCapture) If URL_RegEx.IsMatch(STR) Then Return True Else Return False End Function #End Region
G-Mail Sender (Envía emails) ' USAGE: ' ' GMail_Sender("Your_Email@Gmail.com", "Your_Password", "Email Subject", "Message Body", "Destiny@Email.com") #Region " GMail Sender function " Private Function GMail_Sender(ByVal Gmail_Username As String, ByVal Gmail_Password As String, ByVal Email_Subject As String, ByVal Email_Body As String, ByVal Email_Destiny As String) Try Dim MailSetup As New System.Net.Mail.MailMessage MailSetup.Subject = Email_Subject MailSetup.To.Add(Email_Destiny) MailSetup.From = New System.Net.Mail.MailAddress(Gmail_Username) MailSetup.Body = Email_Body Dim SMTP As New System.Net.Mail.SmtpClient("smtp.gmail.com") SMTP.Port = 587 SMTP.EnableSsl = True SMTP.Credentials = New Net.NetworkCredential(Gmail_Username, Gmail_Password) SMTP.Send(MailSetup) Return True ' Email is sended OK Catch ex As Exception Return ex.Message ' Email can't be sended End Try End Function #End Region
|
|
|
9795
|
Programación / .NET (C#, VB.NET, ASP) / Re: [APORTE] Snippets (ACTUALIZADO 12/01/2013) Posteen aquí sus snippets!!
|
en: 12 Enero 2013, 20:36 pm
|
Otro convertidor, en esta ocasión un convertidor de tiempo, ms, segundos, minutos, horas. #Region " Convert Time Function" ' // By Elektro H@cker ' ' MsgBox(Convert_Time(1, "h", "m")) ' MsgBox(Convert_Time(1, "h", "s")) ' MsgBox(Convert_Time(1, "h", "ms")) ' MsgBox(Convert_Time(6000, "milliseconds", "seconds")) ' MsgBox(Convert_Time(6000, "seconds", "minutes")) ' MsgBox(Convert_Time(6000, "minutes", "hours")) Private Function Convert_Time(ByVal Time As Int64, ByVal Input_Time_Format As String, ByVal Output_Time_Format As String) Dim Time_Span As New TimeSpan If Input_Time_Format.ToUpper = "MS" Or Output_Time_Format.ToUpper = "MILLISECONDS" Then Time_Span = New TimeSpan(TimeSpan.TicksPerMillisecond * Time) If Input_Time_Format.ToUpper = "S" Or Output_Time_Format.ToUpper = "SECONDS" Then Time_Span = New TimeSpan(TimeSpan.TicksPerSecond * Time) If Input_Time_Format.ToUpper = "M" Or Output_Time_Format.ToUpper = "MINUTES" Then Time_Span = New TimeSpan(TimeSpan.TicksPerMinute * Time) If Input_Time_Format.ToUpper = "H" Or Output_Time_Format.ToUpper = "HOURS" Then Time_Span = New TimeSpan(TimeSpan.TicksPerHour * Time) If Output_Time_Format.ToUpper = "MS" Or Output_Time_Format.ToUpper = "MILLISECONDS" Then Return Time_Span.TotalMilliseconds If Output_Time_Format.ToUpper = "S" Or Output_Time_Format.ToUpper = "SECONDS" Then Return Time_Span.TotalSeconds If Output_Time_Format.ToUpper = "M" Or Output_Time_Format.ToUpper = "MINUTES" Then Return Time_Span.TotalMinutes If Output_Time_Format.ToUpper = "H" Or Output_Time_Format.ToUpper = "HOURS" Then Return Time_Span.TotalHours Return False ' Returns false if argument is in incorrect format End Function #End Region
|
|
|
9798
|
Programación / .NET (C#, VB.NET, ASP) / [solucionado] Como simular el método "performclick" de un botón?
|
en: 12 Enero 2013, 18:17 pm
|
Hola, Estoy usando un botón extendido que no dispone del método "performclick" Esto no puedo hacerlo: If "a" = "a" then Button1.performclick()
Puedo escribir el método y no me salta excepción, pero no sucede nada, y he leido el mismo tipo de problema en la página del autor, en CodeProject. La pregunta es... ¿Puedo simularlo de alguna manera? (Que no séa clickando el botón por coordenadas... ) Dispongo del source del botón, por si saben como implementar el método... Gracias por leer.
|
|
|
9799
|
Programación / .NET (C#, VB.NET, ASP) / Re: [APORTE] Snippets (ACTUALIZADO 12/01/2013) Posteen aquí sus snippets!!
|
en: 12 Enero 2013, 18:00 pm
|
He actualizado el pack de Snippets en el post principal (Antes eran 76, ahora 114) Si alguien quiere que incluya un pack con sus snippets en el post principal porfavor que me pase los snippets en formato de snippet (Archivo.snippet). Y añado este snippet, un delimitador de strings, es parecido al método "Split", pero bajo mi opinión lo he mejorado bastante! · Acepta 1 o 2 delimitadores, · Opción de IgnoreCase · Delimitar de izquierda a derecha o de derecha a izquierda. Saludos! #Region " Delimit_String Function " ' // By Elektro H@ker ' ' USAGE: ' ' MsgBox(Delimit_String("Welcome to my new house", "to")) ' my new house ' MsgBox(Delimit_String("Welcome to my new house", "to", "house")) ' my new ' MsgBox(Delimit_String("Welcome to my new house", "TO", "HoUSe", True)) ' my new ' MsgBox(Delimit_String("Welcome to my new house", "house", "to", , "Left")) ' my new ' MsgBox(Delimit_String("Welcome to my new house", "TO", "HoUSe", False)) ' False ' MsgBox(Delimit_String("Welcome to my new house", "to", "to", , "Left")) ' Index was outside bounds of the array Private Function Delimit_String(ByVal STR As String, ByVal Delimiter_A As String, Optional ByVal Delimiter_B As String = "", Optional ByVal Ignore_Case As Boolean = False, Optional ByVal Left_Or_Right As String = "Right") Dim Compare_Method As Integer = 0 ' Don't ignore case If Ignore_Case = True Then Compare_Method = 1 ' Ignore Case If Not Left_Or_Right.ToUpper = "LEFT" And Not Left_Or_Right.ToUpper = "RIGHT" _ Then Return False ' Returns false if the Left_Or_Right argument is in incorrect format If Compare_Method = 0 Then If Not STR.Contains(Delimiter_A) Or Not STR.Contains(Delimiter_B) _ Then Return False ' Returns false if one of the delimiters in NormalCase can 't be found Else If Not STR.ToUpper.Contains(Delimiter_A.ToUpper) Or Not STR.ToUpper.Contains(Delimiter_B.ToUpper) _ Then Return False ' Returns false if one of the delimiters in IgnoreCase can 't be found End If Try If Left_Or_Right.ToUpper = "LEFT" Then STR = Split(STR, Delimiter_A, , Compare_Method)(0) _ Else If Left_Or_Right.ToUpper = "RIGHT" Then STR = Split(STR, Delimiter_A, , Compare_Method)(1) If Delimiter_B IsNot Nothing Then If Left_Or_Right.ToUpper = "LEFT" Then STR = Split(STR, Delimiter_B, , Compare_Method)(1) _ Else If Left_Or_Right.ToUpper = "RIGHT" Then STR = Split(STR, Delimiter_B, , Compare_Method)(0) End If Return STR ' Returns the splitted string Catch ex As Exception Return ex.Message ' Returns exception if index is out of range End Try End Function #End Region
|
|
|
|
|
|
|