帮助函数返回数组 - 类型不匹配 [英] Help with Function to return Array - Type Mismatch

查看:59
本文介绍了帮助函数返回数组 - 类型不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前从来没有在任何网站上发过任何问题,但是经过几天这个障碍,我已经屈服了。我正在开发一个程序来创建一个kml文件并将其导出到Google Earth。在该文件中,我想在地标周围创建一个5英里半径的圆圈。为此,我使用了我在网上找到的kml circlegen源代码。它计算构成圆的点的纬度和经度。计算工作正确(如通过打印到立即窗口或通过调用sub显示),但我无法获得返回数组的函数。由于我已经构建了许多不同的方法,我不断得到类型不匹配。任何帮助将不胜感激!我相信我已经包含了所有必要的功能代码:

展开 | 选择 | Wrap | 行号

解决方案

您好。


变体类型包括数组。

因此,只需将FiveMileCircleGen函数返回值类型更改为Variant。它应该工作。

展开 | 选择 < span class =codeDivider> | Wrap | 行号


谢谢Fish。当我删除()时来自


公共函数FiveMileCircleGen(lat1为Double,lon1为Double)As Variant()


它然后给我一个下标范围错误。为了解决这个问题,我将行更改为以下内容:


Redim ResultArray(i to iNumSides)


现在它给了我一个''运行' - 时间错误13,类型不匹配''


Loren


据我所知,没有办法明确定义一个函数返回数组。


但是,可以将其定义为Variant,并将返回值设置为数组(变量可以处理数组)。

这个快速功能说明了如何做到这一点:

展开 | 选择 | Wrap | Line编号

I''ve never posted a question on any site before, but after racking my head over this hurdle for days, I''ve caved. I''m working on a program that creates a kml file and exports it to Google Earth. In that file, I want to create a 5 mile radius circle around the placemark. To do that, I worked with the kml circlegen source I found online in php. It calculates the latitudes and longitudes of the points that make up the circle. The calculation works correrctly (as shown by printing to the immediate window or by calling the sub), but I can''t get the function to return the array. As many different ways I''ve structured it, I keep getting a ''type mismatch''. Any help would be GREATLY appreciated! I believe I''ve included all the necessary function code:

Expand|Select|Wrap|Line Numbers

解决方案

Hello.

Variant type includes array.
So, just change FiveMileCircleGen function return value type to Variant. It should work.

Expand|Select|Wrap|Line Numbers


Thanks Fish. When I remove the "()" from

Public Function FiveMileCircleGen(lat1 As Double, lon1 As Double) As Variant()

It then gives me a "Subscript out of range" error. To fix that I change the line to the following:

Redim ResultArray(i To iNumSides)

Now it gives me a ''run-time error 13, type mismatch''

Loren


As far as I can tell, there is no way of defining a function explicitly to return an array.

However, it is possible to define it as a Variant, and set the return value as an array (Variants can handle arrays).

This quick function illustrates how this can be done :

Expand|Select|Wrap|Line Numbers


这篇关于帮助函数返回数组 - 类型不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