扩展二维数组 [英] Expanding Two-Dimensional Arrays

查看:68
本文介绍了扩展二维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




首先,如果我提出的问题看起来非常明显,请道歉。我是

自学成才的VB2008(通过VB4,VB6和VB2003)用户,并且总是只需要

拿起我需要知道的东西,当我需要时知道了。


我正在编写一个应用程序,需要能够存储几组

标记数据。实际上,它是一个二维数组。我已经创建了这个,

但是它很难处理,因为我必须用最大的

第二维创建它。即公开ApplTag(5,200)为字符串。


经常看,只有一组标签,而且

标签组可能包括只有10个标签,我的1,200个标签的数组看起来好像是b / b
。我确实想到在我去的时候重新调整它,但是

显然会干扰每一组标签,而不仅仅是我使用的那一块。




我真的不想在这个应用程序中使用数据库,所以有没有其他方式VB2008可以为我更好地处理这个问题?我宁愿能够使用一个尺寸完美的阵列,也可能只是下一个

倍数10倍的数组。


谢谢


John

Hi,

Firstly, apologies if what I am asking seems really obvious. I''m a
self-taught VB2008 (via VB4, VB6 and VB2003) user, and have always just
picked up what I need to know, when I need to know it.

I''m writing an application that needs to be able to store several sets of
tagged data. Effectively, it''s a two-dimensional array. I have created this,
but it is unwieldly to work with, as I have had to create it with a maximum
second dimension. I.e. Public ApplTag(5,200) as String.

Seeing as very often, there will only be one set of tags anyway, and that
set of tags might consist of just 10 tags, my array of 1,200 tags seems a
little over the top. I did think of Redimming it as I went, but that
obviously interferes with every set of tags, and not just the one I am
working with.

I don''t really want to use a database with this application, so is there any
other way that VB2008 can handle this better for me? I''d rather be able to
work with an array that is either perfectly sized, or perhaps just the next
multiple of 10 higher in size.

Thanks

John

推荐答案

你好,John,

赛斯的建议非常好。 dotNet提供了许多不同的方法来构建数据。你可能会觉得有趣的另一个选择是使用一个元素是一维数组的
维数组。这看起来好像是一个二维数组,但你引用单个元素

略有不同。也就是说,而不是:


ApplTag(2,4)


你会参考:


ApplTag(2)(4)


我认为这有时被称为衣衫褴褛的阵列。它可能看起来像这样:b $ b这样:

Dim ApplTag(2)()As String


Dim strRow0 ()As String = {" A"," BB"," CCC"," DDDD"," EEEEE"}

Dim strRow1()As String = {" F" ;,GG}

Dim strRow2()As String = {" H",II,JJJ,KKKK,LLLLL,

" MMMMMM"}

ApplTag(0)= strRow0

ApplTag(1)= strRow1

ApplTag(2)= strRow2


MsgBox(" element(2,4)的值是"& ApplTag(2)(4))


我发现另一种类似数组的用途是

" ArrayList"。你可能也想看一下。


干杯,

兰迪
Hello, John,

Seth''s suggestions are very good. dotNet provides many different ways to
structure your data. Another option you may find interesting is to use a one
dimensional array whose elements are one dimensional arrays. This looks
something like a two dimensional array, but you reference individual elements
slightly differently. That is, instead of:

ApplTag(2,4)

you would refer to:

ApplTag(2)(4)

I think this is sometimes called a "ragged array". It might look something
like this:

Dim ApplTag(2)() As String

Dim strRow0() As String = {"A", "BB", "CCC", "DDDD", "EEEEE"}
Dim strRow1() As String = {"F", "GG"}
Dim strRow2() As String = {"H", "II", "JJJ", "KKKK", "LLLLL",
"MMMMMM"}

ApplTag(0) = strRow0
ApplTag(1) = strRow1
ApplTag(2) = strRow2

MsgBox("The value of element (2,4) is " & ApplTag(2)(4))

Another type that I find to be very useful for array-like purposes is
"ArrayList". You might want to take a look at that also.

Cheers,
Randy




" John Whitworth" < se **** @ gEEEEEEEEEEEEEEEEEEmail.com写在留言中

