小编Ger*_*ert的帖子

将常量数组传递给VB.NET中的函数

我知道您可以轻松地将数组传递给函数,如下面的代码所示

Private Sub SomeFunction(ByVal PassedArray() As String)
    For i As Integer = 0 To PassedArray.Count - 1
        Debug.WriteLine(PassedArray(i))
    Next
End Sub

Public Sub Test()
    Dim MyArray As String() = {"some", "array", "members"}

    SomeFunction(MyArray)
End Sub
Run Code Online (Sandbox Code Playgroud)

但是有没有办法将常量数组传递给VB.NET中的函数呢?

例如在PHP中,您可以编写:

function SomeFunction($array)
{
    for($i=0;$i<count($array);$i++)
    {
         echo($array[$i]);
    }
}

function Test()
{
    SomeFunction(array("some", "array", "members")); // Works for PHP
}
Run Code Online (Sandbox Code Playgroud)

所以重申一下:有没有办法将常量数组直接传递给VB.NET中的函数?这样做有什么好处吗?我想象可以节省几个字节的内存。

PS:

SomeFunction({"some", "array", "member"}) ' This obviously gives a syntax error
Run Code Online (Sandbox Code Playgroud)

vb.net arrays constants

5
推荐指数
2
解决办法
2万
查看次数

VB6中的"对象变量或块变量未设置"运行时错误

我有VB6的问题.我有一个包含几个ComboBox对象的表单.我希望通过一个以SQL查询作为参数的函数来填充ComboBoxes.所以代码看起来像这样

Private Function FillComboBoxFromMDB(ByVal sDBName As String, _
                                     ByVal sSQL As String) As ComboBox
    '/*
    ' * Execute SQL in MDB and fill the ComboBox with the results
    ' * Returns filled ComboBox
    ' */
    Dim DB As Database
    Dim DBRecordset As Recordset

    On Error GoTo FillComboBoxFromMDB_ErrHandler

    Set DB = OpenDatabase(sDBName, False, False)

    If Not DB Is Nothing Then
        Set DBRecordset = DB.OpenRecordset(sSQL)
        If Not DBRecordset Is Nothing Then
            If DBRecordset.RecordCount > 0 Then
                Call FillComboBoxFromMDB.AddItem(DBRecordset.Fields(0).Value)
                ' ^^ This row …
Run Code Online (Sandbox Code Playgroud)

vb6 runtime instantiation

2
推荐指数
1
解决办法
4万
查看次数

标签 统计

arrays ×1

constants ×1

instantiation ×1

runtime ×1

vb.net ×1

vb6 ×1