none
How to declare all listbox items as integers. (Visual Studio)(Visual Basic) RRS feed

  • Question

  • My program contains 6 listboxes, one has values 1000 - 1025, those value will be decomposed into their respective digit placement, 1rst listbox = for 1rst digits, 2nd listbox = for 2nd digits... The final is the reassembly of the decomposed values. 

    [1025] [1] [0] [2] [5] [1025]            [ ] = Listbox

    My problem is, my code works for numbers indiviudally with a textbox, i need it to be converted so it can decomposed all items in a list box. Can anyone help me?

    My program works like this:

    TextBox = [1025]  

    Label = [First digit : 1 , Second digit : 0, Third digit : 2, Last digit : 5]

    It can separate invdivual numbers, I need it so it can run throwout all numbers inserted in a listbox.

    For Dividing numbers that contain four digits I use this part of code:

            number = TextBox1.Text

            Digit1 = number \ 1000
            number = number Mod 1000
            Digit2 = number \ 100
            number = number Mod 100
            Digit3 = number \ 10
            number = number Mod 10
            Digit4 = number

    Then its passed threw a If Statement to figure out if its a four digit value, 3 digit value... And displays it. Using something like this:

     ElseIf (NumberInserted > 1000) And (NumberInserted < 9999) Then
                Call SeperateFourDigits(NombreInscrit, Thousands, Hundreds, Tens, Units)
                Me.lblDigits.Text = "Digit 1 :" & Thousand & vbCrLf &
                                            "Digit 2: " & Hundred & vbCrLf &
                                            "Digit3 : " & Tens & vbCrLf &
                                            "Digit4: " & Units

    My full code that was a translation from french to english (so exuse grammaire mistakes) and is very incomplete is:

    https://docs.google.com/document/d/1x2IHuLt61h2usaQRvr00gRzkce4gMKPrb8-Oq9iLHTA/edit 

    Thanks to anyone that can help, any more information on the code just ask.

     

    Thursday, November 29, 2018 6:27 PM

All replies

  • Hi

    Here is some code that I think is similar to what I think you want :)Needs a Form1 with ListBox1 and Label named 'lblDigits'. When run, selected item will be split as suggested.

    Image

    Code

    Option Strict On
    Option Explicit On
    Public Class Form1
      Dim r As New Random
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        For i As Integer = 1 To 20
          ListBox1.Items.Add(r.Next(1001, 9999))
        Next
      End Sub
      Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
        Dim s() As Char = ListBox1.SelectedItem.ToString.ToArray
        lblDigits.Text = s(0) & " Thousands" & vbCrLf & s(1) & " Hundreds" & vbCrLf & s(2) & " Tens" & vbCrLf & s(3) & " Units"
      End Sub
    End Class


    Regards Les, Livingston, Scotland

    Thursday, November 29, 2018 7:50 PM