VB.net 如何编写一个可以返回数组的函数(过程)?

如:登录窗口,用户名为下列表框,里面的数据项需通过一个函数来完成添加,(因为它地方可也需要用到这个功能,所以选择用函数来实现)

第1个回答  推荐于2016-03-21
public function createstringarr() as string()
return new string(){"d1","d2","d3","d4"}
end function追问

附代码,请帮忙修改

追答

public function CombList(mytj As String) As String()
dim cmd as new oledbcommand(mytj,conn)
'如果用泛型:
dim lr as new list(of string)
''如果不用泛型
'dim lr as new arraylist()

dbreader=cmd.executereader
while dbreader.read
lr.add dbreader.getstring(0)
end while
conn.close()
dbreader.close()
'如果用泛型:
return lr.toarray()
''如果不用泛型:
'return lr.toarray(GetType(String))
End function

调用:
opendata("reg_user","")
tj="select * from reg_user"
dim arraystring as string() = comblist(tj)
for each s as string in arraystring
cmbuserid.items.add(s)
next

本回答被提问者采纳

VB.net 如何编写一个可以返回数组的函数(过程)?
public function createstringarr() as string()return new string(){"d1","d2","d3","d4"} end function

VB.NET格式输出函数format怎么用?
MyStr = Format("HELLO", "<") ' 返回 "hello"。MyStr = Format("This is it", ">") ' 返回 "THIS IS IT

在VB.NET编程中使用数组
4. 申明参数为数组的过程或者函数,由于数组是引用类型,所以在申明参数为数组的函数或过程时,处理方法与参数为值类型的函数或过程有点不一样。5. 简要介绍Array类和其主要的常用,以及通过Array类操作数组的具体方法。在Visual 申明一个数组使用的依然是Dim语句,其申明数组和Visual Basic的主要区别在上面内容中已经简单...

在VB.net中如何取变量、结构、数组、函数的地址?
0 * 4)) '读回数组的第一个元素 MsgBox(Marshal.ReadInt32(pai, 1 * 4)) '读回数组的第二个元素 MsgBox(Marshal.ReadInt32(pai, 2 * 4)) '

用vb.net编写一个函数,求任意整数数组的最大元素
private function maxnum(byval a() as integer) as integer dim i as integer maxnum=a(0)for i = 1 to ubound(a)if a(i)>maxnum then maxnum=a(i)next end function

VB.NET数组或数组列表
Dim TestShoppingList As String = Join(TestItem, " = ") 'Join 就是字符联接函数 后面的 =号 可选 为空值就把所有的字符串在一起 本例用=号 就是把 所有数组的值用 =号联接起来 MsgBox(TestShoppingList) '显示结果值 '这例子 就一个函数可以解决 就不发图片了 希望能帮到你 你...

vb.net 里面如何判断某个值存在一个数组中?
如果是简单类型,可以用数组的indexof方法 Dim colXX As String() = New String() {"1", "2", "3", "4Dim colXX As String() = New String() {"1", "2", "3", "4"} if (colXX.indexof("2") >= 0) then return true end if ...

vb2005的sub或function怎么返回数组?
二维Double这样写:Public Class Form1 Private Sub test(ByRef arr(,) As Double)Dim i As Integer For i = 0 To 3 arr(i, 1) = i Next End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim arr(3, 3) As ...

vb.net,dim rects as rectangle()()={a,b,c,d,e,f} 我忘了双小...
rectabcd.GetValue(2) ''获取rectabcd{c}返回值 Object。……ListRect.Item(2).Height rectabcd.ToList.Item(0) ''获取或设置rectabcd.ToList[a]的值。End Sub Public ListRect As List(Of Drawing.Rectangle) = {New Rectangle(0, 0, 10, 10), New Rectangle(10, 1, 20, 20)}.To...

vb.net保存数据和读取数据问题问题。(VS2010开发坏境)
count += 1 line = sr.ReadLine()If count Mod 2 = 1 Then Else line = line.Replace(",", " ")Dim tmp As String() = line.Trim.Split(" ")For i As Integer = 0 To tmp.Length - 1 '因为多了个","所以多个空字符 CType(arr2(count \\ 2 - 1), String())(i) = tmp(...

相似回答