Foros del Web » Programación para mayores de 30 ;) » .NET »

Traduccion de C# a Visual Basic .Net

Estas en el tema de Traduccion de C# a Visual Basic .Net en el foro de .NET en Foros del Web. hola he encontrado una clase de ejemplo bastante buena que sirve para imprimir tickets, mmmmmm bastante util obiamente para el que quiere imprimir tickets, jajajajaja ...
  #1 (permalink)  
Antiguo 29/06/2007, 15:21
 
Fecha de Ingreso: marzo-2006
Mensajes: 202
Antigüedad: 18 años, 1 mes
Puntos: 2
Mensaje Traduccion de C# a Visual Basic .Net

hola he encontrado una clase de ejemplo bastante buena que sirve para imprimir tickets, mmmmmm bastante util obiamente para el que quiere imprimir tickets, jajajajaja queria ver si me hechaban una manito con la traduccion para poder implementarla en visual el link original donde se encunetra la informacion es:
http://www.foromsn.com/index2.php?Ver=Mensaje&Id=178209

la clase en c# esta en :
http://mig16.cep.la/Ticket.cs

Y LA HE TRADUCIDO CASI TODA PERO AUN TENGO PROBLEMAS CON ALGUNAS COSAS ACA ESTA LO QUE HE TRADUCIDO:

Imports System
Imports System.Drawing
Imports System.Drawing.Printing
Imports System.Collections
Namespace BarControls



Public Class Ticket

Private headerLines As ArrayList = New ArrayList

Private subHeaderLines As ArrayList = New ArrayList

Private items As ArrayList = New ArrayList

Private totales As ArrayList = New ArrayList

Private footerLines As ArrayList = New ArrayList

Private headerImage As Image = Nothing

Private count As Integer = 0

Private maxChar As Integer = 35

Private maxCharDescription As Integer = 20

Private imageHeight As Integer = 0

Private leftMargin As Single = 0

Private topMargin As Single = 3

Private fontName As String = "Lucida Console"

Private fontSize As Integer = 9

Private printFont As Font = Nothing

Private myBrush As SolidBrush = New SolidBrush(Color.Black)

Private gfx As Graphics = Nothing

Private line As String = Nothing

Public Sub New()
MyBase.New()

End Sub

Public Property HeaderImage() As Image
Get
Return HeaderImage
End Get
Set(ByVal value As Image)
If (headerImage <> value) Then
headerImage = value
End If
End Set
End Property

Public Property MaxChar() As Integer
Get
Return MaxChar
End Get
Set(ByVal value As Integer)
If (value <> maxChar) Then
maxChar = value
End If
End Set
End Property

Public Property MaxCharDescription() As Integer
Get
Return MaxCharDescription
End Get
Set(ByVal value As Integer)
If (value <> maxCharDescription) Then
maxCharDescription = value
End If
End Set
End Property

Public Property FontSize() As Integer
Get
Return FontSize
End Get
Set(ByVal value As Integer)
If (value <> fontSize) Then
fontSize = value
End If
End Set
End Property

Public Property FontName() As String
Get
Return FontName
End Get
Set(ByVal value As String)
If (value <> fontName) Then
fontName = value
End If
End Set
End Property

Public Sub AddHeaderLine(ByVal line As String)
headerLines.Add(line)
End Sub

Public Sub AddSubHeaderLine(ByVal line As String)
subHeaderLines.Add(line)
End Sub

Public Sub AddItem(ByVal cantidad As String, ByVal item As String, ByVal price As String)
Dim newItem As OrderItem = New OrderItem(Microsoft.VisualBasic.ChrW(63))
items.Add(newItem.GenerateItem(cantidad, item, price))
End Sub

Public Sub AddTotal(ByVal name As String, ByVal price As String)
Dim newTotal As OrderTotal = New OrderTotal(Microsoft.VisualBasic.ChrW(63))
totales.Add(newTotal.GenerateTotal(name, price))
End Sub

Public Sub AddFooterLine(ByVal line As String)
footerLines.Add(line)
End Sub

Private Function AlignRightText(ByVal lenght As Integer) As String
Dim espacios As String = ""
Dim spaces As Integer = (maxChar - lenght)
Dim x As Integer = 0
Do While (x < spaces)
espacios = (espacios + " ")
x = (x + 1)
Loop
Return espacios
End Function

