Str$() function

313 views
Skip to first unread message

Hendra Wijaya

unread,
Nov 20, 2010, 9:56:14 PM11/20/10
to MapInfo-L

Hi All,

I'm new to this mapbasic programming. some simple syntax make me
headache.
Here for example,

'colIndex = 1
Str$( colIndex )

Error:
(coba2.mb:68) Unrecognized command: Str.

Any body know why I get that error message?

Thanks

Uffe Kousgaard

unread,
Nov 21, 2010, 6:20:41 AM11/21/10
to mapi...@googlegroups.com
Because str$ is not a command, but a function. You need to do something
like this:

dim a string
a = str$(1)

Regards
Uffe Kousgaard

hendra wijaya

unread,
Nov 21, 2010, 6:44:26 AM11/21/10
to mapi...@googlegroups.com
It works!

Thanks for your help.

Regards,
Hendra W,


2010/11/21 Uffe Kousgaard <uf...@routeware.dk>
--
You received this message because you are subscribed to the Google Groups "MapInfo-L" group.To post a message to this group, send email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en

hendra wijaya

unread,
Nov 21, 2010, 8:49:27 AM11/21/10
to mapi...@googlegroups.com
Another question,


colIndex = 3
coin = Str$( colIndex )  ' <-- this works


col = "FIELD" + coin
note temptable.(col)                         '  I'm expecting the code would act like this [ note temptable.FIELD3 ]


Please correct me.

Regards
Hendra W,


2010/11/21 hendra wijaya <hendr...@gmail.com>

Bill Thoen

unread,
Nov 21, 2010, 3:35:27 PM11/21/10
to mapi...@googlegroups.com
On 11/21/2010 6:49 AM, hendra wijaya wrote:
> Another question,
>
>
> colIndex = 3
> coin = Str$( colIndex ) ' <-- this works
>
>
> col = "FIELD" + coin
> note temptable.(col) ' I'm expecting the code
> would act like this [ note temptable.FIELD3 ]
>
>
> Please correct me.
>
To refer to a field in a table by index use the 'col' syntax, For
example, to select column 4 and 6 in a selection when you don't want to
use the formal field names, you use the 'col' syntax, like this:

SELECT col4, col6 FROM myTable

I don't know if it matters, but you should probably not use 'col' as a
variable. The number on the end of the 'col' alias is the index of the
field you want. The index starts at 1. Also these are literals, not
normal variables so you can't do anything like this:
SELECT "col" & 12 ... or SELECT "col12"... or even SELECT "col" +
Str$(12)... ; all these will fail miserably.

Instead, construct your query as a string and execute it with Run
Command. Here's a typical example.

Dim sCmd As String
Dim n As SmallInt

' Select the first 12 fields in thisTable and write them to mySelection
sCmd = "SELECT col1"
For n = 2 to 12
sCmd = sCmd + ", col" & n
Next
Run Command sCmd + " FROM thisTable INTO mySelection"

Hope that helps!

--
*Bill Thoen*
GISnet - www.gisnet.com
303-786-9961
----------------------------------
oo=== oooo= oooo === oo= o=o ooo oo =o o= =oo o=
=o== oo=== oooo= =ooo o o o=o ooo oo =o o= =o=o
o= ooo o
=o === = o= =o=o === oo =o =o=o oo =oo o =o =o=o o


hendra wijaya

unread,
Nov 22, 2010, 4:11:27 AM11/22/10
to mapi...@googlegroups.com
Thanks Bill,

I can use ur way to get the the values form each column as I wanted.

But I still struggling with my flow chart below.
 

FlowChart.JPG
Experts, please help

Hendra W,



FlowChart.JPG

hendra wijaya

unread,
Nov 23, 2010, 3:11:18 AM11/23/10
to mapi...@googlegroups.com

I found the way at last.

fetch first from testx
delete from testx
commit table testx
Select * From sitemap where sitemap.CI = kupret into tempux 'create temporary "tempux" table
delete from tempux
commit table tempux
   
for colIndex = 2 to 32
  kupret = tempe.col(colIndex)
    fetch first from tempux
    Select * From sitemap where sitemap.CI = kupret into tempux
    commit table tempux
    insert into testx select * from tempux
   
next
commit table testx

The final result as I wanted, but there is still something bugging me.

The "testx" table, start to insert the new raw from the end of raw (or EoT). Suppose I have raw-1 until raw-n are empty, and I want the function to insert the record to the first raw, instead of raw-n

I hope some expert can share the solution.

Regards
Hendra W,



2010/11/22 hendra wijaya <hendr...@gmail.com>
FlowChart.JPG
Reply all
Reply to author
Forward
0 new messages