RE: MI-L mapbasic Update table with custom function

2004-04-27 Thread Cummings, Mike
OK, what's the trick?  Corner=strpcorner(stable2.location) doesn't work.  I don't want 
to write code to loop through the table, if I don't have to.  Looping through the 
table is going to be slow.   

The update statement (for some reason) doesn't recognize table field names in custom 
functions.  I have written a MBX with a simple function and I can pass values to fill 
the field.  

When I tried to use an alias(ie - Function xx(str as alias)as string), its fatal for 
Mapinfo 6.5 (win2000 reports an illegal operation  closes Mapinfo).

Someone must have discovered this before.  I have a hard time believing there isn't a 
way to update a field with a custom function without looping through the table or some 
other work around. (I can do it in access.) When I sketched out my flow diagram, it 
never occurred to me that this couldn't be done.  Its back to the drawing board.  The 
Manual says that you can use custom functions in Select statements.  Has anyone had 
any luck?




-Original Message-
From: B. Thoen [mailto:[EMAIL PROTECTED]
Sent: Monday, April 26, 2004 5:07 PM
To: Jacques Paris
Cc: Cummings, Mike; Mapinfo-L
Subject: RE: MI-L mapbasic Update table with custom function 


No, that's not the case. In MapBasic, you can use custom functions in 
'update' statements. In fact, this is a little known trick for rapidly 
updating tables rather than using the slower 'Do While...Loop' technique.

You might need to add the table name to the variable (e.g.  
Corner=strpcorner(stable2.location)), but that's just a stab in the dark.  
Check your spelling too -- 'location' may actually be 'loaction' in the
table, or something like that.

- Bill Thoen

On Mon, 26 Apr 2004, Jacques Paris wrote:

 My interpretation is that the expression used to update a column must be
 written with the MapBasic vocabulary. I deduce that from the fact that
 update as many other functions can be run from the MapBasic window that
 does not support any external calls, i.e. calls to custom functions that
 are not part of the MB set and must be supplied by the user, and the MB
 window does not allow that.
 
 Jacques Paris
 e-mail  [EMAIL PROTECTED]
 MapBasic-MapInfo support  http://www.paris-pc-gis.com
 
 
 -Original Message-
 From: Cummings, Mike [mailto:[EMAIL PROTECTED]
 Sent: 26-Apr-04 18:14
 To: Mapinfo-L
 Subject: MI-L mapbasic Update table with custom function
 
 I tried to compile this code:
 
 Update stable2 Set MTRS = Left$(bm,1)+Twn+Rge+right$(0+sec,2),
 Corner=strpcorner(location)
 
 (Where MTRS, BM, TWN, RGE, SEC, corner  Location are fields in stable2
 and strpcorner is a custom function)
 
 and I get this error message: Subroute Argument location not defined.
 
 Why doesn't this work?  Shouldn't Mapbasic recognize that location is a
 field name?


-
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 11533


-
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 11544



RE: MI-L mapbasic Update table with custom function

2004-04-27 Thread Lawley, Russell S

Mike,

I have used functions in the past for doing this kind of update, but i always called 
the column by its column number  see the code below

tis v fast and handy, but you have to watch some updates because they all occurr 
concurrently, so in the example below, i also update column3, but it gets updated with 
the OLD values from column 2, not the new ones being calculated by the function in teh 
first part of the update.





include mapbasic.def
declare sub main()
declare function mysquare(byval mycolumnum as integer) as float



sub main
Open Table D:\tableone.TAB as mytest 
' now i update column two by calling the function against column 1
Update mytest Set Field2 =  mysquare(1), Field3 = str$(Field2/3)
browse * from mytest
end sub


' my function to return the square of the first column 
Function mysquare(byval mycolumnum as integer) as float
mysquare = mytest.col(mycolumnum) * mytest.col(mycolumnum) 
end function 


hth

r


*
This  e-mail  message,  and  any  files  transmitted  with  it, are
confidential  and intended  solely for the  use of the  addressee. If
this message was not addressed to  you, you have received it in error
and any  copying,  distribution  or  other use  of any part  of it is
strictly prohibited. Any views or opinions presented are solely those
of the sender and do not necessarily represent  those of the British
Geological  Survey. The  security of e-mail  communication  cannot be
guaranteed and the BGS accepts no liability  for claims arising as a
result of the use of this medium to  transmit messages from or to the
BGS. .http://www.bgs.ac.uk
*


-
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 11545



RE: MI-L mapbasic Update table with custom function

2004-04-27 Thread Peter Horsbøll Møller
It does work. So there must be some word that you have used that is confusing the 
compiler
 
Update stable2
   Set MTRS = Left$(BM,1)+TWN+RGE+Right$(0+SEC, 2),
 CORNER=strpcorner(LOCATION)

A few thing to look into:
- is stable2 a variable or the real name of the table ?
- You haven't made a selection from your table and forgot to select all the columns ?
- does strpcorner take the parameter ByVal ?
 
HTH
Peter Horsbøll Møller
GIS Udvikler
Geographical Information  IT
COWI A/S
Odensevej 95
5260 Odense S.
Telefon 6311 4900
Direkte  6311 4908
Mobil5156 1045
Telefax 6311 4949
E-mail [EMAIL PROTECTED]
http://www.cowi.dk http://www.cowi.dk/ 



From: Cummings, Mike [mailto:[EMAIL PROTECTED]
Sent: Tue 27-Apr-04 18:17
To: B. Thoen; Jacques Paris
Cc: Mapinfo-L
Subject: RE: MI-L mapbasic Update table with custom function 



OK, what's the trick?  Corner=strpcorner(stable2.location) doesn't work.  I don't want 
to write code to loop through the table, if I don't have to.  Looping through the 
table is going to be slow.  

The update statement (for some reason) doesn't recognize table field names in custom 
functions.  I have written a MBX with a simple function and I can pass values to fill 
the field. 

When I tried to use an alias(ie - Function xx(str as alias)as string), its fatal for 
Mapinfo 6.5 (win2000 reports an illegal operation  closes Mapinfo).

Someone must have discovered this before.  I have a hard time believing there isn't a 
way to update a field with a custom function without looping through the table or some 
other work around. (I can do it in access.) When I sketched out my flow diagram, it 
never occurred to me that this couldn't be done.  Its back to the drawing board.  The 
Manual says that you can use custom functions in Select statements.  Has anyone had 
any luck?




-Original Message-
From: B. Thoen [mailto:[EMAIL PROTECTED]
Sent: Monday, April 26, 2004 5:07 PM
To: Jacques Paris
Cc: Cummings, Mike; Mapinfo-L
Subject: RE: MI-L mapbasic Update table with custom function


No, that's not the case. In MapBasic, you can use custom functions in
'update' statements. In fact, this is a little known trick for rapidly
updating tables rather than using the slower 'Do While...Loop' technique.

You might need to add the table name to the variable (e.g. 
Corner=strpcorner(stable2.location)), but that's just a stab in the dark. 
Check your spelling too -- 'location' may actually be 'loaction' in the
table, or something like that.

- Bill Thoen

On Mon, 26 Apr 2004, Jacques Paris wrote:

 My interpretation is that the expression used to update a column must be
 written with the MapBasic vocabulary. I deduce that from the fact that
 update as many other functions can be run from the MapBasic window that
 does not support any external calls, i.e. calls to custom functions that
 are not part of the MB set and must be supplied by the user, and the MB
 window does not allow that.

 Jacques Paris
 e-mail  [EMAIL PROTECTED]
 MapBasic-MapInfo support  http://www.paris-pc-gis.com


 -Original Message-
 From: Cummings, Mike [mailto:[EMAIL PROTECTED]
 Sent: 26-Apr-04 18:14
 To: Mapinfo-L
 Subject: MI-L mapbasic Update table with custom function

 I tried to compile this code:

 Update stable2 Set MTRS = Left$(bm,1)+Twn+Rge+right$(0+sec,2),
 Corner=strpcorner(location)

 (Where MTRS, BM, TWN, RGE, SEC, corner  Location are fields in stable2
 and strpcorner is a custom function)

 and I get this error message: Subroute Argument location not defined.

 Why doesn't this work?  Shouldn't Mapbasic recognize that location is a
 field name?


-
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 11533


-
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 11544






Re: MI-L mapbasic Update table with custom function

2004-04-27 Thread Bill Thoen
Here's a complete example of creating a small table and updating
a column with a custom function:
'---
Declare Function FirstWord (ByVal sText As String) As String
Close All Interactive
Create Table TEST (
Corner Char (25),
Location Char (25))
File ApplicationDirectory$()  test.tab
Insert Into TEST (Location) Values (One Fish)
Insert Into TEST (Location) Values (Two Fish)
Insert Into TEST (Location) Values (Red Fish)
Insert Into TEST (Location) Values (Blue Fish)
Update TEST Set Corner=FirstWord(Location)
Commit Table TEST
Browse * From TEST

Function FirstWord (ByVal sText As String) As String
Dim sWord As String
sWord = Left$(sText, InStr(1, sText,  )-1)
FirstWord = sWord
End Function
'---



Cummings, Mike wrote:
 
 OK, what's the trick?  Corner=strpcorner(stable2.location) doesn't work.  I don't 
 want to write code to loop through the table, if I don't have to.  Looping through 
 the table is going to be slow.
 
 The update statement (for some reason) doesn't recognize table field names in custom 
 functions.  I have written a MBX with a simple function and I can pass values to 
 fill the field.
 
 When I tried to use an alias(ie - Function xx(str as alias)as string), its fatal for 
 Mapinfo 6.5 (win2000 reports an illegal operation  closes Mapinfo).
 
 Someone must have discovered this before.  I have a hard time believing there isn't 
 a way to update a field with a custom function without looping through the table or 
 some other work around. (I can do it in access.) When I sketched out my flow 
 diagram, it never occurred to me that this couldn't be done.  Its back to the 
 drawing board.  The Manual says that you can use custom functions in Select 
 statements.  Has anyone had any luck?
 
 -Original Message-
 From: B. Thoen [mailto:[EMAIL PROTECTED]
 Sent: Monday, April 26, 2004 5:07 PM
 To: Jacques Paris
 Cc: Cummings, Mike; Mapinfo-L
 Subject: RE: MI-L mapbasic Update table with custom function
 
 No, that's not the case. In MapBasic, you can use custom functions in
 'update' statements. In fact, this is a little known trick for rapidly
 updating tables rather than using the slower 'Do While...Loop' technique.
 
 You might need to add the table name to the variable (e.g.
 Corner=strpcorner(stable2.location)), but that's just a stab in the dark.
 Check your spelling too -- 'location' may actually be 'loaction' in the
 table, or something like that.
 
 - Bill Thoen
 
 On Mon, 26 Apr 2004, Jacques Paris wrote:
 
  My interpretation is that the expression used to update a column must be
  written with the MapBasic vocabulary. I deduce that from the fact that
  update as many other functions can be run from the MapBasic window that
  does not support any external calls, i.e. calls to custom functions that
  are not part of the MB set and must be supplied by the user, and the MB
  window does not allow that.
 
  Jacques Paris
  e-mail  [EMAIL PROTECTED]
  MapBasic-MapInfo support  http://www.paris-pc-gis.com
 
 
  -Original Message-
  From: Cummings, Mike [mailto:[EMAIL PROTECTED]
  Sent: 26-Apr-04 18:14
  To: Mapinfo-L
  Subject: MI-L mapbasic Update table with custom function
 
  I tried to compile this code:
 
  Update stable2 Set MTRS = Left$(bm,1)+Twn+Rge+right$(0+sec,2),
  Corner=strpcorner(location)
 
  (Where MTRS, BM, TWN, RGE, SEC, corner  Location are fields in stable2
  and strpcorner is a custom function)
 
  and I get this error message: Subroute Argument location not defined.
 
  Why doesn't this work?  Shouldn't Mapbasic recognize that location is a
  field name?
 
 -
 List hosting provided by Directions Magazine | www.directionsmag.com |
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 Message number: 11533

-- 
- Bill Thoen
 
GISnet, 1401 Walnut St., Suite C, Boulder, CO  80302
tel: 303-786-9961, fax: 303-443-4856
http://www.gisnet.com/


-
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 11547



RE: MI-L mapbasic Update table with custom function

2004-04-27 Thread Warren Vick, Europa Technologies Ltd.
Hello Mike,

I see that several people have made suggestions about this one. Here are my
thoughts:

1) You can indeed use a custom function in an UPDATE statement, but not
sub(s). This method can only be used in a MB program and not on the MB
window command line. 

2) Remember that you pass back a return value in MapBasic by assigning the
function name itself to something as if it were a variable. It's very easy
to forget this and have functions returning incorrect values.

3) The function can accept parameters from field names or MapBasic variable
that are in scope.

4) I don't think it matters if the variables are passed byval or not. I am
sure values passed not byval (=by reference), and modified by the function,
are not stored back to the table. This is different from passing a variable
by reference.

5) Your data types should be preferably identical but at least compatible
(data type promotions like smallint-integer-float) are OK.

6) Remember that your column names should not conflict with variable names.
If so, variable names will take precedence. E.g. If you have a variable
called location with a type incompatible with strpcorner(), that could be
your problem.

7) You can break statements along multiple lines so the
Corner=strpcorner(location) which appears to be on a separate line in your
message will be fine. The comma at the end of the preceding line makes it
valid. Unlike some other languages you do not need to use  statement
continuation marks over multiple lines.

