vb中如何给数组赋值?
下面是Turboc中给数组赋值的数据,如何可以在vb中实现,因为初学vb,有很多不明白的,谢谢大家帮忙。float F[251]={
1.000,1.000,1.000,0.999,0.999,0.998,0.997,0.996,0.995,0.994, /* 0 */
0.992,0.991,0.989,0.987,0.985,0.983,0.981,0.978,0.976,0.973, /* 10 */
0.970,0.967,0.963,0.960,0.957,0.953,0.950,0.946,0.943,0.939, /* 20 */
0.936,0.932,0.929,0.925,0.922,0.918,0.914,0.910,0.906,0.903, /* 30 */
0.899,0.895,0.891,0.887,0.882,0.878,0.874,0.870,0.865,0.861, /* 40 */
0.856,0.852,0.847,0.842,0.838,0.833,0.828,0.823,0.818,0.813, /* 50 */
0.807,0.802,0.797,0.791,0.786,0.780,0.774,0.769,0.763,0.757, /* 60 */
0.751,0.745,0.739,0.732,0.726,0.720,0.714,0.707,0.701,0.694, /* 70 */
0.688,0.681,0.675,0.668,0.661,0.655,0.648,0.641,0.635,0.628, /* 80 */
0.621,0.614,0.608,0.601,0.594,0.588,0.581,0.575,0.568,0.561, /* 90 */
0.555,0.549,0.542,0.536,0.529,0.523,0.517,0.511,0.505,0.499, /* 100 */
0.493,0.487,0.481,0.475,0.470,0.464,0.458,0.453,0.447,0.442, /* 110 */
0.437,0.432,0.426,0.421,0.416,0.411,0.406,0.402,0.397,0.392, /* 120 */
0.387,0.383,0.378,0.374,0.370,0.365,0.361,0.357,0.353,0.349, /* 130 */
0.345,0.341,0.337,0.333,0.329,0.326,0.332,0.318,0.315,0.311, /* 140 */
0.308,0.304,0.301,0.298,0.295,0.291,0.288,0.285,0.282,0.279, /* 150 */
0.276,0.273,0.270,0.267,0.265,0.262,0.259,0.256,0.254,0.251, /* 160 */
0.249,0.246,0.244,0.241,0.239,0.236,0.234,0.232,0.229,0.227, /* 170 */
0.225,0.223,0.220,0.218,0.216,0.214,0.212,0.210,0.208,0.206, /* 180 */
0.204,0.202,0.200,0.198,0.197,0.195,0.193,0.191,0.190,0.188, /* 190 */
0.186,0.184,0.183,0.181,0.180,0.178,0.176,0.175,0.173,0.172, /* 200 */
0.170,0.169,0.167,0.166,0.165,0.163,0.162,0.160,0.159,0.158, /* 210 */
0.156,0.155,0.154,0.153,0.151,0.150,0.149,0.148,0.146,0.145, /* 220 */
0.144,0.143,0.142,0.141,0.140,0.138,0.137,0.136,0.135,0.134, /* 230 */
0.133,0.132,0.131,0.130,0.129,0.128,0.127,0.126,0.125,0.124, /* 240 */
0.123}; --------------------编程问答-------------------- dim fff()
dim fffAll as string
fffAll="1.000,1.000,1.000,0.999,0.999,0.998,0.997,0.996,0.995,0.994, /* 0 */
0.992,0.991,0.989,0.987,0.985,0.983,0.981,0.978,0.976,0.973, /* 10 */
0.970,0.967,0.963,0.960,0.957,0.953,0.950,0.946,0.943,0.939, /* 20 */
0.936,0.932,0.929,0.925,0.922,0.918,0.914,0.910,0.906,0.903, /* 30 */
0.899,0.895,0.891,0.887,0.882,0.878,0.874,0.870,0.865,0.861, /* 40 */
0.856,0.852,0.847,0.842,0.838,0.833,0.828,0.823,0.818,0.813, /* 50 */
0.807,0.802,0.797,0.791,0.786,0.780,0.774,0.769,0.763,0.757, /* 60 */
0.751,0.745,0.739,0.732,0.726,0.720,0.714,0.707,0.701,0.694, /* 70 */
0.688,0.681,0.675,0.668,0.661,0.655,0.648,0.641,0.635,0.628, /* 80 */
0.621,0.614,0.608,0.601,0.594,0.588,0.581,0.575,0.568,0.561, /* 90 */
0.555,0.549,0.542,0.536,0.529,0.523,0.517,0.511,0.505,0.499, /* 100 */
0.493,0.487,0.481,0.475,0.470,0.464,0.458,0.453,0.447,0.442, /* 110 */
0.437,0.432,0.426,0.421,0.416,0.411,0.406,0.402,0.397,0.392, /* 120 */
0.387,0.383,0.378,0.374,0.370,0.365,0.361,0.357,0.353,0.349, /* 130 */
0.345,0.341,0.337,0.333,0.329,0.326,0.332,0.318,0.315,0.311, /* 140 */
0.308,0.304,0.301,0.298,0.295,0.291,0.288,0.285,0.282,0.279, /* 150 */
0.276,0.273,0.270,0.267,0.265,0.262,0.259,0.256,0.254,0.251, /* 160 */
0.249,0.246,0.244,0.241,0.239,0.236,0.234,0.232,0.229,0.227, /* 170 */
0.225,0.223,0.220,0.218,0.216,0.214,0.212,0.210,0.208,0.206, /* 180 */
0.204,0.202,0.200,0.198,0.197,0.195,0.193,0.191,0.190,0.188, /* 190 */
0.186,0.184,0.183,0.181,0.180,0.178,0.176,0.175,0.173,0.172, /* 200 */
0.170,0.169,0.167,0.166,0.165,0.163,0.162,0.160,0.159,0.158, /* 210 */
0.156,0.155,0.154,0.153,0.151,0.150,0.149,0.148,0.146,0.145, /* 220 */
0.144,0.143,0.142,0.141,0.140,0.138,0.137,0.136,0.135,0.134, /* 230 */
0.133,0.132,0.131,0.130,0.129,0.128,0.127,0.126,0.125,0.124, /* 240 */
0.123"
fff=split(fffAll,",") --------------------编程问答-------------------- dim f()
dim strf as string strf="1.000,1.000,1.000,0.999,0.999,0.998,0.997,0.996,0.995,0.994,
0.992,0.991,0.989,0.987,0.985,0.983,0.981,0.978,0.976,0.973,
0.970,0.967,0.963,0.960,0.957,0.953,0.950,0.946,0.943,0.939,
0.936,0.932,0.929,0.925,0.922,0.918,0.914,0.910,0.906,0.903,
0.899,0.895,0.891,0.887,0.882,0.878,0.874,0.870,0.865,0.861,
0.856,0.852,0.847,0.842,0.838,0.833,0.828,0.823,0.818,0.813,
0.807,0.802,0.797,0.791,0.786,0.780,0.774,0.769,0.763,0.757,
0.751,0.745,0.739,0.732,0.726,0.720,0.714,0.707,0.701,0.694,
0.688,0.681,0.675,0.668,0.661,0.655,0.648,0.641,0.635,0.628,
0.621,0.614,0.608,0.601,0.594,0.588,0.581,0.575,0.568,0.561,
0.555,0.549,0.542,0.536,0.529,0.523,0.517,0.511,0.505,0.499,
0.493,0.487,0.481,0.475,0.470,0.464,0.458,0.453,0.447,0.442,
0.437,0.432,0.426,0.421,0.416,0.411,0.406,0.402,0.397,0.392,
0.387,0.383,0.378,0.374,0.370,0.365,0.361,0.357,0.353,0.349,
0.345,0.341,0.337,0.333,0.329,0.326,0.332,0.318,0.315,0.311,
0.308,0.304,0.301,0.298,0.295,0.291,0.288,0.285,0.282,0.279,
0.276,0.273,0.270,0.267,0.265,0.262,0.259,0.256,0.254,0.251,
0.249,0.246,0.244,0.241,0.239,0.236,0.234,0.232,0.229,0.227,
0.225,0.223,0.220,0.218,0.216,0.214,0.212,0.210,0.208,0.206,
0.204,0.202,0.200,0.198,0.197,0.195,0.193,0.191,0.190,0.188,
0.186,0.184,0.183,0.181,0.180,0.178,0.176,0.175,0.173,0.172,
0.170,0.169,0.167,0.166,0.165,0.163,0.162,0.160,0.159,0.158,
0.156,0.155,0.154,0.153,0.151,0.150,0.149,0.148,0.146,0.145,
0.144,0.143,0.142,0.141,0.140,0.138,0.137,0.136,0.135,0.134,
0.133,0.132,0.131,0.130,0.129,0.128,0.127,0.126,0.125,0.124,
0.123"
f=split(strf,",") --------------------编程问答-------------------- dim f()
dim strf as string strf="1.000,1.000,1.000,0.999,0.999,0.998,0.997,0.996,0.995,0.994,
0.992,0.991,0.989,0.987,0.985,0.983,0.981,0.978,0.976,0.973,
0.970,0.967,0.963,0.960,0.957,0.953,0.950,0.946,0.943,0.939,
0.936,0.932,0.929,0.925,0.922,0.918,0.914,0.910,0.906,0.903,
0.899,0.895,0.891,0.887,0.882,0.878,0.874,0.870,0.865,0.861,
0.856,0.852,0.847,0.842,0.838,0.833,0.828,0.823,0.818,0.813,
0.807,0.802,0.797,0.791,0.786,0.780,0.774,0.769,0.763,0.757,
0.751,0.745,0.739,0.732,0.726,0.720,0.714,0.707,0.701,0.694,
0.688,0.681,0.675,0.668,0.661,0.655,0.648,0.641,0.635,0.628,
0.621,0.614,0.608,0.601,0.594,0.588,0.581,0.575,0.568,0.561,
0.555,0.549,0.542,0.536,0.529,0.523,0.517,0.511,0.505,0.499,
0.493,0.487,0.481,0.475,0.470,0.464,0.458,0.453,0.447,0.442,
0.437,0.432,0.426,0.421,0.416,0.411,0.406,0.402,0.397,0.392,
0.387,0.383,0.378,0.374,0.370,0.365,0.361,0.357,0.353,0.349,
0.345,0.341,0.337,0.333,0.329,0.326,0.332,0.318,0.315,0.311,
0.308,0.304,0.301,0.298,0.295,0.291,0.288,0.285,0.282,0.279,
0.276,0.273,0.270,0.267,0.265,0.262,0.259,0.256,0.254,0.251,
0.249,0.246,0.244,0.241,0.239,0.236,0.234,0.232,0.229,0.227,
0.225,0.223,0.220,0.218,0.216,0.214,0.212,0.210,0.208,0.206,
0.204,0.202,0.200,0.198,0.197,0.195,0.193,0.191,0.190,0.188,
0.186,0.184,0.183,0.181,0.180,0.178,0.176,0.175,0.173,0.172,
0.170,0.169,0.167,0.166,0.165,0.163,0.162,0.160,0.159,0.158,
0.156,0.155,0.154,0.153,0.151,0.150,0.149,0.148,0.146,0.145,
0.144,0.143,0.142,0.141,0.140,0.138,0.137,0.136,0.135,0.134,
0.133,0.132,0.131,0.130,0.129,0.128,0.127,0.126,0.125,0.124,
0.123"
f=split(strf,",") --------------------编程问答--------------------
--------------------编程问答-------------------- split函数这个我也试用了,但是当把这串数组作为字符串赋值时,段行的时候用"_"符号连接,也会报错,不知道还有没其他方法,用.dat或者.txt导入一维数组中,再次感谢大家帮忙! --------------------编程问答--------------------
Dim f()
On Error Resume Next
f = Array( _
1, 1, 1, 0.999, 0.999, 0.998, 0.997, 0.996, 0.995, 0.994, 0.992, 0.991, 0.989, 0.987, 0.985, 0.983, 0.981, 0.978, 0.976, 0.973, _
0.97, 0.967, 0.963, 0.96, 0.957, 0.953, 0.95, 0.946, 0.943, 0.939, 0.936, 0.932, 0.929, 0.925, 0.922, 0.918, 0.914, 0.91, 0.906, 0.903, _
0.899, 0.895, 0.891, 0.887, 0.882, 0.878, 0.874, 0.87, 0.865, 0.861, 0.856, 0.852, 0.847, 0.842, 0.838, 0.833, 0.828, 0.823, 0.818, 0.813, _
0.807, 0.802, 0.797, 0.791, 0.786, 0.78, 0.774, 0.769, 0.763, 0.757, 0.751, 0.745, 0.739, 0.732, 0.726, 0.72, 0.714, 0.707, 0.701, 0.694, _
0.688, 0.681, 0.675, 0.668, 0.661, 0.655, 0.648, 0.641, 0.635, 0.628, 0.621, 0.614, 0.608, 0.601, 0.594, 0.588, 0.581, 0.575, 0.568, 0.561, _
0.555, 0.549, 0.542, 0.536, 0.529, 0.523, 0.517, 0.511, 0.505, 0.499, 0.493, 0.487, 0.481, 0.475, 0.47, 0.464, 0.458, 0.453, 0.447, 0.442, _
0.437, 0.432, 0.426, 0.421, 0.416, 0.411, 0.406, 0.402, 0.397, 0.392, 0.387, 0.383, 0.378, 0.374, 0.37, 0.365, 0.361, 0.357, 0.353, 0.349, _
0.345, 0.341, 0.337, 0.333, 0.329, 0.326, 0.332, 0.318, 0.315, 0.311, 0.308, 0.304, 0.301, 0.298, 0.295, 0.291, 0.288, 0.285, 0.282, 0.279, _
0.276, 0.273, 0.27, 0.267, 0.265, 0.262, 0.259, 0.256, 0.254, 0.251, 0.249, 0.246, 0.244, 0.241, 0.239, 0.236, 0.234, 0.232, 0.229, 0.227, _
0.225, 0.223, 0.22, 0.218, 0.216, 0.214, 0.212, 0.21, 0.208, 0.206, 0.204, 0.202, 0.2, 0.198, 0.197, 0.195, 0.193, 0.191, 0.19, 0.188, _
0.186, 0.184, 0.183, 0.181, 0.18, 0.178, 0.176, 0.175, 0.173, 0.172, 0.17, 0.169, 0.167, 0.166, 0.165, 0.163, 0.162, 0.16, 0.159, 0.158, _
0.156, 0.155, 0.154, 0.153, 0.151, 0.15, 0.149, 0.148, 0.146, 0.145, 0.144, 0.143, 0.142, 0.141, 0.14, 0.138, 0.137, 0.136, 0.135, 0.134, _
0.133, 0.132, 0.131, 0.13, 0.129, 0.128, 0.127, 0.126, 0.125, 0.124, 0.123)
'注意VB中段行的时候要用"_"符号连接.
'不过也不能断行过多,否则VB会提示错误
'这代码我帮你测试过而且通过了~
'这是本人推荐的用法,将Single和CSng进行修改就能适用不同的类型--------------------编程问答-------------------- dim a
function NewSingleArray(paramarray args()) as single()
dim a() as single, i as long
redim a(ubound(args))
for i=0 to ubound(args)
a(i) = csng(args(i))
next
NewSingleArray = a
end function
'如下调用就能得到正确类型的数组
sub Main()
dim f() as single
f = NewSingleArray( _
1#, 1#, 1#, 0.999, 0.999, 0.998, 0.997, 0.996, 0.995, 0.994, 0.992, 0.991, 0.989, 0.987, 0.985, _
0.983, 0.981, 0.978, 0.976, 0.973, 0.97, 0.967, 0.963, 0.96, 0.957, 0.953, 0.95, 0.946, 0.943, 0.939, _
0.936, 0.932, 0.929, 0.925, 0.922, 0.918, 0.914, 0.91, 0.906, 0.903, 0.899, 0.895, 0.891, 0.887, 0.882, _
0.878, 0.874, 0.87, 0.865, 0.861, 0.856, 0.852, 0.847, 0.842, 0.838, 0.833, 0.828, 0.823, 0.818, 0.813, _
0.807, 0.802, 0.797, 0.791, 0.786, 0.78, 0.774, 0.769, 0.763, 0.757, 0.751, 0.745, 0.739, 0.732, 0.726, _
0.72, 0.714, 0.707, 0.701, 0.694, 0.688, 0.681, 0.675, 0.668, 0.661, 0.655, 0.648, 0.641, 0.635, 0.628, _
0.621, 0.614, 0.608, 0.601, 0.594, 0.588, 0.581, 0.575, 0.568, 0.561, 0.555, 0.549, 0.542, 0.536, 0.529, _
0.523, 0.517, 0.511, 0.505, 0.499, 0.493, 0.487, 0.481, 0.475, 0.47, 0.464, 0.458, 0.453, 0.447, 0.442, _
0.437, 0.432, 0.426, 0.421, 0.416, 0.411, 0.406, 0.402, 0.397, 0.392, 0.387, 0.383, 0.378, 0.374, 0.37, _
0.365, 0.361, 0.357, 0.353, 0.349, 0.345, 0.341, 0.337, 0.333, 0.329, 0.326, 0.332, 0.318, 0.315, 0.311, _
0.308, 0.304, 0.301, 0.298, 0.295, 0.291, 0.288, 0.285, 0.282, 0.279, 0.276, 0.273, 0.27, 0.267, 0.265, _
0.262, 0.259, 0.256, 0.254, 0.251, 0.249, 0.246, 0.244, 0.241, 0.239, 0.236, 0.234, 0.232, 0.229, 0.227, _
0.225, 0.223, 0.22, 0.218, 0.216, 0.214, 0.212, 0.21, 0.208, 0.206, 0.204, 0.202, 0.2, 0.198, 0.197, _
0.195, 0.193, 0.191, 0.19, 0.188, 0.186, 0.184, 0.183, 0.181, 0.18, 0.178, 0.176, 0.175, 0.173, 0.172, _
0.17, 0.169, 0.167, 0.166, 0.165, 0.163, 0.162, 0.16, 0.159, 0.158, 0.156, 0.155, 0.154, 0.153, 0.151, _
0.15, 0.149, 0.148, 0.146, 0.145, 0.144, 0.143, 0.142, 0.141, 0.14, 0.138, 0.137, 0.136, 0.135, 0.134, _
0.133, 0.132, 0.131, 0.13, 0.129, 0.128, 0.127, 0.126, 0.125, 0.124, 0.123)
end sub
a=Array(1.000,1.000,...)依次赋值 --------------------编程问答-------------------- 谢谢大家帮忙了!
补充:VB , 基础类