Convert VB6 code to VB.NET

Trying to convert VB6 code to VB 2008 Express Edition.

Page 1 of 1

3 Replies - 6353 Views - Last Post: 14 July 2008 - 08:13 AM Rate Topic: -----

#1 edwardelric  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-July 08

Convert VB6 code to VB.NET

Posted 13 July 2008 - 01:51 PM

I was wondering if there is anyone who can convert this for me, I used VB6 in College but now as its not available I cant look at my program.

I hope someone can help thank you.

Option Explicit On
Dim sngAngle As Single
Dim sngH As Single
Dim sngX As Single
Dim sngY As Single
Dim intAttempts As Integer

Private Sub cmdGo_Click()
    If txtDistance = "" Then
        intAttempts = intAttempts
        MsgBox("Please enter a distance")
    Else
        intAttempts = intAttempts + 1
    End If
    If txtBearing = "" Then
        intAttempts = 0
        MsgBox("Please enter a bearing!")
    End If
    sngAngle = Val(txtBearing)
    sngAngle = sngAngle * 3.1415 / 180
    sngH = Val(txtDistance)
    sngX = sngH * Sin(sngAngle) / 10
    sngY = sngH * Cos(sngAngle) / 10
    imgHecilopter.Left = imgHecilopter.Left + sngH * Sin(sngAngle)
    imgHecilopter.Top = imgHecilopter.Top - sngH * Cos(sngAngle)
    lblAttempts = intAttempts
    If txtFuel = "0" Then
        MsgBox("Mission Failed")
        Timer1.Enabled = False
    End If
End Sub

Private Sub Exit_Click()
    If Confirm("Are you sure you want to exit?", "Exit") = vbYes Then
        End
    End If
End Sub

Private Sub Form_Load()
    imgInjured.Left = Int(Rnd * Frame4.Width)
    imgInjured.Top = Int(Rnd * Frame4.Height)
    Randomize()
End Sub

Private Sub NewGame_Click()
    If Confirm("Are you sure you want to start a new game?", "New Game") = vbYes Then
        Call Form_Load()
    End If
End Sub

Private Sub About_Click()
    frmAbout.Show()
End Sub

Private Sub Back_Click()
    If Confirm("Are you sure you want to exit?", "Exit") = vbYes Then
        frmMain.Show()
    End If
    Unload(Me)
End Sub

Private Function Confirm(ByVal strConfirm As String, ByVal strTitle As String) As Integer
    Confirm = MsgBox(strConfirm, vbYesNo, strTitle)
End Function

Private Sub Timer1_Timer()
    txtFuel = txtFuel - 1
End Sub


Mod edit: Please :code:
Thanks, gabehabe :)

Is This A Good Question/Topic? 0
  • +

Replies To: Convert VB6 code to VB.NET

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Convert VB6 code to VB.NET

Posted 13 July 2008 - 03:59 PM

Unfortunately no one will just convert this code for you, thats not what what we're here for at Dream.In.Code. We will, however, help you as you walk through the conversion process yourself :)
Was This Post Helpful? 0
  • +
  • -

#3 jacobjordan  Icon User is offline

  • class Me : Perfection
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,499
  • Joined: 11-June 08

Re: Convert VB6 code to VB.NET

Posted 13 July 2008 - 05:38 PM

Sorry to go against your philosophy Psycho, but it really wasn't that hard

    Dim sngAngle As Single
    Dim sngH As Single
    Dim sngX As Single
    Dim sngY As Single
    Dim intAttempts As Integer

    Private Sub cmdGo_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles cmdGo.Click
        If txtDistance = "" Then
            intAttempts = intAttempts
            MsgBox("Please enter a distance")
        Else
            intAttempts = intAttempts + 1
        End If
        If txtBearing = "" Then
            intAttempts = 0
            MsgBox("Please enter a bearing!")
        End If
        sngAngle = Val(txtBearing)
        sngAngle = sngAngle * 3.1415 / 180
        sngH = Val(txtDistance)
        sngX = sngH * Math.Sin(sngAngle) / 10
        sngY = sngH * Math.Cos(sngAngle) / 10
        imgHecilopter.Left = imgHecilopter.Left + sngH * Math.Sin(sngAngle)
        imgHecilopter.Top = imgHecilopter.Top - sngH * Math.Cos(sngAngle)
        lblAttempts = intAttempts
        If txtFuel = "0" Then
            MsgBox("Mission Failed")
            Timer1.Enabled = False
        End If
    End Sub

    Private Sub Exit_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles [Exit].Click
        If Confirm("Are you sure you want to exit?", "Exit") = vbYes Then
            End
        End If
    End Sub

    Private Sub Form_Load(ByVal sender As System.Object, ByVal e As EventArgs) Handles MyBase.Load
        imgInjured.Left = Int(Rnd() * Frame4.Width)
        imgInjured.Top = Int(Rnd() * Frame4.Height)
        Randomize()
    End Sub

    Private Sub NewGame_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles NewGame.Click
        If Confirm("Are you sure you want to start a new game?", "New Game") = vbYes Then
            Form_Load(Me, New EventArgs())
        End If
    End Sub

    Private Sub About_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles About.Click
        frmAbout.Show()
    End Sub

    Private Sub Back_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles Back.Click
        If Confirm("Are you sure you want to exit?", "Exit") = vbYes Then
            frmMain.Show()
        End If
        Me.Close()
    End Sub

    Private Function Confirm(ByVal strConfirm As String, ByVal strTitle As String) As Integer
        Confirm = MsgBox(strConfirm, vbYesNo, strTitle)
    End Function

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As EventArgs) Handles Timer1.Tick
        txtFuel -= 1
    End Sub


Also, you didn't explain some things, so you might need to edit this code a bit more.
Was This Post Helpful? 0
  • +
  • -

#4 edwardelric  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-July 08

Re: Convert VB6 code to VB.NET

Posted 14 July 2008 - 08:13 AM

Thanks for the help :) It seems to work ok and I see some of the places where I need to modify, hopefully I can make it as functional as it was before and update :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1