Regards,
Warren Vick
Europa Technologies Ltd.
http://www.europa-tech.com

-Original Message-
From: Cummings, Mike [mailto:[EMAIL PROTECTED] 
Sent: 26 April 2004 23:14
To: Mapinfo-L
Subject: MI-L mapbasic Update table with custom function 


I tried to compile this code:

Update stable2 Set MTRS = Left$(bm,1)+Twn+Rge+right$(0+sec,2),
Corner=strpcorner(location)

(Where MTRS, BM, TWN, RGE, SEC, corner  Location are fields in stable2 and
strpcorner is a custom function)

and I get this error message: Subroute Argument location not defined.

Why doesn't this work?  Shouldn't Mapbasic recognize that location is a
field name?  

-
List hosting provided by Directions Magazine | www.directionsmag.com | To
unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 11530




-
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 11550



RE: MI-L mapbasic Update table with custom function

2004-04-27 Thread Cummings, Mike
Thanks for the sample code and all the help.  ByVal is the key.  

I know tried using ByVal before my first e-mail; but the function returned a null 
value.  After running your code, I see that I have a problem with the function also. 
(I had originally written this code in visual basic and converted it to Mapbasic.)  
The functions (between the two) are just a little different.  It seems I screwed up 
the conversion.

Again thanks to all! 

-Original Message-
From: Bill Thoen [mailto:[EMAIL PROTECTED]
Sent: Tuesday, April 27, 2004 10:10 AM
To: Cummings, Mike
Subject: Re: MI-L mapbasic Update table with custom function


BTW, you must pass the argument by value, not reference. In your
example below, you've declared Function xx (str as ...). It must
be Function xx (ByVal str ...

Cummings, Mike wrote:
 
 OK, what's the trick?  Corner=strpcorner(stable2.location) doesn't work.  I don't 
 want to write code to loop through the table, if I don't have to.  Looping through 
 the table is going to be slow.
 
 The update statement (for some reason) doesn't recognize table field names in custom 
 functions.  I have written a MBX with a simple function and I can pass values to 
 fill the field.
 
 When I tried to use an alias(ie - Function xx(str as alias)as string), its fatal for 
 Mapinfo 6.5 (win2000 reports an illegal operation  closes Mapinfo).
 
 Someone must have discovered this before.  I have a hard time believing there isn't 
 a way to update a field with a custom function without looping through the table or 
 some other work around. (I can do it in access.) When I sketched out my flow 
 diagram, it never occurred to me that this couldn't be done.  Its back to the 
 drawing board.  The Manual says that you can use custom functions in Select 
 statements.  Has anyone had any luck?
 
 -Original Message-
 From: B. Thoen [mailto:[EMAIL PROTECTED]
 Sent: Monday, April 26, 2004 5:07 PM
 To: Jacques Paris
 Cc: Cummings, Mike; Mapinfo-L
 Subject: RE: MI-L mapbasic Update table with custom function
 
 No, that's not the case. In MapBasic, you can use custom functions in
 'update' statements. In fact, this is a little known trick for rapidly
 updating tables rather than using the slower 'Do While...Loop' technique.
 
 You might need to add the table name to the variable (e.g.
 Corner=strpcorner(stable2.location)), but that's just a stab in the dark.
 Check your spelling too -- 'location' may actually be 'loaction' in the
 table, or something like that.
 
 - Bill Thoen
 
 On Mon, 26 Apr 2004, Jacques Paris wrote:
 
  My interpretation is that the expression used to update a column must be
  written with the MapBasic vocabulary. I deduce that from the fact that
  update as many other functions can be run from the MapBasic window that
  does not support any external calls, i.e. calls to custom functions that
  are not part of the MB set and must be supplied by the user, and the MB
  window does not allow that.
 
  Jacques Paris
  e-mail  [EMAIL PROTECTED]
  MapBasic-MapInfo support  http://www.paris-pc-gis.com
 
 
  -Original Message-
  From: Cummings, Mike [mailto:[EMAIL PROTECTED]
  Sent: 26-Apr-04 18:14
  To: Mapinfo-L
  Subject: MI-L mapbasic Update table with custom function
 
  I tried to compile this code:
 
  Update stable2 Set MTRS = Left$(bm,1)+Twn+Rge+right$(0+sec,2),
  Corner=strpcorner(location)
 
  (Where MTRS, BM, TWN, RGE, SEC, corner  Location are fields in stable2
  and strpcorner is a custom function)
 
  and I get this error message: Subroute Argument location not defined.
 
  Why doesn't this work?  Shouldn't Mapbasic recognize that location is a
  field name?
 
 -
 List hosting provided by Directions Magazine | www.directionsmag.com |
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 Message number: 11533
 
 -
 List hosting provided by Directions Magazine | www.directionsmag.com |
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 Message number: 11544

-- 
- Bill Thoen
 
GISnet, 1401 Walnut St., Suite C, Boulder, CO  80302
tel: 303-786-9961, fax: 303-443-4856
http://www.gisnet.com/


-
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 11551



MI-L mapbasic Update table with custom function

2004-04-26 Thread Cummings, Mike
I tried to compile this code:

Update stable2 Set MTRS = Left$(bm,1)+Twn+Rge+right$(0+sec,2),
Corner=strpcorner(location)

(Where MTRS, BM, TWN, RGE, SEC, corner  Location are fields in stable2
and strpcorner is a custom function)

and I get this error message: Subroute Argument location not defined.

Why doesn't this work?  Shouldn't Mapbasic recognize that location is a
field name?  

-
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 11530



RE: MI-L mapbasic Update table with custom function

2004-04-26 Thread Jacques Paris
My interpretation is that the expression used to update a column must be
written with the MapBasic vocabulary. I deduce that from the fact that
update as many other functions can be run from the MapBasic window that
does not support any external calls, i.e. calls to custom functions that
are not part of the MB set and must be supplied by the user, and the MB
window does not allow that.

Jacques Paris
e-mail  [EMAIL PROTECTED]
MapBasic-MapInfo support  http://www.paris-pc-gis.com


-Original Message-
From: Cummings, Mike [mailto:[EMAIL PROTECTED]
Sent: 26-Apr-04 18:14
To: Mapinfo-L
Subject: MI-L mapbasic Update table with custom function

I tried to compile this code:

Update stable2 Set MTRS = Left$(bm,1)+Twn+Rge+right$(0+sec,2),
Corner=strpcorner(location)

(Where MTRS, BM, TWN, RGE, SEC, corner  Location are fields in stable2
and strpcorner is a custom function)

and I get this error message: Subroute Argument location not defined.

Why doesn't this work?  Shouldn't Mapbasic recognize that location is a
field name?

-
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 11530




-
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 11532