Create Point Using VB6

441 views
Skip to first unread message

stevene

unread,
Dec 23, 2007, 5:49:45 PM12/23/07
to MapInfo-L
Merry Xmas Gang;

Trying to use VB6 to create a point and insert the latitude and
longitude points into a table. I currently use the following in
mapbasic to create a point and it works just fine.

Dim x1, y1 as float
x1 = CommandInfo(CMD_INFO_X)
y1 = CommandInfo(CMD_INFO_Y)
Set Style Symbol MakeSymbol (35, BLUE, 18)
Insert into gps_temp (Latitude, Longitude, obj)
values (x1, y1, CreatePoint(x1,y1)

In VB6 however, I can get the point to draw successfully on the map,
but it falls over when trying to to insert the lat/long. The message
says:
"Run-time error '-2147352567(80020009)': Variable or Field
x1 not defined"

This is what I have written in my vb6

Dim x1, y1 As String
x1 = CMD_INFO_X
y1 = CMD_INFO_Y
mapinfo.do "Set Style Symbol MakeSymbol (35, 255, 18)"
mapinfo.RunMenuCommand 1711
mapinfo.do "Insert into gps_temp (Latitude, Longitude, obj) values
(x1, y1, CreatePoint(x1,y1))"

Any ideas where I'm going wrong?

Cheers!

Uffe Kousgaard

unread,
Dec 23, 2007, 6:19:12 PM12/23/07
to mapi...@googlegroups.com
Steven,

You have asked almost the same question before:
http://groups.google.com/group/mapinfo-l/browse_frm/thread/216390bfeab56881

I also think you need this kind of code instead just doing x1=CMD_INFO_X

x1 = mapinfo.eval "CommandInfo(CMD_INFO_X)"

As an alternative you can also run everything through "mapinfo.do "
commands.

Regards
Uffe Kousgaard

Steven Evans

unread,
Dec 23, 2007, 10:12:22 PM12/23/07
to mapi...@googlegroups.com
Yes, I did have that one a while ago, but I still had the same errors with it. You mentioned in that thread that Vb knew what the variable was but that mapinfo didn't. I'm not sure how I should have declared it or mapinfo?
I left it out of my coding in the end (it was surplus to requirements anyway).
However, I seem to be having the same problem with this one.
I have now changed the code to...

Dim x1, y1, msg As String
x1 = "mapinfo.Eval CommandInfo(CMD_INFO_X)"
y1 = "mapinfo.Eval CommandInfo(CMD_INFO_Y)"
msg = "Insert into gps_temp (Latitude, Longitude, obj) values (x1, y1, CreatePoint(x1,y1))"


mapinfo.do "Set Style Symbol MakeSymbol (35, 255, 18)"
mapinfo.RunMenuCommand 1711

mapinfo.do (msg)

And I still get the same error. Sorry - bit confused by this one!


Steven,

x1 = mapinfo.eval "CommandInfo(CMD_INFO_X)"

Regards
Uffe Kousgaard

Visit Parkes on the web at http://www.parkes.nsw.gov.au.
-----------------------------------------------------------------------
ATTENTION: This e-mail is privileged and confidential. If you are not
the intended recipient please delete the message and notify the sender.
Any views or opinions presented are solely those of the author.
-----------------------------------------------------------------------

David Perry

unread,
Dec 23, 2007, 10:28:39 PM12/23/07
to mapi...@googlegroups.com
I am not sure about VB proper but using VB script you can not use mapbasic defintion (ie CMD_INFO_X)
you must substitute the code (ie 1). Also you are not sending Mapinfo the values of X1,Y1 but the actual string X1,Y1.
 
(Note I am not sure of the exact variable types you will have to check them)
 
Try
 
Dim x1, y1 as Float 
Dim msg As String
x1 = Cdbl("mapinfo.Eval("CommandInfo(1)"))   'convert to a number
y1 = Cdbl("mapinfo.Eval("CommandInfo(2)"))   'convert to a number
Mi.do "Insert into gps_temp (Latitude, Longitude, obj) values ("& x1 &"," & y1& ", CreatePoint(" & x1 & "," & y1& "))"
Alternatively you can decalre X1 and Y1 and give them values inside MapInfo
 
MI.do "Dim X1, Y1 as float"
MI.do "X1 = CommandInfo(CMD_INFO_X)"
MI.do "Y1 = CommandInfo(CMD_INFO_Y)"
MI.do "Insert into gps_temp (Latitude, Longitude, obj) values (x1, y1, CreatePoint(x1,y1))"

>>> steven...@parkes.nsw.gov.au 24/12/2007 1:12 pm >>>
***********************************************************************************
This e-mail (including all attachments) contains information
which is confidential and may be subject to legal or other
professional privilege. It may contain personal information which
is intended for the exclusive use of the addressee(s). No part of
this e-mail should be reproduced, adapted or communicated without
the sender's prior written consent. If you have received this e-
mail in error, please advise us by e-mail, delete it from your
system and destroy all copies. Any confidentiality or privilege
associated with this e-mail is not waived or lost because it has
been sent to you by mistake.
This e-mail is also subject to copyright. No part of this e-mail
should be reproduced or distributed without the written consent
of the copyright owner. Any personal information in this e-mail
must be handled in accordance with the Privacy Act 1988
(Commonwealth).
Opinions expressed in this e-mail do not necessarily reflect
those of Council ("CSC"). Information transmitted by e-mail
cannot be guaranteed as either secure or error-free. E-mails may
contain computer viruses or other defects and can be intercepted,
interfered with, corrupted, lost, destroyed or arrive late or
incomplete. CSC accepts no liability and provides no guarantee or
warranty in relation to these matters or any information, action
or advice contained in this e-mail. If you have any doubt about
the authenticity of an e-mail purportedly sent by CSC, please
contact us immediately.
Warning: Although CSC has taken reasonable precautions, it is
recommended that this e-mail and all attachments be scanned for
viruses before opening. As the recipient you must accept
liability for viruses accompanying this e-mail and all its
attachments.
**********************************************************************************

Trey Pattillo

unread,
Dec 23, 2007, 11:32:38 PM12/23/07
to mapi...@googlegroups.com
When passing DO and EVAL all values are strings, so why not leave them
that way for debugging.

Putting DIMs into MapInfo results in code that can not be debugged easy

Set up a Global VB file with the MapBasic.DEF file reformatted
Now all MB commands and values are available to the VB code

[ I work in Delphi/Pascal so I'm making this short and *wrong* but you
should get the idea]

DIM Msg as String
DIM X1, Y1 as String

X1 = MI.Eval( " format$( commandinfo(cmd_info_x), "##0.000000" ) " )
Y1 = MI.Eval( " format$( commandinfo(cmd_info_y), "##0.000000" ) " )
'' now you have debugging
'' also you are forcing decimals because just commandinfo can return
'' truncated decimal values just like the browser with float fields

Msg = "Insert Into gps_temp ("
Msg = msg + Longitude
Msg = msg + ", "
Msg = msg + Latitude
Msg = msg + ") VALUES ("
Msg = msg + X1
Msg = msg + ", "
Msg = msg + Y1
Msg = msg + ")" '.............more stuff
MI.DO Msg

Now you you can set break points and debug MSG before it gets sent to MI
and figure out that """""" is really """ instead of """" [VB nonsense]

Once it works then you can combine the lines in to one long one

Steven Evans

unread,
Jan 15, 2008, 12:51:49 AM1/15/08
to mapi...@googlegroups.com
Hi Guys;

I couldn't get any of these methods to work. Treys answer allowed me to work out that the variable is defined OK in VB but not in Mapbasic.

If I drop my "Insert..." statement into a mapbasic window and run it, I get exactly the same error, which suggests to me the error is returned from Mapbasic, not VB.

I think the hint came from Trey.... "Set up a Global VB file with the MapBasic.DEF file reformatted Now all MB commands and values are available to the VB code" .

I have already had the Mapbasic.def setup as Mapbasic.bas so VB6 can read it.

The problem is (I think) related to the manner in which I am using the mapbasic code in VB.

Because I am using normal mapbasic statements within VB and I have a mapbasic.bas, I don't have ... Include "Mapbasic.def"... for when the mapbasic code runs (as you would normally have if you used plain old Mapbasic).

So.. I am stumped as to what would be the correct syntax for VB to recognise ... Include "Mapbasic.def"... I've tried it as a string, but I'm not sure if this is how it should be

Incidentally, in all the VB samples I have found, none of them actually show how to insert data into a table.

Cheers

> ************* This e-mail (including all attachments) contains

Visit Parkes on the web at http://www.parkes.nsw.gov.au.

Glen

unread,
Jan 15, 2008, 9:29:26 AM1/15/08
to MapInfo-L
Public Sub Init_Map()

Dim temp As String


temp = "Set Map Window " & Mapid & " Center (" & Lon & "," & Lat
&
" ) Zoom 10"
Mapinfo.Do temp


End Sub
Public Sub Init_table()
Mapinfo.Do "Create Table GPS ( Long Float, Lat Float, Radius
Float)"
Mapinfo.Do "Create Map For GPS CoordSys Earth"
Mapinfo.Do "Open Table GPS Interactive"
Mapinfo.Do "Add Map Layer GPS Animate"


End Sub
Public Sub Show_position()


Dim temp As String


temp = "Insert Into GPS Values ( " & Lon & "," & Lat & "," &
0.09
& " )"
Mapinfo.Do temp
Mapinfo.Do "Set Style Pen MakePen ( 2, 2, " & RED & ")"
Mapinfo.Do "Set Style Brush MakeBrush (02, " & RED & "," & RED &
")"
Mapinfo.Do "Insert Into GPS (obj) Values (CreateCircle( Long,
Lat,
Radius ) )"


End Sub


Note lat and long are Variables
I have a bunch of old VB6 code form my drive -testing tool what app
are you trying to complete?

Glen

unread,
Jan 15, 2008, 9:55:52 AM1/15/08
to MapInfo-L

And VB6 is dead. ;-) long live dot.Net
Reply all
Reply to author
Forward
0 new messages