Note that there are some explanatory texts on larger screens.

plurals
  1. POconvert java class to vb 2008 application
    text
    copied!<p>I wrote a Java class that parses a bpel text file and then returns a count of the number of occurences of certain words. I wanted to convert it to VB2008 Forms application, so that its results are displayed in a TextBox and not on the console. The problem is that VB2008 lacks Scanner and StringTokenizer classes, which are in my current Java class. Am not sure how to get the same functionality (or better) in VB2008. Can someone out there help to convert this class. Thank you. </p> <p>The Java class is as follows:</p> <pre><code>import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; import java.util.StringTokenizer; public class StringParser { private int ctrlFlowStructures; private String filePath; private ArrayList&lt;String&gt; activities; final String[] ctrlFlowsArray={"sequence","if","while","repeatUntil","forEach", "pick","flow"}; public StringParser(String path) { filePath=path; ctrlFlowStructures =0; activities=new ArrayList&lt;String&gt;(); } //count number of occurences of words in ctrlFlowStructureArray public int countCtrlFlowStructures () { Scanner input=null; StringTokenizer st; String line=null; String openingComment="!--"; String closingComment="--"; int c=0; try { input=new Scanner( new FileInputStream(filePath)); } catch(FileNotFoundException e) { System.out.println("Problem opening files."); System.exit(0); } while(input.hasNextLine()) { line=input.nextLine(); line.trim(); st= new StringTokenizer(line, " &lt;,&gt;\"",false); String temp=null; while (st.hasMoreTokens()) { temp=st.nextToken(); //eliminate comments if(temp.equals(openingComment)||temp.equalsIgnoreCase("documentation")) { c=1; } if(temp.equals(closingComment)||temp.equalsIgnoreCase("/documentation")) { c=2; } if(c==0||c==2) { for(int i=0;i&lt; ctrlFlowsArray.length;i++) if(temp.equalsIgnoreCase(ctrlFlowsArray [i])) { ctrlFlowStructures ++; } } } } input.close(); return ctrlFlowStructures; } //display control flow structures public void display() { int openingComment=0; //number of occurrence of an activity for(int i=0;i&lt; ctrlFlowsArray.length;i++) { for (int j=0;j&lt;activities.size();j++) { if(ctrlFlowsArray [i].equalsIgnoreCase(activities.get(j))) { openingComment++; } } if(openingComment&gt;0) { System.out.println(ctrlFlowsArray [i]+" = "+openingComment); openingComment=0; } } } public static void main(String[] args) { StringParser sp=new StringParser("c:\\MyFile1.bpel"); int a = sp.countCtrlFlowStructures(); System.out.println(" The number of control-flow structure(s) = " + a); } } </code></pre> <p>And this is the code snippet of the MyFile1.bpel file that was parsed:</p> <pre><code> &lt;sequence&gt; &lt;documentation&gt; The sequence includes several activities which are executed in lexical order. &lt;/documentation&gt; &lt;receive name="start" partnerLink="MyProcess" operation="operation1" portType="ns1:portType1" variable="inputVar" createInstance="yes"&gt; &lt;documentation&gt; The Receive activity makes the process to wait for the incoming message to arrive. &lt;/documentation&gt; &lt;/receive&gt; &lt;assign name="Assign1"&gt; &lt;documentation&gt; The Assign activity copies data from the input variable to the output variable. &lt;/documentation&gt; &lt;copy&gt; &lt;from&gt;$inputVar.inputType/ns2:paramA&lt;/from&gt; &lt;to&gt;$outputVar.resultType/ns2:paramA&lt;/to&gt; &lt;/copy&gt; &lt;/assign&gt; &lt;reply name="end" partnerLink="MyProcess" operation="operation1" portType="ns1:portType1" variable="outputVar"&gt; &lt;documentation&gt; The Reply activity returns a message from the process to the partner which initiated the communication. &lt;/documentation&gt; &lt;/reply&gt; &lt;/sequence&gt; </code></pre> <p></p> <p>Result: </p> <pre><code>The number of control-flow structure(s) = 1. </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload