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

 

 


Tema destacado: Tutorial básico de Quickjs


  Mostrar Mensajes
Páginas: 1 ... 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 [33] 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 ... 55
321  Programación / .NET (C#, VB.NET, ASP) / Re: Mis malas combinaciones :( en: 29 Agosto 2014, 18:09 pm
Hola pongo el código entero, lo de poner los números en la variable es como difícil sin tener que cortar el código, que como veras hace una serie de cálculos con 20 dígitos que introduzco y saber cuantos números salen de esa ecuación es un poco difícil


Codigo

Código
  1. Public Class Form1
  2.    Dim maximum As Short = 99
  3.    Dim Número As Double
  4.    Private TextBoxes As TextBox() = {Nothing}
  5.    Private Result1 As Int32(), Result2 As Int32(), Result3 As Int32(), Result4 As Int32(), Result5 As Int32(), Result6 As Int32(), Result7 As Int32(), Result8 As Int32(), Result9 As Int32(), Result10 As Int32(), Result11 As Int32(), Result12 As Int32(), Result13 As Int32(), Result14 As Int32(), Result15 As Int32(), Result16 As Int32(), Result17 As Int32(), Result18 As Int32(), Result19 As Int32(), Result20 As Int32()
  6.    Private _textBox As Object
  7.    ReadOnly MAX As Integer = 99
  8.    Dim Rand As New Random
  9.    Dim Rand2 As New Random
  10.    Dim Result22 As Integer
  11.    Dim Counter, Counter2 As Integer
  12.    Dim myLabelArray(6) As Label
  13.    Dim x As Integer = 0
  14.    Private Property ListBox1Count As Integer
  15.    ReadOnly Randomizer As New Random
  16.    Dim Combo As List(Of Integer) = Nothing
  17.    Dim Combos As New List(Of List(Of Integer))
  18.    Dim FixedValues As Integer() = Nothing
  19.    ReadOnly RandomValues As Integer() =
  20.        Enumerable.Range(0, 99).ToArray
  21.  
  22.    Public Sub solonumeros(ByRef e As System.Windows.Forms.KeyPressEventArgs)
  23.        ' evitar letras
  24.        If Char.IsDigit(e.KeyChar) Then
  25.            e.Handled = False
  26.        ElseIf Char.IsControl(e.KeyChar) Then
  27.            e.Handled = False
  28.        ElseIf Char.IsSeparator(e.KeyChar) Then
  29.            e.Handled = False
  30.        Else
  31.            e.Handled = True
  32.        End If
  33.  
  34.    End Sub
  35.  
  36.    Private Property Calcular As Object
  37.  
  38.    Private Property TextBox(ByVal TextBoxCount As Short) As Object
  39.        Get
  40.            Return _textBox
  41.        End Get
  42.        Set(ByVal value As Object)
  43.            _textBox = value
  44.        End Set
  45.    End Property
  46.  
  47.    ReadOnly Property Num1 As Int32
  48.        Get
  49.            Return CInt(TextBox1.Text)
  50.        End Get
  51.    End Property
  52.    ReadOnly Property Num2 As Int32
  53.        Get
  54.            Return CInt(TextBox2.Text)
  55.        End Get
  56.    End Property
  57.    ReadOnly Property Num3 As Int32
  58.        Get
  59.            Return CInt(TextBox3.Text)
  60.        End Get
  61.    End Property
  62.    ReadOnly Property Num4 As Int32
  63.        Get
  64.            Return CInt(TextBox4.Text)
  65.        End Get
  66.    End Property
  67.  
  68.    ReadOnly Property Num5 As Int32
  69.        Get
  70.            Return CInt(TextBox5.Text)
  71.        End Get
  72.    End Property
  73.    '---------------------------------
  74.    ReadOnly Property Num6 As Int32
  75.        Get
  76.            Return CInt(TextBox6.Text)
  77.        End Get
  78.    End Property
  79.  
  80.    ReadOnly Property Num7 As Int32
  81.        Get
  82.            Return CInt(TextBox7.Text)
  83.        End Get
  84.    End Property
  85.    ReadOnly Property Num8 As Int32
  86.        Get
  87.            Return CInt(TextBox8.Text)
  88.        End Get
  89.    End Property
  90.    ReadOnly Property Num9 As Int32
  91.        Get
  92.            Return CInt(TextBox9.Text)
  93.        End Get
  94.    End Property
  95.    ReadOnly Property Num10 As Int32
  96.        Get
  97.            Return CInt(TextBox10.Text)
  98.        End Get
  99.    End Property
  100.    ReadOnly Property Num11 As Int32
  101.        Get
  102.            Return CInt(TextBox11.Text)
  103.        End Get
  104.    End Property
  105.    ReadOnly Property Num12 As Int32
  106.        Get
  107.            Return CInt(TextBox12.Text)
  108.        End Get
  109.    End Property
  110.    ReadOnly Property Num13 As Int32
  111.        Get
  112.            Return CInt(TextBox13.Text)
  113.        End Get
  114.    End Property
  115.    ReadOnly Property Num14 As Int32
  116.        Get
  117.            Return CInt(TextBox14.Text)
  118.        End Get
  119.    End Property
  120.    ReadOnly Property Num15 As Int32
  121.        Get
  122.            Return CInt(TextBox15.Text)
  123.        End Get
  124.    End Property
  125.  
  126.    ReadOnly Property Num16 As Int32
  127.        Get
  128.            Return CInt(TextBox16.Text)
  129.        End Get
  130.    End Property
  131.    ReadOnly Property Num17 As Int32
  132.        Get
  133.            Return CInt(TextBox17.Text)
  134.        End Get
  135.    End Property
  136.    ReadOnly Property Num18 As Int32
  137.        Get
  138.            Return CInt(TextBox18.Text)
  139.        End Get
  140.    End Property
  141.    ReadOnly Property Num19 As Int32
  142.        Get
  143.            Return CInt(TextBox19.Text)
  144.        End Get
  145.    End Property
  146.    ReadOnly Property Num20 As Int32
  147.        Get
  148.            Return CInt(TextBox20.Text)
  149.        End Get
  150.    End Property
  151.  
  152.    Private Sub Sumar(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
  153.        '--------------------------------------------------
  154.        Dim Result1 As Integer() = {Num1 - 1, Num1 - 2, Num1 - 3, Num1 + 1, Num1 + 2, Num1 + 3}
  155.  
  156.        For Index As Integer = 0 To (Result1.Count - 1)
  157.  
  158.            Select Case Result1(Index)
  159.  
  160.                Case Is = 0 ' El valor es 0. esto todavia no me funciona
  161.                    ' Hacer algo con el número 0 aquí. no mostrar el 0
  162.                    '   Result1(Index) = Not 0
  163.  
  164.                Case Is < 0 ' El valor es negativo.
  165.                    ' Lo convierto a positivo si funciona.
  166.                    Result1(Index) = Math.Abs(Result1(Index))
  167.  
  168.            End Select '/ Result1(Index)
  169.  
  170.  
  171.        Next Index
  172.  
  173.        Result1 = Result1.Distinct().ToArray
  174.        Array.Sort(Result1)
  175.  
  176.        '---------------------------------------------------
  177.  
  178.        Result2 = {Num2 + 1, Num2 + 2, Num2 + 3, Num2 - 1, Num2 - 2} _
  179.                  .Distinct().ToArray
  180.        Array.Sort(Result2)
  181.  
  182.        Result3 = {Num3 + 1, Num3 + 2, Num3 + 3, Num3 - 1, Num3 - 2, Num3 - 3} _
  183.                  .Distinct().ToArray
  184.        Array.Sort(Result3)
  185.  
  186.        Result4 = {Num4 + 1, Num4 + 2, Num4 + 3, Num4 - 1, Num4 - 2, Num4 - 3} _
  187.                  .Distinct().ToArray
  188.        Array.Sort(Result4)
  189.  
  190.        Result5 = {Num5 + 1, Num5 + 2, Num5 + 3, Num5 - 1, Num5 - 2, Num5 - 3} _
  191.                  .Distinct().ToArray
  192.        Array.Sort(Result5)
  193.  
  194.        Result6 = {Num6 + 1, Num6 + 2, Num6 + 3, Num6 - 1, Num6 - 2, Num6 - 3} _
  195.                  .Distinct().ToArray
  196.  
  197.        Array.Sort(Result6)
  198.  
  199.        Result7 = {Num7 + 1, Num7 + 2, Num7 + 3, Num7 - 1, Num7 - 2, Num7 - 3} _
  200.                  .Distinct().ToArray
  201.  
  202.        Array.Sort(Result7)
  203.  
  204.        Result8 = {Num8 + 1, Num8 + 2, Num8 + 3, Num8 - 1, Num8 - 2, Num8 - 3} _
  205.                  .Distinct().ToArray
  206.        Array.Sort(Result8)
  207.  
  208.        Result9 = {Num9 + 1, Num9 + 2, Num9 + 3, Num9 - 1, Num9 - 2, Num9 - 3} _
  209.                  .Distinct().ToArray
  210.        Array.Sort(Result9)
  211.  
  212.        Result10 = {Num10 + 1, Num10 + 2, Num10 - 1, Num10 - 2, Num10 - 3} _
  213.                  .Distinct().ToArray
  214.        Array.Sort(Result10)
  215.  
  216.        Result11 = {Num11 + 1, Num11 + 2, Num11 + 3, Num11 - 1, Num11 - 2, Num11 - 3} _
  217.                  .Distinct().ToArray
  218.        Array.Sort(Result11)
  219.  
  220.        Result12 = {Num12 + 1, Num12 + 2, Num12 + 3, Num12 - 1, Num12 - 2, Num12 - 3} _
  221.                  .Distinct().ToArray
  222.        Array.Sort(Result12)
  223.  
  224.        Result13 = {Num13 + 1, Num13 + 2, Num13 + 3, Num13 - 1, Num13 - 2, Num13 - 3} _
  225.                  .Distinct().ToArray
  226.        Array.Sort(Result13)
  227.  
  228.        Result14 = {Num14 + 1, Num14 + 2, Num14 + 3, Num14 - 1, Num14 - 2, Num14 - 3} _
  229.                  .Distinct().ToArray
  230.        Array.Sort(Result14)
  231.  
  232.        Result15 = {Num15 + 1, Num15 + 2, Num15 + 3, Num15 - 1, Num15 - 2, Num15 - 3} _
  233.                  .Distinct().ToArray
  234.        Array.Sort(Result15)
  235.  
  236.        Result16 = {Num16 + 1, Num16 + 2, Num16 + 3, Num16 - 1, Num16 - 2, Num16 - 3} _
  237.                  .Distinct().ToArray
  238.        Array.Sort(Result16)
  239.  
  240.        Result17 = {Num17 + 1, Num17 + 2, Num17 + 3, Num17 - 1, Num17 - 2, Num17 - 3} _
  241.                  .Distinct().ToArray
  242.        Array.Sort(Result17)
  243.  
  244.        Result18 = {Num18 + 1, Num18 + 2, Num18 + 3, Num18 - 1, Num18 - 2, Num18 - 3} _
  245.                  .Distinct().ToArray
  246.        Array.Sort(Result18)
  247.  
  248.        Result19 = {Num19 + 1, Num19 + 2, Num19 + 3, Num19 - 1, Num19 - 2, Num19 - 3} _
  249.                  .Distinct().ToArray
  250.  
  251.        Array.Sort(Result19)
  252.        Result20 = {Num20 + 1, Num20 + 2, Num20 + 3, Num20 - 1, Num20 - 2, Num20 - 3} _
  253.                  .Distinct().ToArray
  254.  
  255.        Array.Sort(Result20)
  256.        ' Elimino duplicados al mismo tiempo que selecciono los números inferiores a MAX.
  257.        Dim Resultss As IEnumerable(Of Integer) =
  258.            (
  259.                From Value As Integer
  260.                In (Result1.Concat(Result2).Concat(Result3).Concat(Result4).Concat(Result5).Concat(Result6).Concat(Result7).Concat(Result8).Concat(Result9).Concat(Result10).Concat(Result11).Concat(Result12).Concat(Result13).Concat(Result14).Concat(Result15).Concat(Result16).Concat(Result17).Concat(Result18).Concat(Result19).Concat(Result20)).Distinct
  261.                Where Value <= MAX
  262.            )
  263.  
  264.        ListBox2.Items.AddRange(Resultss.Cast(Of Object).ToArray)
  265.  
  266.        'funcion unir combis
  267.        FixedValues =
  268.             ((Result1.Concat(Result2).Concat(Result3).Concat(Result4).Concat(Result5).Concat(Result6).Concat(Result7).Concat(Result8).Concat(Result9).Concat(Result10).Concat(Result11).Concat(Result12).Concat(Result13).Concat(Result14).Concat(Result15).Concat(Result16).Concat(Result17).Concat(Result18).Concat(Result19).Concat(Result20)).Distinct).
  269.             Distinct.
  270.             Select(Function(Value As Integer)
  271.                        Return If(Value < MAX, Value, Rand.Next(0, MAX))
  272.                    End Function).ToArray
  273.  
  274.        Dim IndexCounter As Integer = FixedValues.First ' 1
  275.        Dim LenCounter As Integer = 0I
  276.  
  277.        Const NumStep As Integer = 3I
  278.        Const NumLen As Integer = 10I
  279.  
  280.        Do Until IndexCounter > FixedValues.Last
  281.  
  282.            Combo = New List(Of Integer)
  283.  
  284.  
  285.            For Num As Integer = IndexCounter To (FixedValues.Count - 1I) Step NumStep
  286.  
  287.                LenCounter += 1I
  288.                Combo.Add(FixedValues(Num - 1I)) 'matrix fuersa
  289.  
  290.                If LenCounter >= NumLen Then
  291.                    Exit For
  292.                End If
  293.  
  294.            Next Num
  295.  
  296.            If LenCounter < NumLen Then
  297.  
  298.                For RandomNum As Integer = 1I To (NumLen - LenCounter)
  299.  
  300.                    Dim n As Integer = Randomizer.Next(RandomValues.First, RandomValues.Last)
  301.  
  302.                    Do Until Not Combo.Contains(n)
  303.                        n = Randomizer.Next(RandomValues.First, RandomValues.Last)
  304.                    Loop
  305.  
  306.                    Combo.Add(n)
  307.  
  308.                Next ' RandomNum
  309.  
  310.            End If ' LenCounter < NumLen
  311.  
  312. #If DEBUG Then ' #Debug
  313.            Debug.WriteLine(String.Join(", ", Combo))
  314.            ' Stop
  315. #End If
  316.            Combo.Sort()
  317.            Combos.Add(Combo)
  318.            IndexCounter += 1I
  319.            LenCounter = 0I
  320.  
  321.        Loop ' IndexCounter >= FixedValues.Last
  322.  
  323.        ' ******** ordenamiento-------------
  324.        '  Dim values As Integer() = (From n As Integer In Combos Order By n Ascending).ToArray
  325.  
  326.        ' ********
  327.        ' Listbox:
  328.        ' ********
  329.        Combos.ForEach(Sub(comb As List(Of Integer))
  330.  
  331.                           ' Convierto la Lista a 'String', le añado los ceros, y añado el string formateado al Listbox.
  332.                           ListBox1.Items.Add(String.Join(", ",
  333.                                                          From value As String In comb
  334.                                                          Select If(value.Length = 1I,
  335.                                                                    value.Insert(0I, "0"c),
  336.                                                                    value)))
  337.                           ListBox1.Sorted = True
  338.  
  339.  
  340.  
  341.                       End Sub)
  342.  
  343.    End Sub
  344.  
  345.  
  346.        ' Application.Exit()
  347.  
  348.    Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
  349.        sender.text = System.Text.RegularExpressions.Regex.Replace(sender.text, "\D", "")
  350.  
  351.    End Sub
  352.  
  353.    Private Sub TextBox3_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
  354.        sender.text = System.Text.RegularExpressions.Regex.Replace(sender.text, "\D", "")
  355.    End Sub
  356.  
  357.    Private Sub TextBox4_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
  358.        sender.text = System.Text.RegularExpressions.Regex.Replace(sender.text, "\D", "")
  359.    End Sub
  360.  
  361.    Private Sub TextBox5_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
  362.        sender.text = System.Text.RegularExpressions.Regex.Replace(sender.text, "\D", "")
  363.    End Sub
  364.  
  365.    Private Sub TextBox2_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
  366.        sender.text = System.Text.RegularExpressions.Regex.Replace(sender.text, "\D", "")
  367.    End Sub
  368.  
  369.  
  370.    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  371.  
  372.    End Sub
  373.  
  374.    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
  375.        solonumeros(e)
  376.        If e.KeyChar = ChrW(Keys.Enter) Then
  377.            e.Handled = True
  378.            SendKeys.Send("{TAB}")
  379.        End If
  380.    End Sub
  381.  
  382.    Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
  383.        solonumeros(e)
  384.        If e.KeyChar = ChrW(Keys.Enter) Then
  385.            e.Handled = True
  386.            SendKeys.Send("{TAB}")
  387.        End If
  388.    End Sub
  389.  
  390.    Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
  391.        solonumeros(e)
  392.        If e.KeyChar = ChrW(Keys.Enter) Then
  393.            e.Handled = True
  394.            SendKeys.Send("{TAB}")
  395.        End If
  396.    End Sub
  397.  
  398.    Private Sub TextBox4_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
  399.        solonumeros(e)
  400.        If e.KeyChar = ChrW(Keys.Enter) Then
  401.            e.Handled = True
  402.            SendKeys.Send("{TAB}")
  403.        End If
  404.    End Sub
  405.  
  406.    Private Sub TextBox5_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox5.KeyPress
  407.        solonumeros(e)
  408.        If e.KeyChar = ChrW(Keys.Enter) Then
  409.            e.Handled = True
  410.            SendKeys.Send("{TAB}")
  411.        End If
  412.    End Sub
  413.    Private Sub TextBox6_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox6.KeyPress
  414.        solonumeros(e)
  415.        If e.KeyChar = ChrW(Keys.Enter) Then
  416.            e.Handled = True
  417.            SendKeys.Send("{TAB}")
  418.  
  419.        End If
  420.  
  421.    End Sub
  422.    Private Sub TextBox7_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox7.KeyPress
  423.        solonumeros(e)
  424.        If e.KeyChar = ChrW(Keys.Enter) Then
  425.            e.Handled = True
  426.            SendKeys.Send("{TAB}")
  427.  
  428.        End If
  429.  
  430.    End Sub
  431.  
  432.    Private Sub TextBox8_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox8.KeyPress
  433.        solonumeros(e)
  434.        If e.KeyChar = ChrW(Keys.Enter) Then
  435.            e.Handled = True
  436.            SendKeys.Send("{TAB}")
  437.  
  438.        End If
  439.  
  440.    End Sub
  441.  
  442.    Private Sub TextBox9_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox9.KeyPress
  443.        solonumeros(e)
  444.        If e.KeyChar = ChrW(Keys.Enter) Then
  445.            e.Handled = True
  446.            SendKeys.Send("{TAB}")
  447.  
  448.        End If
  449.  
  450.    End Sub
  451.    Private Sub TextBox10_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox10.KeyPress
  452.        solonumeros(e)
  453.        If e.KeyChar = ChrW(Keys.Enter) Then
  454.            e.Handled = True
  455.            SendKeys.Send("{TAB}")
  456.  
  457.        End If
  458.  
  459.    End Sub
  460.  
  461.    Private Sub TextBox11_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox11.KeyPress
  462.        solonumeros(e)
  463.        If e.KeyChar = ChrW(Keys.Enter) Then
  464.            e.Handled = True
  465.            SendKeys.Send("{TAB}")
  466.  
  467.        End If
  468.  
  469.    End Sub
  470.    Private Sub TextBox12_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox12.KeyPress
  471.        solonumeros(e)
  472.        If e.KeyChar = ChrW(Keys.Enter) Then
  473.            e.Handled = True
  474.            SendKeys.Send("{TAB}")
  475.  
  476.        End If
  477.  
  478.    End Sub
  479.    Private Sub TextBox13_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox13.KeyPress
  480.        solonumeros(e)
  481.        If e.KeyChar = ChrW(Keys.Enter) Then
  482.            e.Handled = True
  483.            SendKeys.Send("{TAB}")
  484.  
  485.        End If
  486.  
  487.    End Sub
  488.    Private Sub TextBox14_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox14.KeyPress
  489.        solonumeros(e)
  490.        If e.KeyChar = ChrW(Keys.Enter) Then
  491.            e.Handled = True
  492.            SendKeys.Send("{TAB}")
  493.  
  494.        End If
  495.  
  496.    End Sub
  497.    Private Sub TextBox15_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox15.KeyPress
  498.        solonumeros(e)
  499.        If e.KeyChar = ChrW(Keys.Enter) Then
  500.            e.Handled = True
  501.            SendKeys.Send("{TAB}")
  502.  
  503.        End If
  504.  
  505.    End Sub
  506.    Private Sub TextBox16_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox16.KeyPress
  507.        solonumeros(e)
  508.        If e.KeyChar = ChrW(Keys.Enter) Then
  509.            e.Handled = True
  510.            SendKeys.Send("{TAB}")
  511.  
  512.        End If
  513.  
  514.    End Sub
  515.    Private Sub TextBox17_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox17.KeyPress
  516.        solonumeros(e)
  517.        If e.KeyChar = ChrW(Keys.Enter) Then
  518.            e.Handled = True
  519.            SendKeys.Send("{TAB}")
  520.  
  521.        End If
  522.  
  523.    End Sub
  524.    Private Sub TextBox18_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox18.KeyPress
  525.        solonumeros(e)
  526.        If e.KeyChar = ChrW(Keys.Enter) Then
  527.            e.Handled = True
  528.            SendKeys.Send("{TAB}")
  529.  
  530.        End If
  531.  
  532.    End Sub
  533.    Private Sub TextBox19_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox19.KeyPress
  534.        solonumeros(e)
  535.        If e.KeyChar = ChrW(Keys.Enter) Then
  536.            e.Handled = True
  537.            SendKeys.Send("{TAB}")
  538.  
  539.        End If
  540.  
  541.    End Sub
  542.    Private Sub TextBox20_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox20.KeyPress
  543.        solonumeros(e)
  544.        If e.KeyChar = ChrW(Keys.Enter) Then
  545.            e.Handled = True
  546.            SendKeys.Send("{TAB}")
  547.  
  548.        End If
  549.  
  550.    End Sub
  551.  
  552.    Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  553.        For Each obj As Control In Me.Controls
  554.            If (TypeOf obj Is TextBox) Then
  555.                obj.Text = ""
  556.            End If
  557.            If (TypeOf obj Is GroupBox) Then
  558.                For Each caja As Control In obj.Controls
  559.                    If (TypeOf caja Is TextBox) Then
  560.                        caja.Text = ""
  561.                    End If
  562.                Next
  563.            End If
  564.            ListBox1.Items.Clear()
  565.  
  566.  
  567.        Next
  568.    End Sub
  569.  
  570. End Class
  571.  
  572.  
  573.  
  574.  


322  Programación / .NET (C#, VB.NET, ASP) / Re: Mis malas combinaciones :( en: 29 Agosto 2014, 16:42 pm
Sigue igual :(

sera porque la función que estoy empleando no tiene un largo especifico ? ya que como me da 50 números unas veces otras  también puede dar 80 o sea que los números a combinar nunca son del mismo largo o cantidades ..

Edito) me he dado cuenta que si colocoal principio en el imput números desde el 01 hasta el 09 me produce el error y a partir del numero 10 no lo hace ???

 " Índice fuera de los límites de la matriz "

Luis
323  Programación / .NET (C#, VB.NET, ASP) / Re: Mis malas combinaciones :( en: 29 Agosto 2014, 15:19 pm
otro rollo jejej

Trasteando para aumentar los números ahora me encuentro este error cuando ejecuto el programa pero lo curioso es que con algunos numeros que introduzco no lo hace y variando estos números ( imput) si me sale el error ? si entiendo que se sale de la capacidad del la variable pero lo que no entiendo donde aumentar esta capacidad


 " Índice fuera de los límites de la matriz "



Código
  1. For Num As Integer = IndexCounter To (FixedValues.Count) Step NumStep
  2.  
  3.                LenCounter += 1I
  4.                Combo.Add(FixedValues(Num - 1I)) '<-------Índice fuera de los límites de la matriz.
  5.                If LenCounter >= NumLen Then
  6.                    Exit For
  7.                End If
  8.  
  9.            Next Num



Luis
324  Programación / .NET (C#, VB.NET, ASP) / Re: Mis malas combinaciones :( en: 29 Agosto 2014, 12:10 pm
Hola
Hice lo que me pones pero me sigue dando error,


   " no se controlo InvalidCastException "

No se puede convertir un objeto de tipo 'WhereSelectEnumerableIterator`2[System.Int32,System.Int32]' al tipo 'System.Int32[]'.



sugerencias " Cuando realiza la conversion de un numero,el valor debe ser un numero menor que intinito "
" asegurese que el tipo de origen se puede convertir en el tipo de destino"


SOLUCIONADO " Cada dia me pongo mas ciego y leo mal jejeje )


gracias Elektro

Luis



325  Programación / .NET (C#, VB.NET, ASP) / Re: Mis malas combinaciones :( en: 29 Agosto 2014, 02:07 am
Bueno ya me vas cojiendo la idea :) y gracias por tu paciencia jeje.

Bien seguimos con los problemas ,y tienes razón en el desorden, es que tengo una mala maña , como quiero que funcione de una no presto atencion al orden y esa es una de mis fallas ;(

Bien lo ejecuto y me da este error en :

No se puede convertir un objeto de tipo 'WhereSelectEnumerableIterator`2[System.Int32,System.Int32]' al tipo 'System.Int32[]'



Código
  1. Dim Rand As New Random
  2.        FixedValues =
  3.            (Result1.Concat(Result2).Concat(Result3)).
  4.            Distinct.
  5.            Select(Function(Value As Integer)
  6.                       Return If(Value < MAX, Value, Rand.Next(0, MAX))
  7.                   End Function)
326  Programación / .NET (C#, VB.NET, ASP) / Re: Mis malas combinaciones :( en: 28 Agosto 2014, 14:55 pm
jeje AUXILIO, No de verdad que no tengo nocion de como unir esto ;( ya sera que confundo mucho con tantas cosas a la ves

Cuando lo ejecuto de una ves me hace lo del segundo codigo y se supone que debe ser cuando se ejecute el primero y cambie los valores de " FixedValues " con los de  " Result "


Chapuza que tengo echa :)

Código
  1. Imports System.IO
  2. Public Class Form1
  3.  
  4.    Dim maximum As Short = 99
  5.    Dim x As Integer = 0
  6.    Dim Número As Double
  7.    Private TextBoxes As TextBox() = {Nothing}
  8.    Private Result1 As Int32(), Result2 As Int32(), Result3 As Int32()
  9.    Private _textBox As Object
  10.    Private Property ListBox1Count As Integer
  11.    ReadOnly MAX As Integer = 99
  12.    ReadOnly Randomizer As New Random
  13.    Dim Combo As List(Of Integer) = Nothing
  14.    Dim Combos As New List(Of List(Of Integer))
  15.  
  16.    ReadOnly FixedValues As Integer() = {1, 5, 10, 15, 20, 25, 30, 33, 35, 38, 40, 45, 48}
  17.    ReadOnly RandomValues As Integer() =
  18.        Enumerable.Range(FixedValues.First, FixedValues.Last).ToArray ' 1 to 30
  19.  
  20.  
  21.    Private Property Calcular As Object
  22.  
  23.    Private Property TextBox(ByVal TextBoxCount As Short) As Object
  24.        Get
  25.            Return _textBox
  26.        End Get
  27.        Set(ByVal value As Object)
  28.            _textBox = value
  29.        End Set
  30.    End Property
  31.  
  32.    Public Sub solonumeros(ByRef e As System.Windows.Forms.KeyPressEventArgs)
  33.        ' evitar letras
  34.        If Char.IsDigit(e.KeyChar) Then
  35.            e.Handled = False
  36.        ElseIf Char.IsControl(e.KeyChar) Then
  37.            e.Handled = False
  38.        ElseIf Char.IsSeparator(e.KeyChar) Then
  39.            e.Handled = False
  40.        Else
  41.            e.Handled = True
  42.        End If
  43.  
  44.    End Sub
  45.  
  46.  
  47.    ReadOnly Property Num1 As Int32
  48.        Get
  49.            Return CInt(TextBox1.Text)
  50.        End Get
  51.    End Property
  52.  
  53.    ReadOnly Property Num2 As Int32
  54.        Get
  55.            Return CInt(TextBox2.Text)
  56.        End Get
  57.    End Property
  58.    ReadOnly Property Num3 As Int32
  59.        Get
  60.            Return CInt(TextBox3.Text)
  61.        End Get
  62.    End Property
  63.  
  64.  
  65.    Private Sub Sumar(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
  66.  
  67.  
  68.        Result1 = {Num1 + 1, Num1 + 2, Num1 + 4, Num1 + 6, Num1 - 4, Num1 - 1} _
  69.                  .Distinct().ToArray ' Elimino duplicados
  70.  
  71.        Result2 = {Num2 + 1, Num2 + 2, Num2 + 3, Num2 - 1, Num2 - 2, Num1 - 3} _
  72.                  .Distinct().ToArray ' Elimino duplicados
  73.  
  74.        Result3 = {Num3 - 1, Num3 - 2, Num3 - 3, Num3 + 2, Num3 + 3, Num3 + 5} _
  75.                  .Distinct().ToArray ' Elimino duplicados
  76.  
  77.  
  78.        Dim Rand As New Random
  79.        ' Concateno, y...
  80.        ' Elimino duplicados, y...
  81.        ' Selecciono los números inferiores a MAX, y...
  82.        ' Convierto los números mayores a MAX a números aleatorios entre 0 y MAX.
  83.        Dim Result As IEnumerable(Of Integer) =
  84.            (Result1.Concat(Result2).Concat(Result3)).
  85.            Distinct.
  86.            Select(Function(Value As Integer)
  87.                       Return If(Value < MAX, Value, Rand.Next(0, MAX))
  88.                   End Function)
  89.        ListBox1.Items.AddRange(Result.Cast(Of Object).ToArray)
  90.        ' ******** ------------------------------------------------------------------
  91.  
  92.  
  93.        ' Num ReadOnly FixedValues As Integer() =
  94.        ' Num   Enumerable.Range(1I, 49I).ToArray ' 1 to 30
  95.  
  96.    End Sub
  97.    Private Sub Test() Handles MyBase.Shown
  98.  
  99.        Dim IndexCounter As Integer = FixedValues.First ' 1
  100.        Dim LenCounter As Integer = 0I
  101.  
  102.        Const NumStep As Integer = 5I
  103.        Const NumLen As Integer = 6I
  104.  
  105.        Do Until IndexCounter > FixedValues.Last ' IndexCounter > 30
  106.  
  107.            Combo = New List(Of Integer)
  108.  
  109.            For Num As Integer = IndexCounter To (FixedValues.Count) Step NumStep
  110.  
  111.                LenCounter += 1I
  112.                Combo.Add(FixedValues(Num - 1I))
  113.  
  114.                If LenCounter >= NumLen Then
  115.                    Exit For
  116.                End If
  117.  
  118.            Next Num
  119.  
  120.  
  121.  
  122.            If LenCounter < NumLen Then ' If LenCounter < 10
  123.  
  124.                For RandomNum As Integer = 1I To (NumLen - LenCounter)
  125.  
  126.                    Dim n As Integer = Randomizer.Next(RandomValues.First, RandomValues.Last)
  127.  
  128.                    Do Until Not Combo.Contains(n)
  129.                        n = Randomizer.Next(RandomValues.First, RandomValues.Last)
  130.                    Loop
  131.  
  132.                    Combo.Add(n)
  133.  
  134.                Next ' RandomNum
  135.  
  136.            End If ' LenCounter < NumLen
  137.  
  138. #If DEBUG Then ' #Debug
  139.            Debug.WriteLine(String.Join(", ", Combo))
  140.            ' Stop
  141. #End If
  142.            Combo.Sort()
  143.            Combos.Add(Combo)
  144.            IndexCounter += 1I
  145.            LenCounter = 0I
  146.  
  147.        Loop ' IndexCounter >= FixedValues.Last
  148.  
  149.        ' ******** ordenamiento-------------
  150.        '  Dim values As Integer() = (From n As Integer In Combos Order By n Ascending).ToArray
  151.  
  152.        ' ********
  153.        ' Listbox:
  154.        ' ********
  155.        Combos.ForEach(Sub(comb As List(Of Integer))
  156.  
  157.                           ' Convierto la Lista a 'String', le añado los ceros, y añado el string formateado al Listbox.
  158.                           ListBox1.Items.Add(String.Join(", ",
  159.                                                          From value As String In comb
  160.                                                          Select If(value.Length = 1I,
  161.                                                                    value.Insert(0I, "0"c),
  162.                                                                    value)))
  163.                           ListBox1.Sorted = True
  164.  
  165.  
  166.  
  167.                       End Sub)
  168.    End Sub ' Test
  169.  
  170. End Class
  171.  
327  Programación / .NET (C#, VB.NET, ASP) / Re: Mis malas combinaciones :( en: 28 Agosto 2014, 14:18 pm
Gracias Elektro por tus consejos :) ahora tengo otro reto (para mi jeje) no me respondas que voy a ver si lo hago ( si no lo logro, grito auxilio ) tengo este código que ya conoces de sobra jejej

Código
  1. Public Class Form1
  2.  
  3.    Dim maximum As Short = 99
  4.    Dim x As Integer = 0
  5.    Dim Número As Double
  6.    Private TextBoxes As TextBox() = {Nothing}
  7.    Private Result1 As Int32(), Result2 As Int32(), Result3 As Int32()
  8.    Private _textBox As Object
  9.    Private Property ListBox1Count As Integer
  10.    ReadOnly MAX As Integer = 99
  11.  
  12.  
  13.  
  14.    Private Property Calcular As Object
  15.  
  16.    Private Property TextBox(ByVal TextBoxCount As Short) As Object
  17.        Get
  18.            Return _textBox
  19.        End Get
  20.        Set(ByVal value As Object)
  21.            _textBox = value
  22.        End Set
  23.    End Property
  24.  
  25.    Public Sub solonumeros(ByRef e As System.Windows.Forms.KeyPressEventArgs)
  26.        ' evitar letras
  27.        If Char.IsDigit(e.KeyChar) Then
  28.            e.Handled = False
  29.        ElseIf Char.IsControl(e.KeyChar) Then
  30.            e.Handled = False
  31.        ElseIf Char.IsSeparator(e.KeyChar) Then
  32.            e.Handled = False
  33.        Else
  34.            e.Handled = True
  35.        End If
  36.  
  37.    End Sub
  38.  
  39.  
  40.    ReadOnly Property Num1 As Int32
  41.        Get
  42.            Return CInt(TextBox1.Text)
  43.        End Get
  44.    End Property
  45.  
  46.    ReadOnly Property Num2 As Int32
  47.        Get
  48.            Return CInt(TextBox2.Text)
  49.        End Get
  50.    End Property
  51.    ReadOnly Property Num3 As Int32
  52.        Get
  53.            Return CInt(TextBox3.Text)
  54.        End Get
  55.    End Property
  56.  
  57.  
  58.    Private Sub Sumar(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
  59.  
  60.  
  61.        Result1 = {Num1 + 1, Num1 + 2, Num1 + 4, Num1 + 6, Num1 - 4, Num1 - 1} _
  62.                  .Distinct().ToArray ' Elimino duplicados
  63.  
  64.        Result2 = {Num2 + 1, Num2 + 2, Num2 + 3, Num2 - 1, Num2 - 2, Num1 - 3} _
  65.                  .Distinct().ToArray ' Elimino duplicados
  66.  
  67.        Result3 = {Num3 - 1, Num3 - 2, Num3 - 3, Num3 + 2, Num3 + 3, Num3 + 5} _
  68.                  .Distinct().ToArray ' Elimino duplicados
  69.  
  70.  
  71.        Dim Rand As New Random
  72.        ' Concateno, y...
  73.        ' Elimino duplicados, y...
  74.        ' Selecciono los números inferiores a MAX, y...
  75.        ' Convierto los números mayores a MAX a números aleatorios entre 0 y MAX.
  76.        Dim Result As IEnumerable(Of Integer) =
  77.            (Result1.Concat(Result2).Concat(Result3)).
  78.            Distinct.
  79.            Select(Function(Value As Integer)
  80.                       Return If(Value < MAX, Value, Rand.Next(0, MAX))
  81.                   End Function)
  82.        ListBox1.Items.AddRange(Result.Cast(Of Object).ToArray)
  83.    End Sub
  84. End Class
  85.  



Y quiero integrarlo a este que funciona ya gracias a ti :) donde  a la variable " FixedValues " enviarle los datos de la variable " Result "  ya seguro me dara errores del tipo integer :) y esas cosas jejej


Código
  1. Imports System.IO
  2.  
  3. Public Class LuisClass_v2
  4.  
  5.    ReadOnly Randomizer As New Random
  6.  
  7.    ' Num ReadOnly FixedValues As Integer() =
  8.    ' Num   Enumerable.Range(1I, 49I).ToArray ' 1 to 30
  9.  
  10.    ReadOnly FixedValues As Integer() = {1, 5, 10, 15, 20, 25, 30, 33, 35, 38, 40, 45, 48}
  11.  
  12.    ReadOnly RandomValues As Integer() =
  13.        Enumerable.Range(FixedValues.First, FixedValues.Last).ToArray ' 1 to 30
  14.  
  15.    Dim Combo As List(Of Integer) = Nothing
  16.    Dim Combos As New List(Of List(Of Integer))
  17.  
  18.    Private Sub Test() Handles MyBase.Shown
  19.  
  20.        Dim IndexCounter As Integer = FixedValues.First ' 1
  21.        Dim LenCounter As Integer = 0I
  22.  
  23.        Const NumStep As Integer = 5I
  24.        Const NumLen As Integer = 6I
  25.  
  26.        Do Until IndexCounter > FixedValues.Last ' IndexCounter > 30
  27.  
  28.            Combo = New List(Of Integer)
  29.  
  30.            For Num As Integer = IndexCounter To (FixedValues.Count) Step NumStep
  31.  
  32.                LenCounter += 1I
  33.                Combo.Add(FixedValues(Num - 1I))
  34.  
  35.                If LenCounter >= NumLen Then
  36.                    Exit For
  37.                End If
  38.  
  39.            Next Num
  40.  
  41.  
  42.  
  43.            If LenCounter < NumLen Then ' If LenCounter < 10
  44.  
  45.                For RandomNum As Integer = 1I To (NumLen - LenCounter)
  46.  
  47.                    Dim n As Integer = Randomizer.Next(RandomValues.First, RandomValues.Last)
  48.  
  49.                    Do Until Not Combo.Contains(n)
  50.                        n = Randomizer.Next(RandomValues.First, RandomValues.Last)
  51.                    Loop
  52.  
  53.                    Combo.Add(n)
  54.  
  55.                Next ' RandomNum
  56.  
  57.            End If ' LenCounter < NumLen
  58.  
  59. #If DEBUG Then ' #Debug
  60.            Debug.WriteLine(String.Join(", ", Combo))
  61.            ' Stop
  62. #End If
  63.            Combo.Sort()
  64.            Combos.Add(Combo)
  65.            IndexCounter += 1I
  66.            LenCounter = 0I
  67.  
  68.        Loop ' IndexCounter >= FixedValues.Last
  69.  
  70.        ' ******** ordenamiento-------------
  71.        '  Dim values As Integer() = (From n As Integer In Combos Order By n Ascending).ToArray
  72.  
  73.        ' ********
  74.        ' Listbox:
  75.        ' ********
  76.        Combos.ForEach(Sub(comb As List(Of Integer))
  77.  
  78.                           ' Convierto la Lista a 'String', le añado los ceros, y añado el string formateado al Listbox.
  79.                           ListBox1.Items.Add(String.Join(", ",
  80.                                                          From value As String In comb
  81.                                                          Select If(value.Length = 1I,
  82.                                                                    value.Insert(0I, "0"c),
  83.                                                                    value)))
  84.                           ListBox1.Sorted = True
  85.  
  86.  
  87.  
  88.                       End Sub)
  89.    End Sub ' Test
  90.  
  91.  
  92.  
  93.    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  94.        Dim rutaFichero As String
  95.        Dim i As Integer
  96.  
  97.        rutaFichero = Path.Combine(Application.StartupPath, "contenido_listbox.txt")
  98.        Dim fichero As New IO.StreamWriter(rutaFichero)
  99.        For i = 0 To ListBox1.Items.Count - 1
  100.            fichero.WriteLine(ListBox1.Items(i))
  101.        Next
  102.        fichero.Close()
  103.    End Sub
  104.    ' contar que no ay repetidos
  105.  
  106.    Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
  107.  
  108.        Label1.Text = CStr(ListBox1.Items.Count)
  109.  
  110.        Dim query = From item As String In ListBox1.Items.Cast(Of String)() _
  111.                    Order By item _
  112.                    Group By item = item _
  113.                    Into Total = Group, Count() _
  114.                    Select Total
  115.  
  116.        Dim msg As New System.Text.StringBuilder()
  117.  
  118.        For Each item In query
  119.            msg.AppendLine(String.Format("Combinaciones {0} existen {1}", item(0), item.Count))
  120.        Next
  121.  
  122.        MessageBox.Show(msg.ToString())
  123.  
  124.    End Sub
  125.  
  126.  
  127. End Class
  128.  


Gracias por tu paciencia

Luis






328  Programación / .NET (C#, VB.NET, ASP) / Re: Mis malas combinaciones :( en: 28 Agosto 2014, 13:23 pm
Solucionado ;)

Código
  1. Label1.Text = CStr(ListBox1.Items.Count)


luis
329  Programación / .NET (C#, VB.NET, ASP) / Re: Mis malas combinaciones :( en: 28 Agosto 2014, 13:11 pm
Como contar cuantas combinaciones hay en el listbox ?

Buscando encontre esta rutina funciona pero lo que hace es comparar las combinaciones y decirme que solo hay una combinacion eso lo sabemos ya que el pograma no da repetidos nesecito saber cuantas hay en total.

contar y mostrar    " Combinaciones = 30 "  o la cantidad que salgan :)

codigo que encontre a alguien le puede servir para comparar registros :)

Código
  1. ' contar que no ay repetidos
  2.  
  3.    Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
  4.  
  5.        Dim query = From item As String In ListBox1.Items.Cast(Of String)() _
  6.                    Order By item _
  7.                    Group By item = item _
  8.                    Into Total = Group, Count() _
  9.                    Select Total
  10.  
  11.        Dim msg As New System.Text.StringBuilder()
  12.  
  13.        For Each item In query
  14.            msg.AppendLine(String.Format("Combinaciones {0} existen {1}", item(0), item.Count))
  15.        Next
  16.  
  17.        MessageBox.Show(msg.ToString())
  18.  
  19.    End Sub
330  Programación / .NET (C#, VB.NET, ASP) / Re: Mis malas combinaciones :( en: 27 Agosto 2014, 06:06 am
Listo :)    funciona como quería

Muchas gracias elektro

Luis

( nos levantamos pronto ee)
Páginas: 1 ... 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 [33] 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 ... 55
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines