Results 1 to 5 of 5

Thread: hi, converting to JAVA

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    5

    hi, converting to JAVA

    Right, I have to convert the following code to JAVA but am havnig some trouble understanding the basic concepts!

    VERSION 5.00
    Begin VB.Form Form1
    Caption = "Form1"
    ClientHeight = 4575
    ClientLeft = 60
    ClientTop = 450
    ClientWidth = 4680
    LinkTopic = "Form1"
    ScaleHeight = 4575
    ScaleWidth = 4680
    StartUpPosition = 3 'Windows Default
    Begin VB.CommandButton Command1
    Caption = "Start"
    Height = 495
    Left = 600
    TabIndex = 0
    Top = 240
    Width = 1095
    End
    End
    Attribute VB_Name = "Form1"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = False
    ' areas program - Mike Parr 20/feb/06
    Option Explicit
    Dim shapeType As String 'global: used by more than one procedure
    '---------------------------------------------------

    Private Sub Command1_Click()
    Dim another As String

    another = InputBox("Want to calculate an area? (y/n)")
    While another = "y"
    Call getShape
    If shapeType = "t" Then
    Call areaTriangle
    ElseIf shapeType = "r" Then
    Call areaRectangle
    End If
    another = InputBox("Want to calculate another area? (y/n)")
    Wend
    MsgBox ("End of Program")
    End Sub
    '---------------------------------------------------

    'getShape: ask the user what type of shape, and check it
    Private Sub getShape()
    shapeType = InputBox("Area: type r for rectangle, t for triangle")
    While (shapeType <> "t") And (shapeType <> "r")
    shapeType = InputBox("Try again: type r for rectangle, t for triangle")
    Wend
    End Sub
    '-------------------------------------------------

    ' areaRectangle: get rectangle size, calculate area
    Private Sub areaRectangle()
    Dim area As Double
    Dim itsHeight As Double
    Dim itsWidth As Double
    itsWidth = getNumberInRange("Enter height of rectangle", 0.1, 100)
    itsHeight = getNumberInRange("Enter width of rectangle", 0.1, 100)
    area = itsWidth * itsHeight
    MsgBox "Area of rectangle is " & area

    End Sub
    '---------------------------------------------------


    'areaTriangle: get triangle size, calculate area
    Private Sub areaTriangle()
    Dim itsBase As Double ' only used in 1 proc, hence local is ok
    Dim itsHeight As Double
    Dim area As Double

    itsBase = getNumberInRange("Enter base of triangle", 0.1, 100)
    itsHeight = getNumberInRange("Enter height of triangle", 0.1, 100)
    area = 0.5 * itsBase * itsHeight
    MsgBox "Area of triangle is " & area
    End Sub
    '--------------------------------------------------

    'getNumberInRange: give it a prompt, and double items for max and min
    Private Function getNumberInRange(ByVal prompt As String, ByVal minInput As Double, _
    ByVal maxInput As Double) As Double
    Dim number As Double
    Dim fullPrompt As String

    fullPrompt = prompt & " (range " & minInput & " to " & maxInput & " )"
    number = getNumber(fullPrompt)
    While (number < minInput) Or (number > maxInput)
    number = getNumber("Range!! " & fullPrompt) '(
    Wend
    getNumberInRange = number ' pass result back to caller
    End Function
    '----------------------------------------------------

    'getNumber: gets number, ignoring range
    Private Function getNumber(ByVal fullPrompt As String) As Double
    Dim s As String

    s = InputBox(fullPrompt)
    While Not IsNumeric(s)
    s = InputBox(fullPrompt)
    Wend
    getNumber = s 'return it to caller
    End Function
    '----------------------------------------------------




    now obviously I am not asking someone to do this for me but some help in the right direction would be awesome!!!

    cheers

    T

  2. #2
    Fanatic Member
    Join Date
    Sep 2000
    Posts
    770

    Re: hi, converting to JAVA

    The right direction would be to google.com, because that's what everyone else is going to tell you to do.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    5

    Re: hi, converting to JAVA

    well i'm searching on there too


    was it too much to ask for a little advice?

  4. #4
    Fanatic Member
    Join Date
    Sep 2000
    Posts
    770

    Re: hi, converting to JAVA

    Well, that is the best advice IMO.

    http://java.sun.com/developer/onlineTraining/new2java/

    That should have everything you need to get your IDE setup and start coding.
    Last edited by nkad; Apr 24th, 2006 at 06:34 AM.

  5. #5
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: hi, converting to JAVA

    I would not expect anyone to be able to convert non-trivial VB code to Java code nor vice-versa unless they were an expert in both VB and Java...

    Are you an expert in either?
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width