Jump to content

Translating a Visual Basic program to Java

- - - - -

  • Please log in to reply
4 replies to this topic

#1
bloodchains

bloodchains

    Learning Programmer

  • Members
  • PipPipPip
  • 73 posts
I have to translate a program written in Visual Basic into Java for my school test because I'm not really knowledgeable in VB. My questions are:

  • Does Java have a "Single" type? The program declares a couple of variables as Single. I'm not familiar with the Single type is.
  • Is using ArrayList in Java the same as changing the size of an array in VB with ReDim?
I think I have more questions, but I can't think of them right now. Maybe it's better if I just show a part of the code in the VB program so you know what I'm looking at.

#Region "Declarations"

    Const _default_capacity As Integer = 16
    Const _default_growth_factor As Single = 1.25
    Private _growth_factor As Single
    Private _count As Integer
    Private _arr() As Object
#End Region

#Region "Constructors"

    Public Sub New(Optional ByVal new_capacity As Integer = _default_capacity, Optional ByVal new_growth_factor As Single = _default_growth_factor)
        ReDim _arr(new_capacity - 1)
        _count = 0
        If new_growth_factor <= 1.0 Then
            new_growth_factor = _default_growth_factor
        End If
        _growth_factor = new_growth_factor
    End Sub

    Public Sub New(ByVal other As CArray)
        ReDim _arr(other._arr.GetUpperBound(0))
        _growth_factor = other._growth_factor
        _count = other._count

        For index As Integer = 0 To _count - 1
            _arr(index) = other._arr(index)
        Next
    End Sub

#End Region


#2
Sinipull

Sinipull

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 386 posts
Single appears to be floating point type in Visual Basic. It's less precise than double. Should use float or double in java.
(People have got to learn to Google.)

ArrayList in Java is a dynamic type which changes it's size automatically if needed, and hides that logic from the user.
It declares bigger array and copies the objects from old array to new bigger array, if the old one starts to fill up.
.

#3
bloodchains

bloodchains

    Learning Programmer

  • Members
  • PipPipPip
  • 73 posts
Thanks. And yes, I did try to Google the single type. I was trying to find about it in Java, and didn't really find something about Java that says something about Single. I was thinking of using Double, but I wanted to ask someone from Codecall. Why would Codecall exist in the first place if all they answered is, "Google it"?

#4
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Judging by the little code your"class" in VB has, it looks like you were writing your own ArrayList in vb.

#5
bloodchains

bloodchains

    Learning Programmer

  • Members
  • PipPipPip
  • 73 posts
Yes, that's what I was thinking. I don't know if my professor wanted me to do this in Java, or if it's not needed at all.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users