using ImportData with VBScript

Pit Mueller
12-17-2007, 07:24 AM
I have problems using ImportData. Somehow the call of ImportData fails
Please help!

Dim oMP, oDSSMP, oDSMP
Set oMP = GetObject(, "MapPoint.Application")
Set oDSSMP = oMP.ActiveMap.DataSets

' geoFieldName = 1
' geoFieldName2 = 2
' geoFieldAddress1 = 3
' geoFieldCity = 6
' geoFieldPostal1 = 11
' geoFieldCountry = 15
' geoFieldInformation 22
' geoFieldData 23
Dim myExampleArray(3, 2)
myExampleArray(1, 1) = "Name"
myExampleArray(1, 2) = 1 'geoFieldName

myExampleArray(2, 1) = "Vorname"
myExampleArray(2, 2) = 2 'geoFieldName2

myExampleArray(3, 1) = "Land"
myExampleArray(3, 2) = 15 'geoFieldCountry


Set oDSMP = oDSSMP.ImportData("C:\Temp\export.txt", myExampleArray, , 9)

Wilfried
12-29-2007, 11:50 AM
Hi,

What exacly fails, what is the error, is there an exception raised ?

Pit Mueller
01-25-2008, 07:05 AM
The Code is:

800A0FC6

"Data could not be imported, columns not found" (translated from german message)

Set oDSMP = oDSSMP.ImportData(sMyFile, myExampleArray, 39070, 9, 1)

Last Parameter means geoImportFirstRowNotHeadings

Winwaed
01-25-2008, 08:26 AM
But the first row consists of column headings, doesn't it?

(and if it doesn't, how are you telling it what each column is?)

Richard

Pit Mueller
01-25-2008, 09:47 AM
But the first row consists of column headings, doesn't it?

(and if it doesn't, how are you telling it what each column is?)

Richard

No -> i use the array to tell him what columns exist in that file.

Regards

Pit

Eric Frost
01-25-2008, 10:05 AM
Can you post a sample of the export.txt text file as an attachment?

Eric

Pit Mueller
01-28-2008, 08:22 AM
Dim myExampleArray(6, 1)

myExampleArray(1, 1) = 1 'geoFieldName

myExampleArray(2, 1) = 2 'geoFieldName2

myExampleArray(3, 1) = 15 'geoFieldCountry

myExampleArray(4, 1) = 6 'geoFieldCity

myExampleArray(5, 1) = 3 'geoFieldAddress1

myExampleArray(6, 1) = 11 'geoFieldPostal1

Set oDSMP = oDSSMP.ImportData(sMyFile, myExampleArray, 39070, 9, 1)

Eric Frost
01-28-2008, 08:29 AM
Are you able to import it using the regular MapPoint interface / wizard?

I've never imported fixed width text, only CSV or comma-separated.

Can you convert to CSV and see if that helps it to work?

By the way, this is my 2,000th post!

Eric

Pit Mueller
01-29-2008, 08:41 AM
Hi Eric!

Thank you for your help!!

Yes i can import the file directy using the wizard.
The columns are not fixed, they are separated by TABs ;)

Pit

Eric Frost
01-29-2008, 08:44 AM
Just want to be sure - it is working for you now?

What did you do? Switch to CSV?

Eric

Pit Mueller
02-06-2008, 10:38 AM
Unfortunately it is not working with the above code.
Only if i start the import without this array and a header line in the file, i can do the import silently - but i have to choose a special header line for the import file to make MapPoint recognizing the content of the columns automatically.

Pit

Wilfried
02-09-2008, 02:08 AM
Hi,

I did a quick test writing to a file and import it using code below. It works very good. Eventually you try it and check for differences.

double lat;
double lon;
string fileName = Path.GetDirectoryName(Assembly.GetExecutingAssembl y().GetModules()[0].FullyQualifiedName) + "\\temp.csv";

TextWriter writer = new StreamWriter(fileName, false);
try {
writer.WriteLine("Lat;Lon");
lat = 51;
lon = 4;
for (int k = 0; k < 3000; k++) {
writer.WriteLine(lat.ToString() + ";" + lon.ToString());
lon += .0003;
}
} finally {
writer.Close();
}

MapPoint.DataSet dataSet;

// Define field specification
object[,] fieldSpecifications = null;
fieldSpecifications = new object[2, 2];

// Specify what fields are geographic and what fields are not
fieldSpecifications[0, 0] = "Lat";
fieldSpecifications[0, 1] = MapPoint.GeoFieldType.geoFieldLatitude;
fieldSpecifications[1, 0] = "Lon";
fieldSpecifications[1, 1] = MapPoint.GeoFieldType.geoFieldLongitude;
dataSet = MP.ActiveMap.DataSets.ImportData(fileName,
fieldSpecifications,
MapPoint.GeoCountry.geoCountryDefault,
MapPoint.GeoDelimiter.geoDelimiterSemicolon, 0);
dataSet.Symbol = 37;
dataSet.ZoomTo();

Pit Mueller
02-11-2008, 07:29 AM
Thank you for your answer!

This code doesn't seem to be VbScript? What Language ist it? C#?

writer.WriteLine("Lat;Lon");

means, that you add a header line to that file.

In my example I do not add a header line and I use TAB as delimiter, because ; may exist as field content.

Pit

Wilfried
02-15-2008, 08:17 AM
Hi,

Yes example is in C#. Yes I use always a header, maybe that's the reason. But now you can easy compare. I "think" if the delimiting character is in a string and you put the string into quotes "" then you can have it in there. Not sure but easy found with a little experiment.

 
Web mp2kmag.com
mapforums.com