Results 1 to 8 of 8

Thread: newbie question

  1. #1

    newbie question

    I am having trouble with array's and learning the tbasic language so my question is this. Using the console module, what would be the correct way to write an application that allows you to enter 10 numbers and display them in descending order?

  2. #2
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Leverkusen, Germany
    Age
    51
    Posts
    3,278
    Blog Entries
    2
    Rep Power
    339

    Re: newbie question

    Hi steiny.

    Welcome to the forum! Just to get it right. You want to enter 10 numbers, store them in an array. Then sort them descending? Adn then print them in the console window?

    Best wishes
    Michael
    Running Windows 7 Home, 64 bit, 8 GB ram, Athlon II X2 255, ATI Radeon HD 4200.

  3. #3

    Re: newbie question

    That is correct.

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,171
    Blog Entries
    2
    Rep Power
    10

    Re: newbie question

    Ciao steney and welcome to thinBasic community forum.

    I just write down a little example that can give you a start.
    [code=thinbasic]
    Uses "Console"

    Dim HowManyNumbers As Integer
    Dim MyNumber As Number
    Dim MyArray() As Number
    Dim Counter As Long

    Do
    Print "How many numbers (1 to 10): "
    HowManyNumbers = Console_ReadLine
    Loop While Outside(HowManyNumbers, 0, 10)

    If HowManyNumbers > 0 Then
    ReDim MyArray(HowManyNumbers)
    For Counter = 1 To HowManyNumbers
    Print "Enter number " & Counter & ": "
    MyArray(Counter) = Console_ReadLine
    Next

    PrintL "---Printing out sorted ---"
    Array Sort MyArray
    For Counter = 1 To HowManyNumbers
    PrintL Format$(Counter, "00") & ": ", MyArray(Counter)
    Next
    PrintL "--------------------------"

    PrintL "<Press a key to finish>"
    Console_WaitKey
    Else

    PrintL "---Ok, no numbers---------"
    PrintL "<Press a key to finish>"
    Console_WaitKey

    End If
    [/code]

    Ciao
    Eros
    Attached Files Attached Files
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  5. #5

    Re: newbie question

    Thanks for the help Eros.

  6. #6
    Senior Member catventure's Avatar
    Join Date
    Oct 2005
    Location
    UK
    Posts
    576
    Blog Entries
    1
    Rep Power
    69

    Re: newbie question

    Hi Steiny,

    Also (from helpfile) to sort an array in descending order:

    ARRAY SORT ArrayVariable([StartIndex]) [FOR nElements] [,{ASCEND | DESCEND}]

    catventure.
    http://tab.thinbasic.com - Home Of The ThinBasic Adventure Builder Project. (Interactive Fiction/Text Adventure Maker)
    TAB Forum - http://adventure.rpgdynasty.com/
    TAB Email Group - http://tech.groups.yahoo.com/group/TAB_IF_CREATOR/

  7. #7
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,171
    Blog Entries
    2
    Rep Power
    10

    Re: newbie question

    oops, sorry I forgot about descending order.

    Just change one line in script from
    [code=thinbasic]Array Sort MyArray[/code]
    to
    [code=thinbasic]Array Sort MyArray, DESCEND[/code]

    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  8. #8
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    45
    Posts
    914
    Rep Power
    101

    Re: newbie question

    ...may be this help too.

    I have tried this very short way, but with no descend way, I have never tried it before

    [code=thinbasic]' Empty GUI script created on 11-05-2009 20:47:57 by (ThinAIR)

    uses "console"
    dim n as long

    DIM arrays( 20 ) AS INTEGER

    arrays(1) = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20

    ARRAY SORT arrays(20) FOR 1, descend

    ' -- Print line of array items joined by space
    PRINTL JOIN$( Arrays, " " )

    WAITKEY[/code]

    welcome steiny and have fun with thinbasic

    bye, frank
    you can't always get what you want, but if you try sometimes you might find, you get what you need

Posting Permissions

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