Results 1 to 35 of 35

Thread: [RESOLVED] How to put 5 numbers in this order 1,2,3,4,5

  1. #1

    Thread Starter
    Fanatic Member memas's Avatar
    Join Date
    Jan 2010
    Location
    athens,greece
    Posts
    531

    Resolved [RESOLVED] How to put 5 numbers in this order 1,2,3,4,5

    i have 6 textboxes and i want the results of theses (1-2,1-3,1-4,1-5) to drive them
    1 in 5 labels but the smallest result to label1 the second result to label2.....and the bigest result to label5
    2 the numbers to abs absolute
    3 the equal numbers to appear once
    thank you
    memas

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: How to put 5 numbers in this order 1,2,3,4,5

    you have 6 numbers that you want to display in 5 labels???

    to sort your numbers, add them to an array:

    vb Code:
    1. dim intArray() as integer = {5,3,2,4,1}
    2. array.sort(intArray)

  3. #3

    Thread Starter
    Fanatic Member memas's Avatar
    Join Date
    Jan 2010
    Location
    athens,greece
    Posts
    531

    Re: How to put 5 numbers in this order 1,2,3,4,5

    i am new in programming and i cannot understand except if i send you the code that i have and you add the next step
    thank you
    memas

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: How to put 5 numbers in this order 1,2,3,4,5

    post your code in this thread. use the Code or VBCode tags above the message editor textbox to format your code

  5. #5

    Thread Starter
    Fanatic Member memas's Avatar
    Join Date
    Jan 2010
    Location
    athens,greece
    Posts
    531

    Re: How to put 5 numbers in this order 1,2,3,4,5

    Dim num1 As Integer = Val(num1TextBox.Text)
    Dim num16 As Integer = Val(num16TextBox.Text)
    Dim num17 As Integer = Val(num17TextBox.Text)
    Dim num18 As Integer = Val(num18TextBox.Text)

    Dim a As Integer = num1TextBox.Text - num16TextBox.Text
    Dim b As Integer = num1TextBox.Text - num17TextBox.Text
    Dim c As Integer = num1TextBox.Text - num18TextBox.Text

    i want to drive theses results according to their values to labels the smallest label1 ,the bigest to label5
    equal numbers to appear once
    and the numbers to be abs absolute

  6. #6
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: How to put 5 numbers in this order 1,2,3,4,5

    Code:
    Option Strict On 'SHOULD BE FIRST STATEMENT OF ALL PROGRAMS
    Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim tb1, tb2 As Integer 'Integer is one form of number.  
            '1.  Make sure we have numbers.  Check and convert the Textboxes(read about TryParse)
            If Not Integer.TryParse(TextBox1.Text, tb1) Then
                'what was in Textbox1 wasn't a number
                Exit Sub
            End If
            If Not Integer.TryParse(TextBox2.Text, tb2) Then
                'what was in Textbox2 wasn't a number
                Exit Sub
            End If
            '2.  Now that we have numbers we can subtract
            Dim tb12diff As Integer
            tb12diff = tb1 - tb2
            '3.  Now put that in a label
            Label1.Text = tb12diff.ToString
        End Sub
    End Class
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  7. #7

    Thread Starter
    Fanatic Member memas's Avatar
    Join Date
    Jan 2010
    Location
    athens,greece
    Posts
    531

    Re: How to put 5 numbers in this order 1,2,3,4,5

    i cannot understand the code what is the use of that
    what means tb1
    memas

  8. #8
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: How to put 5 numbers in this order 1,2,3,4,5

    You would do yourself a great service by getting a fundamental book.

    http://search.yahoo.com/search?p=vis...8&fr=yfp-t-701
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  9. #9

    Thread Starter
    Fanatic Member memas's Avatar
    Join Date
    Jan 2010
    Location
    athens,greece
    Posts
    531

    Angry Re: How to put 5 numbers in this order 1,2,3,4,5

    thank you

  10. #10
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: How to put 5 numbers in this order 1,2,3,4,5

    Sorry. But
    Dim something as Integer is fundamental, at least IMHO it is.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  11. #11

    Thread Starter
    Fanatic Member memas's Avatar
    Join Date
    Jan 2010
    Location
    athens,greece
    Posts
    531

    Re: How to put 5 numbers in this order 1,2,3,4,5

    ok
    thanks

  12. #12
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: How to put 5 numbers in this order 1,2,3,4,5

    you've only given me 4 numbers to work with. but:

    vb Code:
    1. Dim num1 As Integer = Val(num1TextBox.Text)
    2. Dim num16 As Integer = Val(num16TextBox.Text)
    3. Dim num17 As Integer = Val(num17TextBox.Text)
    4. Dim num18 As Integer = Val(num18TextBox.Text)
    5.  
    6. Dim a As Integer = math.abs(num1 - num16)
    7. Dim b As Integer = math.abs(num1 - num17)
    8. Dim c As Integer = math.abs(num1 - num18)
    9.  
    10. dim numbers() as integer = {a, b, c}
    11. array.sort(numbers)
    12.  
    13. label1.text = numbers(0)
    14. label2.text = numbers(1)
    15. label3.text = numbers(2)

    there are plenty of online resources + tuition available for beginners.
    try this:

    http://www.homeandlearn.co.uk/NET/vbNET.html

  13. #13
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Thumbs down Re: How to put 5 numbers in this order 1,2,3,4,5

    Quote Originally Posted by dbasnett View Post
    Sorry. But
    Dim something as Integer is fundamental, at least IMHO it is.
    booya!

    if he'd got past the integer declaration the integer.tryparse would've got him

  14. #14

    Thread Starter
    Fanatic Member memas's Avatar
    Join Date
    Jan 2010
    Location
    athens,greece
    Posts
    531

    Re: How to put 5 numbers in this order 1,2,3,4,5

    paul
    thank you very much
    it is working except that we need equal numbers to appear once
    and i have errors when the strict option is on
    and how you describe this code are this an array?
    i have a book from jame foxall that i read and i am in programming 15 days ago
    memas
    Last edited by memas; Jan 3rd, 2010 at 04:47 PM.

  15. #15
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: How to put 5 numbers in this order 1,2,3,4,5

    this is an array:

    dim numbers() as integer = {a, b, c}

    its got 3 elements - 0, 1, + 2 which represent a, b, + c

    heres another array, where its sorted differently + only distinct numbers (no more than 1 occurence of any number) are selected:

    vb Code:
    1. Dim numbers() As Integer = {2, 2, 4, 5, 5, 3, 1}
    2. Dim distinctNumbers = (From item In numbers _
    3.                         Order By item _
    4.                         Select item Distinct)
    5. numbers = distinctNumbers.ToArray

  16. #16

    Thread Starter
    Fanatic Member memas's Avatar
    Join Date
    Jan 2010
    Location
    athens,greece
    Posts
    531

    Re: How to put 5 numbers in this order 1,2,3,4,5

    paul
    so which is the correct for my program?
    memas

  17. #17
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: How to put 5 numbers in this order 1,2,3,4,5

    a combination of the 2 posts

    use the array from the first post, + the sorting + selecting from the last post.
    as dbasnett said, you really need to read + practice with programming yourself to learn it.

  18. #18
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: How to put 5 numbers in this order 1,2,3,4,5

    Figures... I found some of his books online, and if you have the Sam's Teach Yourself .Net in 24 Hours, Data Types aren't covered until Hour 12.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  19. #19

    Thread Starter
    Fanatic Member memas's Avatar
    Join Date
    Jan 2010
    Location
    athens,greece
    Posts
    531

    Re: How to put 5 numbers in this order 1,2,3,4,5

    i try to expan with more labels and more textboxes and i have error may i send you the code?
    thank you

  20. #20
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: How to put 5 numbers in this order 1,2,3,4,5

    ok. post your code again

  21. #21

    Thread Starter
    Fanatic Member memas's Avatar
    Join Date
    Jan 2010
    Location
    athens,greece
    Posts
    531

    Re: How to put 5 numbers in this order 1,2,3,4,5

    paul
    thank you
    Option Strict Off

    Public Class testform1





    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


    Dim num1 As Integer = Val(num1TextBox.Text)
    Dim num16 As Integer = Val(num16TextBox.Text)
    Dim num17 As Integer = Val(num17TextBox.Text)
    Dim num18 As Integer = Val(num18TextBox.Text)
    Dim num19 As Integer = Val(num19TextBox.Text)
    Dim num20 As Integer = Val(num20TextBox.Text)

    Dim a As Integer = Math.Abs(num1 - num16)
    Dim b As Integer = Math.Abs(num1 - num17)
    Dim c As Integer = Math.Abs(num1 - num18)
    Dim d As Integer = Math.Abs(num1 - num19)
    Dim f As Integer = Math.Abs(num1 - num20)






    Dim numbers() As Integer = {a, b, c, d, f}
    Array.Sort(numbers)

    label1.Text = numbers(0)
    Label2.Text = numbers(1)
    Label3.Text = numbers(2)
    label4.Text = numbers(3)
    Label5.Text = numbers(4)
    Label6.Text = numbers(5)
    Label7.Text = numbers(6)



    End Sub
    End Class

  22. #22
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: How to put 5 numbers in this order 1,2,3,4,5

    ok. you can turn option strict back on. turn option infer on too.

    your array has 5 elements - a, b, c, d, f

    that is 0 to 4.

    so numbers(0) is ok, numbers(4) is ok, but numbers(6) is outside of the bounds of the array

    vb Code:
    1. Public Class testform1
    2.  
    3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    4.  
    5.         Dim num1 As Integer = Val(num1TextBox.Text)
    6.         Dim num16 As Integer = Val(num16TextBox.Text)
    7.         Dim num17 As Integer = Val(num17TextBox.Text)
    8.         Dim num18 As Integer = Val(num18TextBox.Text)
    9.         Dim num19 As Integer = Val(num19TextBox.Text)
    10.         Dim num20 As Integer = Val(num20TextBox.Text)
    11.  
    12.         Dim a As Integer = Math.Abs(num1 - num16)
    13.         Dim b As Integer = Math.Abs(num1 - num17)
    14.         Dim c As Integer = Math.Abs(num1 - num18)
    15.         Dim d As Integer = Math.Abs(num1 - num19)
    16.         Dim f As Integer = Math.Abs(num1 - num20)
    17.  
    18.         Dim numbers() As Integer = {a, b, c, d, f}
    19.         Dim distinctNumbers = (From item In numbers _
    20.                         Order By item _
    21.                         Select item Distinct)
    22.         numbers = distinctNumbers.ToArray
    23.  
    24.         if numbers.getupperbound(0) >= 0 then
    25.             label1.Text = numbers(0).tostring
    26.         else
    27.             label1.Text = ""
    28.         end if
    29.         if numbers.getupperbound(0) >= 1 then
    30.             Label2.Text = numbers(1).tostring
    31.         else
    32.             label2.Text = ""
    33.         end if
    34.         if numbers.getupperbound(0) >= 2 then
    35.             label3.Text = numbers(2).tostring
    36.         else
    37.             label3.Text = ""
    38.         end if
    39.         if numbers.getupperbound(0) >= 3 then
    40.             Label4.Text = numbers(3).tostring
    41.         else
    42.             label4.Text = ""
    43.         end if
    44.         if numbers.getupperbound(0) >= 4 then
    45.             Label5.Text = numbers(4).tostring
    46.         else
    47.             label5.Text = ""
    48.         end if
    49.     End Sub
    50. End Class

  23. #23

    Thread Starter
    Fanatic Member memas's Avatar
    Join Date
    Jan 2010
    Location
    athens,greece
    Posts
    531

    Re: How to put 5 numbers in this order 1,2,3,4,5

    paul
    the programe works but when i turn on the option strict i have errors
    Option Strict On disallows implicit conversions from 'Double'
    thank you again you are a god

  24. #24
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: How to put 5 numbers in this order 1,2,3,4,5

    change:

    vb Code:
    1. Math.Abs(num1 - num16)

    to:

    vb Code:
    1. Math.Abs(cint(num1 - num16))

    etc

  25. #25

    Thread Starter
    Fanatic Member memas's Avatar
    Join Date
    Jan 2010
    Location
    athens,greece
    Posts
    531

    Smile Re: How to put 5 numbers in this order 1,2,3,4,5

    paul
    i changed it but still errors
    Option Strict On disallows implicit conversions from 'Double' to 'Integer'.
    maybe is there that i write val(num1TextBox.Text)?
    memas

    cint(val(num1TextBox.Text)) returns an integer
    and this works what is better?










    '
    Last edited by memas; Jan 3rd, 2010 at 06:02 PM.

  26. #26
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: How to put 5 numbers in this order 1,2,3,4,5

    i found it now.

    val(num1TextBox.Text) returns a double

    cint(val(num1TextBox.Text)) returns an integer

  27. #27

    Thread Starter
    Fanatic Member memas's Avatar
    Join Date
    Jan 2010
    Location
    athens,greece
    Posts
    531

    Re: How to put 5 numbers in this order 1,2,3,4,5

    paul
    i tried this and works no errors
    Dim num1 As Integer = Integer.Parse(num1TextBox.Text)
    Dim num16 As Integer = Integer.Parse(num16TextBox.Text)
    Dim num17 As Integer = Integer.Parse(num17TextBox.Text)
    Dim num18 As Integer = Integer.Parse(num18TextBox.Text)
    Dim num19 As Integer = Integer.Parse(num19TextBox.Text)
    Dim num20 As Integer = Integer.Parse(num20TextBox.Text)
    memas thank you again

  28. #28
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: How to put 5 numbers in this order 1,2,3,4,5

    that works ok if your textbox contains an integer. if not it causes a runtime error.
    try this:

    vb Code:
    1. Dim num1 As Integer
    2. Integer.tryParse(num1TextBox.Text, num1)
    3. Dim num16 As Integer
    4. Integer.tryParse(num16TextBox.Text, num16)
    5. Dim num17 As Integer
    6. Integer.tryParse(num17TextBox.Text, num17)
    7. Dim num18 As Integer
    8. Integer.tryParse(num18TextBox.Text, num18)
    9. Dim num19 As Integer
    10. Integer.tryParse(num19TextBox.Text, num19)
    11. Dim num20 As Integer
    12. Integer.tryParse(num20TextBox.Text, num20)

  29. #29

    Thread Starter
    Fanatic Member memas's Avatar
    Join Date
    Jan 2010
    Location
    athens,greece
    Posts
    531

    Re: How to put 5 numbers in this order 1,2,3,4,5

    is better to choose the parse method or the cint ?
    memas

  30. #30
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: How to put 5 numbers in this order 1,2,3,4,5

    If you just use CInt and some one put a letter (a,b A....) in the text box the application will error. The TryParse avoids this condition
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  31. #31

    Thread Starter
    Fanatic Member memas's Avatar
    Join Date
    Jan 2010
    Location
    athens,greece
    Posts
    531

    Re: How to put 5 numbers in this order 1,2,3,4,5

    thank you gary

  32. #32
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: How to put 5 numbers in this order 1,2,3,4,5

    as gary said, CInt can cause an error

    CInt("1") returns 1 in integer datatype
    CInt("a") causes a runtime error

    Val("1") returns 1 in double datatype
    Val("a") returns 0 in double datatype


    so

    CInt(Val("1")) returns 1 in integer datatype
    CInt(Val("a")) returns 0 in integer datatype

    but integer.tryparse is a better option

  33. #33

    Thread Starter
    Fanatic Member memas's Avatar
    Join Date
    Jan 2010
    Location
    athens,greece
    Posts
    531

    Re: How to put 5 numbers in this order 1,2,3,4,5

    Paul
    thank you for your help
    i am happy because i see this programe working
    thank you again you gave me courage to love more the programming science

  34. #34
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: How to put 5 numbers in this order 1,2,3,4,5

    Now would be the best time to read about data types in your book.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  35. #35

    Thread Starter
    Fanatic Member memas's Avatar
    Join Date
    Jan 2010
    Location
    athens,greece
    Posts
    531

    Re: How to put 5 numbers in this order 1,2,3,4,5

    ok i will

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width