Results 1 to 2 of 2

Thread: Numbrr to increasing string

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

    Number to increasing string

    Hello ...

    I have Made a little example with increasing number and autoconverts to a String but found perhaps a Bug?

    '---Script created on 02-24-2024 17:49:57 by lionheart 
    '
    '
    uses "ui" 
    long flag = 10
    flag++
    msgbox str$(flag) '11
    'thinbasic result 10 ?
    '
    ' number to an increasing string
    '
    '1)
    string s = "200"
    s = val(s)+1 '201
    msgbox  s 'result: "201"
    'thinbasic result: 2001
    
    '2)
    long k
    k++
    s = val(s)+k
    msgbox s 'result: "202"
    'thinbasic result : 2001
    
    '3)
    string m = " Mona"
    string st = "3000 " + m
    st = val(st)+1
    msgbox st + m 'result: 3001 Mona
    'thinbasic result: 30001
    
    '4)
    long km = 100
    km++
    string m =" Mona"
    string sr ="3000 " + m
    sr = val(sr) + val(km)+1
    msgbox sr + m 'result: 3102 Mona
    'thinbasic result: 30001001
    
    Last edited by Lionheart008; 24-02-2024 at 20:26.
    you can't always get what you want, but if you try sometimes you might find, you get what you need

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,818
    Rep Power
    10
    First of all, thanks for testing, it is always usefull.

    To me all exposes cases are as expected.

    ++ is not supported by thinBasic, at the moment it is just ignored.
    All the other cases ... if thinBasic expects a string, math is for string so + is considered "concatenation" even if before there is a VAL

    If you need to sum a number into to a string that represent a number, use a numeric variable as destination like:
    long n
    string s = "200"
    n = val(s)+1
    msgbox  0, n
    
    Which math to follow (numeric + or + as string concatenation) depends by the destination type
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Similar Threads

  1. Returning string from DLL in V1.10.7.0
    By GrahamC in forum Console
    Replies: 7
    Last Post: 20-01-2023, 19:12
  2. Never use Len when you use unicode string.
    By kcvinu in forum thinBasic General
    Replies: 3
    Last Post: 02-05-2021, 13:36
  3. String-in-String-Pointers?
    By ReneMiner in forum thinBasic General
    Replies: 9
    Last Post: 11-06-2013, 14:55

Members who have read this thread: 1

Posting Permissions

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