PDA

View Full Version : Strings and data type



Henry
28-06-2011, 08:59
Hello, There :o

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!

ErosOlmi
28-06-2011, 11:11
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 (http://www.thinbasic.com/public/products/thinBasic/help/html/stringhandling.htm)

Let me know.
Ciao
Eros

Henry
28-06-2011, 12:56
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.