VB判定多個變數互不相等,vb 判斷兩個變數相等

2022-04-01 03:15:16 字數 3547 閱讀 2422

1樓:

dim a(70) as integer

dim i, j as integer

dim flag as balloon

flag = false

for i = 0 to 69

for j = 1 to 69

if a(i) = a(j) and i<>j thenflag = true

exit for

end if

next

if flag = true then

exit for

end if

next

拜託樓主,我可以是一個msgbox也沒有彈出來啊。我的演算法是,如果遇到一次不等,則跳出迴圈,直接去下面的程式,麻煩樓主仔細看看。

2樓:悠悠周郎

for i = 0 to 69

if intx(i) = intx(i+1)msgbox("有相等的數值。")

exit sub

end if

3樓:官琦

1樓的演算法不對

用1維陣列排序的演算法去做對了

關於提問者的補充:

很多人給的答案都不錯了

是你自己應用能力太差了

你可以定義一個比爾變數

allsame as boolean =false '預設互不相等初值

用上面的longfei503演算法去判斷

把msgbox的地方allsame=true '發現有相等的值了最後在根據

if allsame then

'有相同

else

'不相同在這裡作業

end if

4樓:匿名使用者

dim i,j

for i=0 to 68

for j=i+1 to 69

if a(i)<>a(j) then 你的下一步next

next

5樓:匿名使用者

三樓演算法也不是最佳演算法.原因是複雜了.我將其修改後如下:

dim a(70) as integer

dim i, j as integer

for i = 0 to 68

for j = i+1 to 69

if a(i) = a(j) then

msgbox("有相等的數值")

exit sub

end if

next j

next i

vb 判斷兩個變數相等

6樓:

private sub command1_click()a1 = 1

t1 = 1

a = 1                       '這裡有問題了,每次這個全域性變數都重新被賦值了,還有結果a不是永遠是1,而是永遠是2,解決辦法,把這句移到呼叫過程或函式前邊

if a1 = t1 then

a = a + 1

end if

msgbox a1, , "a1"

msgbox a, , "a"

end sub

為什麼我的執行沒有問題?

執行的結果是:

第一個資訊框:a1=1

第二個資訊框:a=2

沒有問題啊

7樓:匿名使用者

a1 = 1

t1=1

a = 1 '這裡有問題了,每次這個全域性變數都重新被賦值了,還有結果a不是永遠是1,而是永遠是2,解決辦法,把這句移到呼叫過程或函式前邊

if a1 = t1 then

a = a + 1

end if

msgbox a1, , "a1"

msgbox a, , "a"

8樓:

如果用靜態區域性變數可以解決問題。

我是c++的

9樓:匿名使用者

你上面的**不是原本的**吧,這個**中a並不永遠是1,在a=a+1後a的值是2。

這段**並沒有把問題點顯示出來。

附件中是將你的原**儲存成vbs指令碼(壓縮),執行的結果a是2。

vb中如何判斷一個變數是否同時滿足兩個條件? 如 判斷 a 是否 小於等於b 大於等於c!

10樓:匿名使用者

你好..

vb中不等號是<>

例:變數a不等於10

if a<>10 then

'此處寫條件達成時執行的**

end if

11樓:

if a <= b and a>=c then msgbox"true"

相當於c裡面的邏輯與,只不過basic更解釋性一些

12樓:

a<=b && a>=c

13樓:

vb中的話是

if a <= b and a>=c then msgbox"true"

如果是c中的話是

if(a<=b&&a>=x)

14樓:沙慧月

if a <= b and a>=c then msgbox"true"

15樓:sk傷

if a>=b and b>=c then

else

endif

16樓:匿名使用者

if ( a<=b&& b>=c) then.......

vb 三組數中如何判斷那一個與其它兩個數值不等

17樓:匿名使用者

這個邏輯不難吧,就是有些繁瑣。假設3個值儲存到變數:a,b,c,結果儲存到 r

if a=b then

if a<>c then r=c

else

if a=c then

r=belse

r=aend if

end if

vb 如何判斷兩個數 是否相等

18樓:_儒雅的

if int(text1.text)>int(text2.text) then

text3.text ="大數是:" & text1.textelse

text3.text ="大數是:" & text2.textend if

19樓:匿名使用者

可以if s = 2 then

...else

...end if

20樓:小弟慕名而來

if s=2 then

是可以判斷的

判斷後是執行then語句

21樓:匿名使用者

如果按照你的寫法,s的資料型別必須為數值型

vb有多個frame,每個frame有多個optionbut

把你所有的optionbutton複製成控制元件組。然後在 option1 mouseup 事件中新增以下 for i 0 to option1.uboundoption1 i value falseif i index then option1 i value true next 把所有的opti...

vb中步長為變數怎麼算,VB裡的步長是什麼意思

這個是關鍵,a為5,a為4,b為12,a為2這個關鍵是step一次定值 a 1b 10 fori 1 to10 step 2a a 1 b b 1 i i 1 next i第1次迴圈結束,i 為7fori 8to10step 2a a 1 b b 1 i i 1 next i第3次迴圈結束,以後每次...

自己編的matlab函式如何輸出多個變數的數字結果

m,n好像是a,b的函式呀。結果當然是一個表示式 a,b 命令視窗輸入 x,y located a,b 裡面a,b值由你自己定。要把因變數都打出來,不然預設第一個因變數。 沫沫容 function dataout dataread filein,fileout,line fidin fopen fi...