Pieces of Java code need to be converted

samuel_1991

Member
Joined
Jan 19, 2009
Messages
13
Programming Experience
Beginner
Hi every1, I have tried to find the internet that a Java to VB.net convertor is not available (At least they are paid products which I do not have the $ to do it. I am a student)


Now, I have roughly thought that in Java and need to use it in VB.Net (PDA), how should I do it?

I do have Table_Number as an arrayList that can dynamically saved (add / remove) table number conditon because mine is a restaurant order taking system where customer seats and leaves the table after the meal.

The code I want to convert is about checking if the table number entered by a waiter / waitress is some table that is currently occupied by someone (Therefore it is wrong)

VB.NET:
for (int i = 0; i < Table_Number.size(); i++)
{
  if (Table_Number(i) == txttbNo)
   {
[COLOR="Lime"]'This is comment. the txttbNo is a variable declared in VB.Net that equates to txtTableNo.text (A textbox with a name txtTableNo)[/COLOR]
   System.out.println("Sorry, the seat is occupied by another customer");
   }
}


Also another question , sorry, how do I add an arrayList with multiple values in VB.Net?

(Say like customer 1 may order dish 1, 3 qty, dish 5 , 2 qty only while customer 2 may order dish 4, 2 qty only whereas customer 3 may order dish 6 , 1 qty only. All of these are variables that can varies a lot. Supposing there are 10 dishes offered by restaurant.)
Thanks in advance.
 
Last edited:
The java code would look something like this:
VB.NET:
For i As Integer = 0I To Table_Number.size - 1I
  If Table_Number(i) = txttbNo Then
    Console.WriteLine("Sorry, the seat is occupied by another customer")
    'For a GUI app:
    Messagebox.Show("Sorry, the seat is occupied by another customer")
  End If
Next i
I don't know if it's 100% correct, I haven't tested it.

As for adding a multivalued item to an arraylist, there's several ways to do it, the most simplest way to do it (that I can think of) would be to make a couple of classes, one for dish and quantity and another for customers, the customers class would need to have a list (of your dish class) for storing the dish(es) and quantity(ies) then you can have 2nd list (of your customer class) to hold the customers, no need for an actual arraylist.
 
Answered. Thank You!! :)

Thank you JuggaloBrotha, IT WORKS!!
The java code would look something like this:
VB.NET:
For i As Integer = 0I To Table_Number.size - 1I
  If Table_Number(i) = txttbNo Then
    Console.WriteLine("Sorry, the seat is occupied by another customer")
    'For a GUI app:
    Messagebox.Show("Sorry, the seat is occupied by another customer")
  End If
Next i
I don't know if it's 100% correct, I haven't tested it.

As for adding a multivalued item to an arraylist, there's several ways to do it, the most simplest way to do it (that I can think of) would be to make a couple of classes, one for dish and quantity and another for customers, the customers class would need to have a list (of your dish class) for storing the dish(es) and quantity(ies) then you can have 2nd list (of your customer class) to hold the customers, no need for an actual arraylist.

However, I have to pinpoint 2 things. First, the code you have provided works like charm for 99.99999999%. The other small fraction is only that it should be
VB.NET:
For i As Integer = 0I To Table_Number.[I]count[/I] - 1I

Secondly, as mentioned previously, is the meaning of couple of classes = couple of .vb or many public class like one shown:
VB.NET:
Public Class FormName
'Enter various codes for various controls
End Class
Public class Dishes
'Enter various codes for various controls
End Class
Public class Qty
'Enter various codes for various controls
End Class
within the same .vb?
 
Last edited:
Thank you JuggaloBrotha, IT WORKS!!

However, I have to pinpoint 2 things. First, the code you have provided works like charm for 99.99999999%. The other small fraction is only that it should be
VB.NET:
For i As Integer = 0I To Table_Number.[I]count[/I] - 1I

Secondly, as mentioned previously, is the meaning of couple of classes = couple of .vb or many public class like one shown:
VB.NET:
Public Class FormName
'Enter various codes for various controls
End Class
Public class Dishes
'Enter various codes for various controls
End Class
Public class Qty
'Enter various codes for various controls
End Class
within the same .vb?
That's pretty good considering I had no idea what Table_Number was, so I didn't change the size property because that could have broken the code and the whole thing wouldn't have worked.

You can have multiple classes defined in a single *.vb file, I do that all the time when I have several small classes for various things.

All I did was point out the structure of storing collections of information like that, I don't know what's best for your case because I don't know what all the requirements are.
 
That's pretty good considering I had no idea what Table_Number was, so I didn't change the size property because that could have broken the code and the whole thing wouldn't have worked.

You can have multiple classes defined in a single *.vb file, I do that all the time when I have several small classes for various things.

All I did was point out the structure of storing collections of information like that, I don't know what's best for your case because I don't know what all the requirements are.

Thanks any and the Table_NumberI mentioned is an arrayList.

Regarding multiple classes in a single .vb, I will try and post it out. Afterall I am the one doing my school assignment, therefore I should know my requirments the best.
 
You can put classes anywhere you want as long as it helps you organize things. Using nested classes usually mean there is a strong dependency with the parent class, the nested class can be both private and public. Multiple classes can be put in same class file, one after the other, but you would usually only do this for small, strongly related classes, for example EventArgs classes. If you need to edit them at the same time it helps organization to put one class in each one class file. Also when you visit a project later or review someone elses projects it helps the overview to see the class tree in Solution Explorer, instead of having to browse or use Object Browser to see where is what.
 
Back
Top