Private Function DottedLine() As String
Dim dotted As String = ""
Dim x As Integer = 0
Do While (x < maxChar)
dotted = (dotted + "=")
x = (x + 1)
Loop
Return dotted
End Function

Public Function PrinterExists(ByVal impresora As String) As Boolean
For Each strPrinter As String In PrinterSettings.InstalledPrinters
If (impresora = strPrinter) Then
Return True
End If
Next
Return False
End Function

Public Sub PrintTicket(ByVal impresora As String)
printFont = New Font(fontName, fontSize, FontStyle.Regular)
Dim pr As PrintDocument = New PrintDocument
pr.PrinterSettings.PrinterName = impresora
AddHandler pr.PrintPage, AddressOf Me.pr_PrintPage
pr.Print()
End Sub
  #2 (permalink)  
Antiguo 29/06/2007, 15:22
 
Fecha de Ingreso: marzo-2006
Mensajes: 202
Antigüedad: 18 años, 1 mes
Puntos: 2
Re: Traduccion de C# a Visual Basic .Net

continua:

Private Sub pr_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
e.Graphics.PageUnit = GraphicsUnit.Millimeter
gfx = e.Graphics
DrawImage()
DrawHeader()
DrawSubHeader()
DrawItems()
DrawTotales()
DrawFooter()
If (Not (headerImage) Is Nothing) Then
headerImage.Dispose()
headerImage.Dispose()
End If
End Sub

Private Function YPosition() As Single
Return (topMargin _
+ ((count * printFont.GetHeight(gfx)) _
+ imageHeight))
End Function

Private Sub DrawImage()
If (Not (headerImage) Is Nothing) Then
Try
gfx.DrawImage(headerImage, New Point(CType(leftMargin, Integer), CType(YPosition(), Integer)))
Dim height As Double = ((CType(headerImage.Height, Double) / 58) _
* 15)
imageHeight = (CType(Math.Round(height), Integer) + 3)
Catch As Exception

End Try
End If
End Sub

Private Sub DrawHeader()
For Each header As String In headerLines
If (header.Length > maxChar) Then
Dim currentChar As Integer = 0
Dim headerLenght As Integer = header.Length

While (headerLenght > maxChar)
line = header.Substring(currentChar, maxChar)
gfx.DrawString(line, printFont, myBrush, leftMargin, YPosition, New StringFormat)
count = (count + 1)
currentChar = (currentChar + maxChar)
headerLenght = (headerLenght - maxChar)

End While
line = header
gfx.DrawString(line.Substring(currentChar, (line.Length - currentChar)), printFont, myBrush, leftMargin, YPosition, New StringFormat)
count = (count + 1)
Else
line = header
gfx.DrawString(line, printFont, myBrush, leftMargin, YPosition, New StringFormat)
count = (count + 1)
End If
Next
DrawEspacio()
End Sub

Private Sub DrawSubHeader()
For Each subHeader As String In subHeaderLines
If (subHeader.Length > maxChar) Then
Dim currentChar As Integer = 0
Dim subHeaderLenght As Integer = subHeader.Length

While (subHeaderLenght > maxChar)
line = subHeader
gfx.DrawString(line.Substring(currentChar, maxChar), printFont, myBrush, leftMargin, YPosition, New StringFormat)
count = (count + 1)
currentChar = (currentChar + maxChar)
subHeaderLenght = (subHeaderLenght - maxChar)

End While
line = subHeader
gfx.DrawString(line.Substring(currentChar, (line.Length - currentChar)), printFont, myBrush, leftMargin, YPosition, New StringFormat)
count = (count + 1)
Else
line = subHeader
gfx.DrawString(line, printFont, myBrush, leftMargin, YPosition, New StringFormat)
count = (count + 1)
line = DottedLine()
gfx.DrawString(line, printFont, myBrush, leftMargin, YPosition, New StringFormat)
count = (count + 1)
End If
Next
DrawEspacio()
End Sub