新闻:%2 **************** @ TK2MSFTNGP05.phx.gbl ...


感谢大家的帮助。我会尝试你的建议。


我原来把标签,长度和价值作为一个班级结构,但是我确实把b $ b弄得一团糟当我试图将其合并到数组中时。我将通过提供的示例代码获得另外的支付。


干杯


JW




" John Whitworth" < se **** @ gEEEEEEEEEEEEEEEEEEmail.com写在留言中

新闻:%2 **************** @ TK2MSFTNGP05.phx.gbl ...

"John Whitworth" <se****@gEEEEEEEEEEEEEEEEmail.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...

>
>



大家好,


好​​的......我试过按照一些建议,并且有构建了

以下......


公共类ApplElement


私有_tag作为字符串

Private _length As Integer

Private _value As String


Public Sub ApplElement(ByVal tag As String,ByVal length As Integer,

ByVal值As String)

_tag = tag

_length = length

_value = value

End Sub


Public ReadOnly Property Tag()As String

获取

返回_tag

结束获取

结束物业


Public ReadOnly属性长度()为整数

获取

返回_length < br $>
结束获取

结束物业


公共读物属性值()为字符串

获取

返回_value

结束获取

结束财产


结束班级

公共类EmvApp


私有_元作为应用


Public Sub EmvApp(ByVal元素作为应用)

_element = element

End Sub


Public ReadOnly Property Element()

获取

返回_元素

结束获取

结束物业


结束课程

我试图添加一个新的应用程序元素(由Tag,Length

和Value组成)使用以下行(事先有DIMmed):


EmvApplic.Add(New EmvApp(New ApplElement(BuildRow.Tag,BuildRow.Len,

BuildRow.Val)))

编辑器给出错误:公共参数太多 Sub New()''。


我现在不确定:


- 是EmvApplic.Add应该添加一个新的应用程序元素同时还有一个新的

应用程序数组?

- 我可以使用它来为Visa EmvA添加50个ApplElements pp,

然后将46 TLV ApplElements添加到MasterCard EmvApp,然后返回

Visa一个,并根据需要添加更多?

- 为什么我得到太多的论点?当ApplElement设置3个值?


对不起,如果我在这里真的很厚...我肯定很快便会掉线。

我意识到我之前在VB.net中没有真正处理过课程

意义上 - 只有VB6课程,我想它更像是结构?


谢谢


John

Hi again all,

OK...I''ve tried to follow some of the advice, and have constructed the
following...

Public Class ApplElement

Private _tag As String
Private _length As Integer
Private _value As String

Public Sub ApplElement(ByVal tag As String, ByVal length As Integer,
ByVal value As String)
_tag = tag
_length = length
_value = value
End Sub

Public ReadOnly Property Tag() As String
Get
Return _tag
End Get
End Property

Public ReadOnly Property Length() As Integer
Get
Return _length
End Get
End Property

Public ReadOnly Property Value() As String
Get
Return _value
End Get
End Property

End Class
Public Class EmvApp

Private _element As ApplElement

Public Sub EmvApp(ByVal element As ApplElement)
_element = element
End Sub

Public ReadOnly Property Element()
Get
Return _element
End Get
End Property

End Class
And I attempt to add one new application element (consisting of Tag, Length
and Value) using the following line (having DIMmed beforehand):

EmvApplic.Add(New EmvApp(New ApplElement(BuildRow.Tag, BuildRow.Len,
BuildRow.Val)))

The editor gives error: "Too many arguments to ''Public Sub New()''.

Not sure I understand now:

- is EmvApplic.Add supposed to be adding a new application element and a new
application array at the same time?
- can I use this to, for instance, add 50 ApplElements to a Visa EmvApp,
then add 46 TLV ApplElements to a MasterCard EmvApp, then go back to the
Visa one, and add any more as necessary?
- and why do I get "too many arguments" when ApplElement is set up 3 values?

Sorry if I am being totally thick here...I''m sure the penny will drop soon.
I realised that I haven''t actually dealt with classes before in the VB.net
sense - only VB6 classes, which I guess are more like structures?

Thanks

John


这篇关于扩展二维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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