none
Problem with listbox RRS feed

  • Question

  • I want listbox accept English characters And symbols only

    symbols

     Example / or ؟ or ! ....

    Wednesday, September 20, 2017 9:21 PM

Answers

  • I want if the text in a non - English language message appears to stop copying in the listbox1

    Why do you refuse to provide an example of the data you are using?  It is a simple request.

    I will take a guess, but please do not ask for the code to be modified if the guess is wrong.

    Add this function to the SubTitle2 class:

        Public Overrides Function ToString() As String
            Static Match As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!?"
            Dim Temp As Char() = _text.ToCharArray
            Dim Outp As String = ""
            For Each c As Char In Temp
                If Match.Contains(c) Then Outp &= c.ToString
            Next
            Return (Outp)
        End Function

    Then replace 
       ListBox1.Items.Add(vb4)
    with
       ListBox1.Items.Add(SubT.ToString)

    • Marked as answer by jamilaid Friday, September 22, 2017 10:10 PM
    Thursday, September 21, 2017 9:58 PM

All replies

  • I want listbox accept English characters And symbols only symbols

     Example / or ؟ or ! ....

    A listbox 'accepts' what you put into it, and that is under program control.    If you want to control the contents of the list box then you need to ensure that any items you add to the listbox contain only the symbols that you want to use.  How you do that depends on where those items are coming from.  You should show the code that you are using to populate the listbox.
    Wednesday, September 20, 2017 9:26 PM
  • I want listbox accept English characters And symbols only symbols

     Example / or ؟ or ! ....

    A listbox 'accepts' what you put into it, and that is under program control.    If you want to control the contents of the list box then you need to ensure that any items you add to the listbox contain only the symbols that you want to use.  How you do that depends on where those items are coming from.  You should show the code that you are using to populate the listbox.

     OFD3.Filter = "|*.srt"
            OFD3.DefaultExt = "srt"
            If OFD3.ShowDialog() = DialogResult.OK Then

                Dim sr As New System.IO.StreamReader(OFD3.FileName, Encoding.Default)
                Dim SubT As SubTitle2
                Do While Not sr.EndOfStream
                    SubT = New SubTitle2
                    Dim Seq As String = sr.ReadLine

                    If Seq  <> "" Then
                        SubT.Sequence =Seq
                        SubT.strng1= sr.ReadLine

    end if

    (SubT.strng1)listbox.item.add
    • Edited by jamilaid Wednesday, September 20, 2017 9:34 PM
    Wednesday, September 20, 2017 9:32 PM
  • (SubT.strng1)listbox.item.add

    Do you mean

      Listbox1.Items.Add(SubT.ToString)

    If so then you need to show the SubT class, as that is where the ToString is calculated, and that is where the characters that you do not want to appear in the listbox listing will be stripped out.

    Wednesday, September 20, 2017 9:38 PM
  • Public Class SubTitle2Public Class SubTitle2
        

        Public Property Sequence As String
        Public Property strng1 As String

    End Class

    This Class did not understand what to do

    Wednesday, September 20, 2017 9:49 PM
  • Public Class SubTitle2Public Class SubTitle2
        Public Property Sequence As String
        Public Property strng1 As String
    End Class

    Provide an example of what the ToString for that class should be.   Show a sample for Sequence and for string1, and what should then appear in the list box.

    Wednesday, September 20, 2017 9:52 PM
  • Public Class SubTitle2Public Class SubTitle2
        Public Property Sequence As String
        Public Property strng1 As String
    End Class

    Provide an example of what the ToString for that class should be.   Show a sample for Sequence and for string1, and what should then appear in the list box.

    I am sorry but I would say that I did not understand

    Because I do not speak English and new in programming

    Wednesday, September 20, 2017 10:28 PM
  • I just want to show the English language only
    Not another language

    Of the "any.srt"

    If any.srt contains another language I want to show a message

    • Edited by jamilaid Wednesday, September 20, 2017 11:15 PM
    Wednesday, September 20, 2017 11:06 PM
  • I am sorry but I would say that I did not understand

    Your class uses these properties:
        Public Property Sequence As String
        Public Property strng1 As String

    It appears that you want to put a description from the class into a listbox, filtering out certain unwanted characters.   To do that you would use code like:
      Listbox1.Items.Add(SubT.ToString)

    where subT is an instance of SubTitle2.   Therefore, your class needs a ToString method.  That method will take the properties Sequence or strng1, or perhaps both, to create the ToString.  

    In order to provide more information about how you would do that it is necessary for you to provide an example of Sequence and strng1, and what the ToString string that is created from these values would look like.  Two examples would be even better.

    Wednesday, September 20, 2017 11:08 PM
  • Is there a theoretical example or anything that talks about the same subject?

    In order to benefit more
    Thursday, September 21, 2017 2:38 AM
  • Is there a theoretical example or anything that talks about the same subject?

    All you need to do is to provide the example values for Sequence and strng1, and how you want that object to appear in the list box.  There is no theory involved - it's a simple practical task, but it requires example data in order to demonstrate how it should be done.

    Thursday, September 21, 2017 2:44 AM
  •  I'm trying with this code

    Dim st As String = SubT.Text
                        Dim st2 As String
                        st2 = CStr(st.Contains("a"))
                        MessageBox.Show(st2)
                    End If

    Thursday, September 21, 2017 3:06 AM
  •  I'm trying with this code

    Dim st As String = SubT.Text
                        Dim st2 As String
                        st2 = CStr(st.Contains("a"))
                        MessageBox.Show(st2)
                    End If

    What is subT.Text?      I don't believe that exists.  But if you can show an example value for it then I can show you how to make sure that it only contains the characters you want.  But without an example to use, it's not possible to know what result you want.

    Thursday, September 21, 2017 3:11 AM
  • Hi jamilaid,

    According to your description and your thread's title, you want to accept English characters And symbols in the ListBox, so you could detect if the digit in char or not using char.IsDigit(), if not you can add this char. Do you want to like this:

    Dim dt1 As New DataTable
            dt1.Columns.Add("Column1", GetType(String))
            dt1.Rows.Add("1234asdfg")
            dt1.Rows.Add("asdj@#$")
            dt1.Rows.Add("12hj&^")
            dt1.Rows.Add("GHJY@#$")
            dt1.Rows.Add("&^%gh")
            dt1.Rows.Add("678jgh")
    
            For i As Integer = 0 To dt1.Rows.Count - 1
                If Char.IsDigit(dt1.Rows(i)(0)) = False Then
                    ListBox1.Items.Add(dt1.Rows(i)(0))
                Else
                    Continue For
                End If
            Next

    Best Regards,

    Cherry




     


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, September 21, 2017 5:36 AM
    Moderator
  • Hi jamilaid,

    According to your description and your thread's title, you want to accept English characters And symbols in the ListBox, so you could detect if the digit in char or not using char.IsDigit(), if not you can add this char. Do you want to like this:

    Dim dt1 As New DataTable
            dt1.Columns.Add("Column1", GetType(String))
            dt1.Rows.Add("1234asdfg")
            dt1.Rows.Add("asdj@#$")
            dt1.Rows.Add("12hj&^")
            dt1.Rows.Add("GHJY@#$")
            dt1.Rows.Add("&^%gh")
            dt1.Rows.Add("678jgh")
    
            For i As Integer = 0 To dt1.Rows.Count - 1
                If Char.IsDigit(dt1.Rows(i)(0)) = False Then
                    ListBox1.Items.Add(dt1.Rows(i)(0))
                Else
                    Continue For
                End If
            Next

    I converted with this code and it only replaces the text

    I want if the text in a non - English language message appears to stop copying in the textbox

    • Edited by jamilaid Thursday, September 21, 2017 3:05 PM
    Thursday, September 21, 2017 3:00 PM
  • I want if the text in a non - English language message appears to stop copying in the listbox1

    Why do you refuse to provide an example of the data you are using?  It is a simple request.

    I will take a guess, but please do not ask for the code to be modified if the guess is wrong.

    Add this function to the SubTitle2 class:

        Public Overrides Function ToString() As String
            Static Match As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!?"
            Dim Temp As Char() = _text.ToCharArray
            Dim Outp As String = ""
            For Each c As Char In Temp
                If Match.Contains(c) Then Outp &= c.ToString
            Next
            Return (Outp)
        End Function

    Then replace 
       ListBox1.Items.Add(vb4)
    with
       ListBox1.Items.Add(SubT.ToString)

    • Marked as answer by jamilaid Friday, September 22, 2017 10:10 PM
    Thursday, September 21, 2017 9:58 PM
  • Thank you

    I'm sorry .. I may not understand well what you want because I do not speak English
    I use google translate it may not help me well

    Friday, September 22, 2017 4:40 AM
  • What does this message mean?

    and

    The letters appear in the LISTBOX abnormally mean distances
    • Edited by jamilaid Friday, September 22, 2017 5:07 AM
    Friday, September 22, 2017 4:59 AM
  • What does this message mean?

    It means that a variable (probably _text) is Nothing.   It is probably because this line
                                SubT.Text += line
    didn't get executed.  And that in turn is probably because this line
                    If Seq <> "" Then

    was false (that is, Sseq was blank, and Text was never initialised).  But as you won't provide example of your data it is not possible to know whether or not that's what happened.

    Friday, September 22, 2017 7:30 AM
  • Thank you for your help
    Problem solved
    Friday, September 22, 2017 10:10 PM