Results 1 to 3 of 3

Thread: array question multiple assignment

  1. #1
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    934
    Rep Power
    109

    array question multiple assignment

    it's possible to convert this array example from oxygen module to thinbasic?

      
    Uses "console"      'multiple assignment      
    Dim a(10) As Long
     'Dim a(10) As Long => (2,4,6,8,10,12,42,99) ' that's possible to convert to thinbasic?     
    Dim s As String   
    s = a(2) + a(5) 'result: 14   
    Print "answer is: " + s + a(6) 'result: 14 12   
    WaitKey
    
    thanks for help in advance, good week-end, frank
    Attached Files Attached Files
    Last edited by Lionheart008; 17-03-2012 at 10:20.
    you can't always get what you want, but if you try sometimes you might find, you get what you need

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi,

    it is basically the same, instead of <= you would use just = and ommit the parenthesis.

    Way #1
    Dim a(10) As Long = 2, 4, 6, 8, 10, 12, 42, 99
    
    Way #2
    Long a(10) = 2, 4, 6, 8, 10, 12, 42, 99
    
    Way #3 - after array is declared
    a(1) = 2, 4, 6, 8, 10, 12, 42, 99
    
    There is problem in your code at line:
    Dim s As String  
    s = a(2) + a(5) ' result: 14
    
    ... this will not result in 14, because you assign to string. That means the array values will be converted to string first, behaving as "4" + "10", resulting in "410".

    To do what you need, you should use:
    Dim s As String  
    s = Format$(a(2) + a(5)) 'result: 14
    

    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    934
    Rep Power
    109
    thank you petr for answer and explanationes that's working fine. my mistake don't using format$ for adding strings, I've forgot that.. I have tried making some exercises with combobox/listbox for my fundialox module and wanted to work with alternative way don't using "array assign" but that's nearly impossible after first experiments. but I will see. have a nice day and good luck for your studying time with your pretties robots.

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

Similar Threads

  1. Array question
    By TheOne in forum Tips and Tricks
    Replies: 5
    Last Post: 10-05-2013, 12:29
  2. Array element assignment
    By ErosOlmi in forum thinBasic vaporware
    Replies: 4
    Last Post: 19-06-2007, 10:21

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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