Private Sub DrawItems()
Dim ordIt As OrderItem = New OrderItem(Microsoft.VisualBasic.ChrW(63))
gfx.DrawString("CANT DESCRIPCION IMPORTE", printFont, myBrush, leftMargin, YPosition, New StringFormat)
count = (count + 1)
DrawEspacio()
For Each item As String In items
line = ordIt.GetItemCantidad(item)
gfx.DrawString(line, printFont, myBrush, leftMargin, YPosition, New StringFormat)
line = ordIt.GetItemPrice(item)
line = (AlignRightText(line.Length) + line)
gfx.DrawString(line, printFont, myBrush, leftMargin, YPosition, New StringFormat)
Dim name As String = ordIt.GetItemName(item)
leftMargin = 0
If (name.Length > maxCharDescription) Then
Dim currentChar As Integer = 0
Dim itemLenght As Integer = name.Length

While (itemLenght > maxCharDescription)
line = ordIt.GetItemName(item)
gfx.DrawString((" " + line.Substring(currentChar, maxCharDescription)), printFont, myBrush, leftMargin, YPosition, New StringFormat)
count = (count + 1)
currentChar = (currentChar + maxCharDescription)
itemLenght = (itemLenght - maxCharDescription)

End While
line = ordIt.GetItemName(item)
gfx.DrawString((" " + line.Substring(currentChar, (line.Length - currentChar))), printFont, myBrush, leftMargin, YPosition, New StringFormat)
count = (count + 1)
Else
gfx.DrawString((" " + ordIt.GetItemName(item)), printFont, myBrush, leftMargin, YPosition, New StringFormat)
count = (count + 1)
End If
Next
leftMargin = 0
DrawEspacio()
line = DottedLine()
gfx.DrawString(line, printFont, myBrush, leftMargin, YPosition, New StringFormat)
count = (count + 1)
DrawEspacio()
End Sub

Private Sub DrawTotales()
Dim ordTot As OrderTotal = New OrderTotal(Microsoft.VisualBasic.ChrW(63))
For Each total As String In totales
line = ordTot.GetTotalCantidad(total)
line = (AlignRightText(line.Length) + line)
gfx.DrawString(line, printFont, myBrush, leftMargin, YPosition, New StringFormat)
leftMargin = 0
line = (" " + ordTot.GetTotalName(total))
gfx.DrawString(line, printFont, myBrush, leftMargin, YPosition, New StringFormat)
count = (count + 1)
Next
leftMargin = 0
DrawEspacio()
DrawEspacio()
End Sub

Private Sub DrawFooter()
For Each footer As String In footerLines
If (footer.Length > maxChar) Then
Dim currentChar As Integer = 0
Dim footerLenght As Integer = footer.Length

While (footerLenght > maxChar)
line = footer
gfx.DrawString(line.Substring(currentChar, maxChar), printFont, myBrush, leftMargin, YPosition, New StringFormat)
count = (count + 1)
currentChar = (currentChar + maxChar)
footerLenght = (footerLenght - maxChar)

End While
line = footer
gfx.DrawString(line.Substring(currentChar, (line.Length - currentChar)), printFont, myBrush, leftMargin, YPosition, New StringFormat)
count = (count + 1)
Else
line = footer
gfx.DrawString(line, printFont, myBrush, leftMargin, YPosition, New StringFormat)
count = (count + 1)
End If
Next
leftMargin = 0
DrawEspacio()
End Sub

Private Sub DrawEspacio()
line = ""
gfx.DrawString(line, printFont, myBrush, leftMargin, YPosition, New StringFormat)
count = (count + 1)
End Sub
End Class

Public Class OrderItem

Private delimitador() As Char = New Char() {Microsoft.VisualBasic.ChrW(63)}

Public Sub New(ByVal delimit As Char)
MyBase.New()
delimitador = New Char() {delimit}
End Sub

Public Function GetItemCantidad(ByVal orderItem As String) As String
Dim delimitado() As String = orderItem.Split(delimitador)
Return delimitado(0)
End Function
  #3 (permalink)  
Antiguo 29/06/2007, 15:23
 
Fecha de Ingreso: marzo-2006
Mensajes: 202
Antigüedad: 18 años, 1 mes
Puntos: 2
Re: Traduccion de C# a Visual Basic .Net

y por ultimo

Public Function GetItemName(ByVal orderItem As String) As String
Dim delimitado() As String = orderItem.Split(delimitador)
Return delimitado(1)
End Function

