Results 1 to 3 of 3

Thread: Strings and data type

  1. #1

    Question Strings and data type

    Hello, There

    Im currently learning ThinBasic and i wanted to know how to do somthing. If anyone can help it would be greatly appricated. Please find attached my current code with comments, error is on line 12 with comments to indicate what i wan't it to do, i need help with the syntax of that part of my code. If anyone can please help me to get it working.

    Dim Counter           As Long
    Dim CompareValue      As String 
    Dim Sip As String
    Dim SipID As String * 3  ' Set Length to 3 This is the start value '
    
    Sip = InputBox$ "Name", "Input", "BoB" ' This takes input and then counts value of howmany characters the input is' 
    For Counter = 1 To Len(Sip)   
    CompareValue = Counter
      Next
       
    SipID = InputBox$ "Name", "Input", "ID" ' Here i want to take the second input and limit it to the number entered before by SIP eg. bob = 3 '
    SipID = As String * (CompareValue) ' Here i can't set the value to the length of SIP count"       
      MsgBox 0, CompareValue 
      MsgBox 0, SipID
    
    Please note, the input box for SIPID will be removed and the variable SIPID will only be used to set the string size from input SIP

    Thank you!

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,814
    Rep Power
    10
    Hi Henry.

    Fixed strings cannot change they initial size.
    Once you have defined your string being 3 bytes in length, it will remain such for the duration of the variable scope.
    So
    SipID = As String * (CompareValue)
    
    is not a valid thinBasic syntax.

    Using fixed string length is usually driven by specific needs, maybe related to record structure or UDT structure or databases or whatever situation where you MUST be sure your string never will be greater or less that that size.

    For all other situations just use dynamic strings and all the memory handling will be done by thinBasic engine.
    You can always check your string using the many native thinBasic string functions

    Let me know.
    Ciao
    Eros
    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

  3. #3

    Cool Thanks

    Thank you i understand Im working on it now, think i might have found another method. That was very helpful thank you very much.

    Ill keep you posted once i have a working code!

    Cheers.

Similar Threads

  1. FreeBasic SDK: extended data type
    By ErosOlmi in forum Module SDK (Freebasic version)
    Replies: 29
    Last Post: 15-09-2008, 20:47
  2. Most efficient integer data type for small numbers?
    By Randall in forum thinBasic General
    Replies: 4
    Last Post: 12-09-2007, 03:57

Members who have read this thread: 0

There are no members to list at the moment.

Tags for this Thread

Posting Permissions

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