Migrando para o VB.NET parte 3

 

Tipo

VB 6

VB.NET

DoEvents

DoEvents

System.Windows.Forms.Application.DoEvents

Instância da aplicação

App.hInstance

System.Runtime.InteropServices.Marshal.GetHINSTANCE _(System.Reflection.Assembly.GetExecutingAssembly.GetModules() _(0)).ToInt32()

Carregar Imagem

Picture1.Picture = LoadPicture(path)

Dim img As Image = Image.FromFile(path)
Picture1.Image = img

Carregar um ícone

Me.Icon = LoadPicture(path)

Dim ico As New Icon(path)
Me.Icon = ico

App Object

App.Path & App.EXEName

System.Reflection.Assembly.GetExecutingAssembly.Location.ToString

Ler a partir de um arquivo

Open path For Input As #1
Line Input #1, buffer
Close #1

Dim fs As FileStream = File.Open(path, FileMode.OpenOrCreate, _ FileAccess.Read)
Dim sr As New StreamReader(fs)
Buffer = sr.ReadLine
sr.Close

Escrever para um arquivo

Open path For Output As #1
Write #1, buffer
Close #1

Dim fs As FileStream = File.Open(path, FileMode.OpenOrCreate, _
FileAccess.Write)
Dim sr As New StreamWriter(fs)
sr.Write(buffer)
sr.Close

Propriedades

Private valor As String
Public Property Get Teste() As Variant
    nome = valor
End Property

Public Property Let Teste(ByVal vNewValue As Variant)
    Set valorNome = vNewValue
End Property

Public Property teste()

   Get

       teste = valor

     End Get

     Set(ByVal Value)

       valor = Value

      End Set

End Property

 

Verificar instância anterior

App.PrevInstance

Function PrevInstance() As Boolean
If Ubound(Diagnostics.Process.GetProcessesByName_
    (Diagnostics.Process.GetCurrentProcess).ProcessName)) > 0 Then
     Return True
Else
    Return False
End If
End Sub

Declaração de Classes

Uma nova classe fica em um arquivo separado que usa a extensão .cls  se  identifica pelo arquivo.  Ex: Nome.cls

No visual Basic .NET a classe é identificada pela declaração

Class... End Class

O código fica em arquivos com a extensão .vb. Ex: Nome.vb

 

Uso e Criação de Interfaces

Interface Icliente
   Property Cliente() As String
End Interface

Public Class Clientes
   Implements ICliente
    ....
End Class

Public Interface UmaInterface
  Function WhoAmI() As String
End Interface

Public Class AClass
  Implements UmaInterface
   ....
End Class