? asked in 電腦與網際網路程式設計 · 1 decade ago

這是java寫的程式要怎麼用VB寫阿!請幫幫我!拜託!

老師之前給我的程式要我用VB寫出來!!因為老師用的程式語言比較少人會!!這是之後我同學用Java寫出來的!!由於我VB並不是那麼好,寫出來的程式都被老師退回來!!我真的沒有辦法了,真的非常需要各位VB高手的幫助!幫助我把這Java寫出來的程式用VB寫出來!!拜託了!謝謝!

因有亂碼及字數上的限制!!所以我把程式列在補充資料上!!不好意思!!

// Obtain F, X, Omega and Omega minimal

import java.util.*;

public class OmegaMin{

List<int[]>F=new ArrayList<int[]>();

List<int[]>X=new ArrayList<int[]>();

List<int[]>Omega=new ArrayList<int[]>();

List<int[]>OmegaMin=new ArrayList<int[]>();

OmegaMin(int d){

int f1, f2, f3, f4, x1, x2, x3, x4;

// Find all feasible vector F

for(f1=0; f1>=0 && f1<=6; f1++){

for(f2=0; f2>=0 && f2<=6; f2++){

for(f3=0; f3>=0 && f3<=6; f3++){

for(f4=0; f4>=0 && f4<=6; f4++){

if(f1+f2+f3+f4==d && f1+f2+f3+f4<=6 && f1+f2+f4<=5 && f2+f3+f4<=6){

int arrayF[]={f1, f2, f3, f4};

this.F.add(arrayF);

}

}

}

}

}

// Obtain X from F

for(int i=0; i<this.F.size(); i++){

f1=this.F.get(i)[0];

f2=this.F.get(i)[1];

f3=this.F.get(i)[2];

f4=this.F.get(i)[3];

x1=f1+f2+f3+f4;

x2=f1+f2+f4;

x3=f2+f3+f4;

x4=f1+f2+f3+f4;

int arrayX[]={x1, x2, x3, x4};

this.X.add(arrayX);

}

// Filter all of X and find Omega

List<int[]>Omega=new ArrayList<int[]>(this.X);

for(int i=0; i<Omega.size(); i++){

for(int j=i+1; j<Omega.size(); j++){

if(Omega.get(i)[0]==Omega.get(j)[0] && Omega.get(i)[1]==Omega.get(j)[1] && Omega.get(i)[2]==Omega.get(j)[2] && Omega.get(i)[3]==Omega.get(j)[3]){

Omega.remove(j);

}

}

}

this.Omega=Omega;

// Find all of Omega minimal

List<int[]> OmegaMin=new ArrayList<int[]>(this.Omega);

for(int i=OmegaMin.size()-1; i>=0; i--){

for(int j=i+1; j<OmegaMin.size(); j++){

if(OmegaMin.get(i)[0] <OmegaMin.get(j)[0] || OmegaMin.get(i)[1] <OmegaMin.get(j)[1] || OmegaMin.get(i)[2] <OmegaMin.get(j)[2] || OmegaMin.get(i)[3] <OmegaMin.get(j)[3]){

if(OmegaMin.get(i)[0] >OmegaMin.get(j)[0] || OmegaMin.get(i)[1] >OmegaMin.get(j)[1] || OmegaMin.get(i)[2] >OmegaMin.get(j)[2] || OmegaMin.get(i)[3] >OmegaMin.get(j)[3]){

// do nothing (accept that the two Omega)

} else{

OmegaMin.remove(j);

}} else{

OmegaMin.remove(i);

}

}

}

this.OmegaMin=OmegaMin;

}

Update:

List<int[]> getF(){

return F;

}

List<int[]> getX(){

return X;

}

List<int[]> getOmega(){

return Omega;

}

List<int[]> getOmegaMin(){

return OmegaMin;

}

}

Update 2:

以上是我的程式內容!!請各位精通VB及Java的高手來幫幫我!!拜託了~~~

2 Answers

Rating
  • Favorite Answer

    看看這樣能不能過得了關吧XD

    (7年以上沒摸過VB了)

    -----------------------------------

    Dim d as Integer

    Dim o(5 * 6, 4) as Integer

    Dim len as Integer

    Dim minSum as Integer

    Dim repeat as Boolean

    Dim i as Integer

    Dim f1 as Integer, f2 as Integer, f3 as Integer, f4 as Integer

    Dim x1 as Integer, x2 as Integer, x3 as Integer, x4 as Integer, xsum as Integer

    ' Set your demand d

    d = 6

    'Initial

    len = 0

    minSum = -1

    For f1 = 0 To d

    For f2 = 0 To (d - f1)

    For f3 = 0 To (d - f1 - f2)

    f4 = d - f1 - f2 - f3

    x1 = f1 + f2 + f3 + f4

    x2 = f1 + f2 + f4

    x3 = f2 + f3 + f4

    x4 = f1 + f2 + f3 + f4

    If x1 <= 6 And x2 <= 5 And x3 <= 6 Then

    'To Print f for f1, f2, f3, f4

    'To Print x for x1, x2, x3, x4

    repeat = False

    If len > 0 Then

    For i = 0 To len - 1

    If o(i)(0) == x1 And o(i)(0) == x1 And o(i)(0) == x1 And o(i)(0) == x1 Then

    repeat = True;

    End If

    Next

    End If

    If repeat = False Then

    xsum = x1 + x2 + x3 + x4

    o(len)(0) = f1

    o(len)(1) = f2

    o(len)(2) = f3

    o(len)(3) = f4

    o(len)(4) = xsum

    len = len + 1

    'To Print omega for x1, x2, x3, x4

    If minSum < 0 And minSum > xsum Then

    minSum = xsum;

    End If

    End If

    End If

    Next

    Next

    Next

    If len > 0 Then

    For i = 0 To len - 1

    If o(i)(4) == minSum Then

    'To Print OmegaMin for o(i)(0), o(i)(1), o(i)(2), o(i)(3)

    End If

    Next

    End If

    2010-01-21 11:41:31 補充:

    To Print 的地方你要自己寫哦

    2010-01-21 11:42:40 補充:

    反正就是在 Form 上拉幾個 Lable, 然後組成字串加上去

    2010-01-21 11:44:24 補充:

    If o(i)(0) == x1 And o(i)(0) == x1 And o(i)(0) == x1 And o(i)(0) == x1 Then

    這行改成

    If o(i)(0) == x1 And o(i)(1) == x2 And o(i)(2) == x3 And o(i)(3) == x4 Then

    2010-01-22 09:05:28 補充:

    發現2層的陣列寫法全部用錯了XD

    像 o(len)(0) 之類的都要改成 o(len, 0)

    Source(s): ゆっくりしていってね!!!
  • Anonymous
    7 years ago

    我每次都是去這里看的哦, http://lvmiss.com/

    吐冖偵向

Still have questions? Get your answers by asking now.