VB迴圈搜尋的問題,VB 一個迴圈搜尋的問題

2022-12-18 02:26:23 字數 1271 閱讀 5936

1樓:砍侃看

'本程式是用right 和 left 兩個函式對字串進行操'作。先取字串長存在num中,再從後往前依次取倒數'第1、2、3...直到第num個字串,並在取完後對字元'穿首字元進行判斷,如果是a則得到a在整個串中的倒'數位置並存於i中,再用整串的長相減便得所需結果

sub commond_click()

dim str as string,nowstr as stringdim num as integer,i as integer,lastanum as integer

str="要操作的字串"

num=len(str)

for i=1 to num

nowstr=right(str,i) '取右邊i個字串if left(nowstr,1)=="a" thenlastanum=num-i+1

msgbox lastanum,vbinformation '訊息框顯示a的位置

exit for 』如果找到推出迴圈

end if

next i

end sub

2樓:匿名使用者

不用迴圈

private sub command1_click()s$ = "dadfdsa1fdafjfkdafdsaaadfdsasdf"

msgbox instrrev(s, "a")end sub

非要用迴圈就這樣

private sub command1_click()s$ = "dadfdsa1fdafjfkdafdsaaadfdsasdf"

for i& = len(s) to 1 step -1if mid$(s, i, 1) = "a" then exit for

next

msgbox i

end sub

3樓:

sub findlasta()

dim i as integer

dim lasta as integer

lasta = len(s)

do while mid$(s, lasta, 1) <> "a"

lasta = lasta - 1

if lasta = 0 then msgbox "no a founded.": goto 10

loop

msgbox lasta

10 end sub

4樓:匿名使用者

不就是找最後的a嗎?幹嘛用迴圈啊,用instrrev函式

VB的問題,一個VB的問題

以下 只需要按command1就可以同時顯示text1和text2了 option explicit option base 1 private sub command1 click dim a 15 as integer dim i as integer text1.text for i 1 to...

vb的問題,vb的一個問題

private sub form queryunload cancel as integer,unloadmode as integer 點選右上角的關閉 dim a as integer a msgbox 確認關閉嗎?vbokcancel vbquestion,系統提示 if a vbok the...

VB基礎問題,VB一個基礎問題

private sub command1 click static i as integer dim a a array 小1 王2 小3 李4 太5 多6 了7 不8 寫9 了10 label1.caption a i if i 9 then i i 1end sub private sub co...