Public Function GetItemPrice(ByVal orderItem As String) As String
Dim delimitado() As String = orderItem.Split(delimitador)
Return delimitado(2)
End Function

Public Function GenerateItem(ByVal cantidad As String, ByVal itemName As String, ByVal price As String) As String
Return (cantidad _
+ (delimitador(0) _
+ (itemName _
+ (delimitador(0) + price))))
End Function
End Class

Public Class OrderTotal

Private delimitador() As Char = New Char() {Microsoft.VisualBasic.ChrW(63)}

Public Sub New(ByVal delimit As Char)
MyBase.New()
delimitador = New Char() {delimit}
End Sub

Public Function GetTotalName(ByVal totalItem As String) As String
Dim delimitado() As String = totalItem.Split(delimitador)
Return delimitado(0)
End Function

Public Function GetTotalCantidad(ByVal totalItem As String) As String
Dim delimitado() As String = totalItem.Split(delimitador)
Return delimitado(1)
End Function

Public Function GenerateTotal(ByVal totalName As String, ByVal price As String) As String
Return (totalName _
+ (delimitador(0) + price))
End Function
End Class
End Namespace


AHORA UNA MANITO PORFIS ES DE UTILIDAD PUBLICA A CUALQUIERA LE PUEDE SERVIR....SORRY POR TANTA INFO PERO NO CABIA EN UN SOLO POST...
  #4 (permalink)  
Antiguo 01/07/2007, 00:36
Avatar de RootK
Moderador
 
Fecha de Ingreso: febrero-2002
Ubicación: México D.F
Mensajes: 8.004
Antigüedad: 22 años, 2 meses
Puntos: 50
Re: Traduccion de C# a Visual Basic .Net

en las faq´s está colocada una liga para traducir de vb.net a c# y viceversa, y otro cosa, si no vas a hacer modificaciones puedes ocupar la .dll que viene en la página y la agregas a tu proyecto

Salu2
__________________
Nadie roba nada ya que en la vida todo se paga . . .

Exentrit - Soluciones SharePoint & Net
  #5 (permalink)  
Antiguo 03/07/2007, 07:20
 
Fecha de Ingreso: marzo-2006
Mensajes: 202
Antigüedad: 18 años, 1 mes
Puntos: 2
Re: Traduccion de C# a Visual Basic .Net

TU Dices en: Choose toolbox items-->COM components-->browse o en add a Reference??? me podrias explpicar un poco mas???
  #6 (permalink)  
Antiguo 03/07/2007, 08:02
Avatar de moNTeZIon  
Fecha de Ingreso: enero-2005
Ubicación: Lliçà de Munt - BCN
Mensajes: 1.625
Antigüedad: 19 años, 4 meses
Puntos: 9
Re: Traduccion de C# a Visual Basic .Net

Para agregar referencias:

Botón derecho sobre el proyecto > Agregar referencia... > Examinar > Buscar la DLL en tu HD.

__________________
..:: moNTeZIon ::..
  #7 (permalink)  
Antiguo 03/07/2007, 09:05
 
Fecha de Ingreso: marzo-2006
Mensajes: 202
Antigüedad: 18 años, 1 mes
Puntos: 2
Re: Traduccion de C# a Visual Basic .Net

ya lo he hecho muchas veses incluso segui el consejo de root de buscar el traductor de codigo de c a visual y cree nuevamente la clase pero ni aun asi puedo instanciar un nuevo objeto?? que hago mal??
  #8 (permalink)  
Antiguo 04/07/2007, 01:38
Avatar de moNTeZIon  
Fecha de Ingreso: enero-2005
Ubicación: Lliçà de Munt - BCN
Mensajes: 1.625
Antigüedad: 19 años, 4 meses
Puntos: 9
Re: Traduccion de C# a Visual Basic .Net

No puede ser que te falte agregar algún namespace o algo así??
__________________
..:: moNTeZIon ::..
  #9 (permalink)  
Antiguo 04/07/2007, 07:31
 
Fecha de Ingreso: marzo-2006
Mensajes: 202
Antigüedad: 18 años, 1 mes
Puntos: 2
Re: Traduccion de C# a Visual Basic .Net

ahi me pillaste. nose si le falte algo, me podrias ayudar? gracias men de todas formas
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 03:09.