elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Únete al Grupo Steam elhacker.NET


  Mostrar Mensajes
Páginas: 1 ... 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 [970] 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 ... 1232
9691  Programación / Scripting / Re: [PAPER] Compilación de scripts en Python a .exe en: 18 Enero 2013, 19:12 pm
@shordan37
No revivas un tema de hace 2 años, las dudas se formulan en nuevos posts.

PD: para compilar es tán séncillo como descargar CXFreeze http://cx-freeze.sourceforge.net/,
y escribir en consola:

Código:
cxfreeze.bat "archivo.py"

Tema cerrado.
9692  Programación / .NET (C#, VB.NET, ASP) / Re: problema con Random en: 18 Enero 2013, 17:41 pm
Poca funcionalidad más puede tener un "get random numbers", sólamente elegir si se quiere un número décimal o... bueno, ya vendrá, primero necesito que funcione xD



Lo de la lista solo era un ejemplo de uno de los casos en los que siempre manda el mismo número.

Citar
1- NO generar la instancia de clase Random, ni la semilla, dentro de un bucle.
Ya que si lo haces, puedes tener la seguridad de que los valores se repitan.

2- NO generar la semilla ni la instancia del objeto Random dentro de un método que será llamado de forma consecutiva.
Podías pensar, que si en lugar de crear la instancia dentro del bucle, la creas fuera se soluciona, pero si ese "fuera" es dentro del método, la verdad es que no.

Pues vaya :(.



Código
  1.    Private Sub GetRandomNumbers(Byval Min as int32, Byval Max as int32)
  2.    ' Inicializamos el generador de nº aleatorios
  3.    Randomize()
  4.    ' Generamos un valor aleatorio entre 50 y 100
  5.    Dim Valor As Integer = CInt(Int((100 * Max()) + Min))
  6.    return Valor
  7.    End Sub

Se nota que lo has escrito al vuelo, no funciona! xD

He intentado corregirlo pero me devuelve siempre valores por encima de "400"
9693  Programación / .NET (C#, VB.NET, ASP) / [SOLUCIONADO] problema con Random en: 18 Enero 2013, 17:18 pm
¿Que debo hacer para que esto funcione?

Si declaro la variable "Rando" fuera de la función, funciona, pero precísamente lo que pretendo es ahorrarme la necesidad de declarar la variable fuera de la función... xD

Código
  1. Public Class Form1
  2.  
  3.    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  4.        Dim a As New List(Of String)
  5.        For x As Integer = 0 To 10 : a.Add(Get_Random_Number(1, 100)) : Next
  6.  
  7.        For Each f In a : MsgBox(f) : Next ' El número siempre es el mismo
  8.  
  9.    End Sub
  10.  
  11.    Public Function Get_Random_Number(ByVal min As Integer, ByVal max As Integer) As Integer
  12.        Dim Rando As New Random
  13.        Return Rando.Next(min, max)
  14.    End Function
  15.  
  16. End Class
9694  Programación / .NET (C#, VB.NET, ASP) / Re: Bucles en: 18 Enero 2013, 16:42 pm
Código
  1. Public Class Form1
  2.  
  3.    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  4.  
  5.        Me.Size = New Point(600, 600)
  6.        Dim Rando As New Random
  7.  
  8.        ' Creo los controles y los añado al form, para este ejemplo.
  9.        Dim Button_(10) As Button
  10.        For num = 0 To 10 : Button_(num) = New Button : Me.Controls.Add(Button_(num)) : Next
  11.  
  12.        For Each Control In Me.Controls
  13.            If Control.GetType.ToString.Contains("Button") Then ' Si el control es de tipo Button...
  14.                Control.location = New Point(Rando.Next(1, 500), Rando.Next(1, 500)) ' Los coloco aleatóriamente
  15.            End If
  16.        Next
  17.    End Sub
  18.  
  19. End Class
9695  Programación / .NET (C#, VB.NET, ASP) / Re: [APORTE] Snippets !! (Posteen aquí sus snippets) en: 18 Enero 2013, 16:03 pm
Sí xDDDDDD, apuntes convertidos en funciones/snippets, creo que para lo poco que sé de .NET me lo curro ;D.
9696  Programación / .NET (C#, VB.NET, ASP) / Re: [APORTE] Snippets !! (Posteen aquí sus snippets) en: 18 Enero 2013, 14:06 pm
No es mucho, pero puede servir...

Obtener la ruta del directorio o del archivo "user.config"

Código
  1. #Region " Get User Config Function "
  2.  
  3.    ' [ Get User Config Function ]
  4.    '
  5.    ' // By Elektro H@cker (Gracias a Seba123Neo)
  6.    '
  7.    ' Examples :
  8.    '
  9.    ' * First add a reference to "System.Configuration" in the proyect
  10.    '
  11.    ' MsgBox(Get_User_Config(User_Config.File))
  12.    ' MsgBox(Get_User_Config(User_Config.Path))
  13.  
  14.    Enum User_Config
  15.        File
  16.        Path
  17.    End Enum
  18.  
  19.    Private Function Get_User_Config(ByVal Setting As User_Config) As String
  20.        Dim UserConfig As String = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.PerUserRoaming).FilePath
  21.        Select Case Setting
  22.            Case User_Config.File : Return UserConfig
  23.            Case User_Config.Path : Return UserConfig.Substring(0, UserConfig.LastIndexOf("\"))
  24.            Case Else : Return False
  25.        End Select
  26.    End Function
  27.  
  28. #End Region
9697  Programación / .NET (C#, VB.NET, ASP) / Re: [SOLUCIONADO] Ejecutar recurso embedido del programa? en: 18 Enero 2013, 13:43 pm
ups perdón, a veces confundo importaciones con referencias :rolleyes:

ya me funciona,
saludos.
9698  Programación / .NET (C#, VB.NET, ASP) / Re: Una pregunta sobre IO.Directory.GetFiles en: 18 Enero 2013, 13:17 pm
Puf, para perder tiempo de lectura de disco haciendo múltiples búsquedas y/o filtrando la lista... busco algo más "natural"
creo que jamás diría esto, pero es que para eso es mejor usar el comando "DIR" de la CMD (en VB.NET) sincéramente xD.

@3mp3z@ndo
Gracias por la info , parece la mejor opción pero me queda la duda,

¿Esto solo hace una búsqueda y filtra, o hace dos búsquedas?
Código
  1. Dim files = Directory.GetFiles("C:\", "*").Where(Function(s) s.EndsWith(".exe") OrElse s.EndsWith(".xml"))
9699  Programación / .NET (C#, VB.NET, ASP) / Re: [APORTE] Snippets !! (Posteen aquí sus snippets) en: 18 Enero 2013, 11:27 am
Obtener la arquitectura del OS

Código
  1. #Region " Get OS Architecture Function "
  2.  
  3.    ' [ Get OS Architecture Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' Dim Architecture = Get_OS_Architecture()
  9.  
  10.    Private Function Get_OS_Architecture() As Integer
  11.        Dim Bits = Runtime.InteropServices.Marshal.SizeOf(GetType(IntPtr)) * 8
  12.        Select Case Bits
  13.            Case 32 : Return 32 ' x86
  14.            Case 64 : Return 64 ' x64
  15.            Case Else : Return Nothing ' xD
  16.        End Select
  17.    End Function
  18.  
  19. #End Region



Ejemplo de un overload

Código
  1.    ' Examples:
  2.    '
  3.    ' Test(0)
  4.    ' Test"0")
  5.  
  6.    Sub Test(ByVal Argument As Integer)
  7.        MsgBox("Integer: " & Argument)
  8.    End Sub
  9.  
  10.    Sub Test(ByVal Argument As String)
  11.        MsgBox("String: " & Argument)
  12.    End Sub



El snippet de Get All Files, mejorado:

Código
  1. #Region " Get All Files Function "
  2.  
  3.    ' [ Get All Files Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples:
  8.    '
  9.    ' Dim Files As Array = Get_All_Files("C:\Test", True)
  10.    ' For Each File In Get_All_Files("C:\Test", False) : MsgBox(File) : Next
  11.  
  12.    Private Function Get_All_Files(ByVal Directory As String, Optional ByVal Recursive As Boolean = False) As Array
  13.        If System.IO.Directory.Exists(Directory) Then
  14.            If Not Recursive Then : Return System.IO.Directory.GetFiles(Directory, "*", IO.SearchOption.TopDirectoryOnly)
  15.            Else : Return IO.Directory.GetFiles(Directory, "*", IO.SearchOption.AllDirectories)
  16.            End If
  17.        Else
  18.            Return Nothing
  19.        End If
  20.    End Function
  21.  
  22. #End Region
9700  Programación / .NET (C#, VB.NET, ASP) / [SOLUCIONADO] Una pregunta sobre IO.Directory.GetFiles en: 18 Enero 2013, 10:10 am
¿No se puede usar algún separador de expresión?

He intentado esto:

Código
  1. IO.Directory.GetFiles(Directory, "*.exe, *.vb")
  2.  
  3. IO.Directory.GetFiles(Directory, "*.exe; *.vb")
  4.  
  5. IO.Directory.GetFiles(Directory, "*.exe" + "*.vb")
  6.  
  7. IO.Directory.GetFiles(Directory, "*.exe" + IO.Path.AltDirectorySeparatorChar + "*.vb")
  8.  
  9. IO.Directory.GetFiles(Directory, "*.exe" + IO.Path.DirectorySeparatorChar + "*.vb")
Páginas: 1 ... 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 [970] 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 ... 1232
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines