0

私はVS2012を使用しています。

コードの実行中に変数を動的に宣言する方法がわかりません。Web サイトから EMS ディスパッチのデータを取得するプログラムを作成しようとしています。Web サイトは数秒ごとに更新され、投稿される通話にはそれぞれ固有の ID 番号が付けられます。各ディスパッチの一意の ID 番号を使用し、その一意の ID 番号を使用して新しいインシデント変数を宣言し、それをアクティブなディスパッチのコレクションに追加したいと考えています。私が理解できない唯一の部分は、投稿された各ディスパッチの変数を宣言し、一意の ID 番号で名前を付ける方法です。

何かのようなもの:

Structure Incident
  Dim id As Integer

  Dim numer As String
  Dim date1 As String
  Dim time As String
  Dim box As String
  Dim type As String
  Dim street As String
  Dim crosstreet As String
  Dim location As String
  Dim announced As Boolean
  Dim complete As Boolean
End Structure

UniqueIDstringfromwebsite = "1234"

Dim (code to get variable declared with unique ID as variable name) as incident

これは私の最初の投稿であり、投稿でコードサンプルを正しく動作させることができません。

4

2 に答える 2

1

これが私の最初の答えです-だからあなたは良い仲間です!

構造体の代わりにクラスを実装する必要はありませんか?そうすれば、コンストラクターを実装できます。IDを名前として使用して変数を作成する必要はないと思いますが、IDをディスパッチコレクションに追加する必要があります(これは(インシデントの)リストである可能性があります:

例えば

Public Class Incident

     'define private variables

     Private _id as integer
     Private _number as string
     Private _date1 as String
     Private _time as String
     'etc...

     'define public properties

    Public Property Number as string
        Get 
            Return _number
        End Get
        Set (value as string)
            _number = value
        End Set
    End Property

    'Repeat for each Public Property

    'Implement Constuctor that takes ID
    Public Sub New(id as integer)
        _id = id
        'code here to get incident properties based on id
    End Sub

End Class

お役に立てれば!

于 2013-03-19T15:33:17.057 に答える
1

a を使用しDictionaryて var を識別できます。

Dim myVar As New Dictionary(Of Integer, Incident)

UniqueIDstringfromwebsite = 1234
myVar.Add(UniqueIDstringfromwebsite, New Incident)

変数の名前を値で動的に、そして誠実に変更できるとは思いません。それがいつ役立つかわかりません。

そして、このようにして、構造をクラスに変換することをお勧めします。

于 2013-03-19T15:22:59.430 に答える