vb陣列擷取,vb中陣列元素的提取問題

時間 2022-12-01 00:25:34

1樓:

private sub command1_click()dim a() as string, ac, ia = split(text1.text, vbcrlf)ac = val(text2.text)

if ubound(a) >= ac and ac > 0 thenfor i = 0 to ac - 1

text3.text = text3.text & a(i) & vbcrlf

next

end if

end sub

如何在vb中快速擷取陣列中的一部分

2樓:匿名使用者

你好,擷取用mid函式就可以。

比如:a="1234567" 要想擷取第5個字5,就寫 b=(a,5,1)

函式名稱:mid

主要功能:從乙個字串的指定位置開始,擷取指定數目的字元。

使用格式:mid(text,start_num,num_chars)引數說明:text代表乙個文字字串;start_num表示指定的起始位置;num_chars表示要擷取的數目。

vb中陣列元素的提取問題

3樓:網海1書生

dim s() as string

s = split(text1.text, " ")text2.text = s(0)

text3.text = s(1)

text4.text = s(2)

4樓:匿名使用者

dim a(3) as string

a=split(text1.text," ")text2.text=a(1)

text3.text=a(2)

text4.text=a(3)

vb怎麼取用用逗號分隔的資料

5樓:勒泰號

split(sj, ",")

6樓:匿名使用者

用split()這個函式。

例:dim a() as string

dim str1 as string

str1="111.112.113.114"

a = split(str1, ".")

a的下標是0到3

請教vb乙個陣列複製的問題

7樓:匿名使用者

如果你用的是vb6.0的話,那有乙個相當簡單的方法來完成陣列複製操作。即使用vb6.0中提供的動態陣列增強功能。

它的使用也很簡單,首先是宣告陣列,然後是直接賦值。例如對於你上面的提供的**,改為使用動態陣列增強功能的話,**如下:

dim a() as single '注意a陣列必須是動態陣列,如寫為dim a(1000000) as single則錯誤

dim b(1000000) as single

dim i as integer

for i=0 to 999999

a(i)=b(i)

next i

a=b '直接賦值,夠簡單吧

必須注意的是,這裡作為目的陣列的a不能為固定陣列(即在宣告時就指定了大小的陣列),否則會引發錯誤。

8樓:

想要快速的複製陣列麼?那就快用api函式copymemory吧。。。

哈哈,不好意思,做廣告了。那麼廢話少說,原始碼:

private declare sub copymemory lib "kernel32" alias "rtlmovememory" (destination as any, source as any, byval length as long)

private sub command1_click()dim a(10), b() as integerdim i as integer

for i = 0 to 10

a(i) = i

next

redim b(ubound(a))

copymemory byval varptr(b(0)), byval varptr(a(0)), lenb(a(0)) * 11

for i = 0 to 10

print b(i)

next

end sub

不再使用迴圈複製陣列了,真的很慢很麻煩。

9樓:5庸置疑

dim a1,a2

a1=array(1,2,3,4,5,6)a2=a1即可!

10樓:匿名使用者

dim a(1000000) as singledim b(1000000) as singledim c(1000000) as singledim i%

if a(i)<>b(i) then

c(i)=a(i)

a(i)=b(i)

end if

vb乙個包含10個陣列元素的陣列a,該陣列分別賦值2.4.6.8........20輸出

vb字串取出放入陣列中

11樓:

dim myarray() as stringdim str1 as string

str1="02 03 04 05 06 07 08 09 10 11 12 13..."

myarray=split(str1," ")for i=0 to ubound(myarray())debug.print myarray(i)next

12樓:匿名使用者

option explicit

private sub command1_click()dim a as variant

dim i as integer

a = split(text1.text, " ")end sub

vb 陣列中依次提取單個數值

13樓:激舞傳奇

根據題意(判斷乙個數是不是2的倍數,也就是判斷乙個數是不是奇數和偶數),有如下**:

private sub form_load()

text1.text = "52,65,43,76,13" '初始化文字框字串

end sub

private sub command1_click()

dim numarr

dim i as integer

numarr = split(text1.text, ",")

for i = 0 to ubound(numarr)

if val(numarr(i)) mod 2 = 0 then

msgbox numarr(i) & "是偶數"

else

msgbox numarr(i) & "是奇數"

end if

next

end sub

判斷偶數的個數關鍵是要定義乙個計數器變數(這裡為「k」),然後在迴圈中進行疊加,具體**如下:

private sub command1_click()

dim numarr

dim i as integer, k as integer

k = 0

numarr = split(text1.text, ",")

for i = 0 to ubound(numarr)

if val(numarr(i)) mod 2 = 0 then k = k + 1

next

msgbox "偶數的個數為:" & k

end sub

vb怎樣求陣列元素個數

以語句dim a 3 2 to 2 5 為例 option base 1 private sub form click dim i as integer,j as integer,k as integer dim count as long dim a 3,2 to 2,5 as integer f...

vb中陣列的定義是什麼,VB中陣列的定義是什麼

dim a 10 as integer dim b 3 to 5 as string 3 宣告了b是陣列名 字串型 一維陣列 有9個元素,下標的範圍是 3 5,每個元素最多存放3個字 dim c 1 to 5,4 as long 宣告了c是陣列名 長整型 二維陣列 第一維下標範圍為 1 5,第二維下...

VB中如何計算數值陣列中各元素值之和

option explicit option base 1 private sub form activate dim a 5 sum as integer,i as integer a 1 1 a 2 2 a 3 3 a 4 4 a 5 5 for i 1 to 5 sum sum a i nex...

VB求陣列裡的素數,VB 如何在一串陣列中算出素數個數

private sub command1 click dim i as integer,num as integerdim a 100 as integer,b 100 as integer,yes as boolean num 0 print 原來的數是 for k 1 to 100 a k in...

vb陣列定義與賦值,vb怎麼定義字串陣列?怎麼賦值?

dim cnt1 as variant cnt1 array 1600,0,0,0,0 array 函式 返回乙個包含陣列的 variant。語法array arglist 所需的 arglist 引數是乙個用逗號隔開的值表,這些值用於給 variant 所包含的陣列的各元素賦值。如果不提供引數,則...