Amigos estoy dando mis primeros pasos con VB .NET y me tope con la siguiente
parte de codigo:
<<<<<<< En C# >>>>>>>>
if (val <> null)
{
Statements..
}
Desearia saber cual es es el equivalente de la condicional en VB, yo hago lo
siguiente:
If val Is Not Nul Then... Es lo correcto?...porque tengo un problema con la
condicional, o no lo estoy empleando correctamnete, lo que pasa es que me
baje una aplicacion de ejemplo de Impresion de codigo de barras de la pagina
del Guille, esta esta en C# pero al covertirla en VB no me imprime el codigo
de Barras.
Coloco codigo con el que tengo problemas.
<<<<<<<<< Esto esta en C# y corre sin Problemas >>>>>>>>>
/// <summary>
/// Carga el ComboBox con las fuentes que se encuentran en la carpeta
Fonts.
/// </summary>
private void CargarListaFuentes()
{
try
{
DirectoryInfo dir = new DirectoryInfo( PATH_FONTS );
if(dir.Exists)
{
FileInfo[] file = dir.GetFiles();
//Si la carpeta existe recorremos su contenido en busca de Fuentes.
foreach( FileInfo fonts in file )
{
if(fonts.Extension == ".TTF")
{
cbListaFonts.Items.Add( fonts.Name );
}
}
//Seleccionamos por defecto una fuente.
cbListaFonts.SelectedIndex = 0;
}
}
catch( Exception ex)
{
MessageBox.Show( ex.Message);
}
}
/// <summary>
/// Carga del fichero la Fuente Pasada como parámetro.
/// </summary>
/// <param name="fuente">Fuente a Cargar del Archivo</param>
private void CargarFuente(string fuente)
{
PrivateFontCollection pfc = new PrivateFontCollection();
pfc.AddFontFile( PATH_FONTS + @"\" + fuente);
FontFamily fontFamily = pfc.Families[0];
_Font = new Font( fontFamily,30);
}
/// <summary>
/// Incluye al Código los * para que el lector lea correctamente el
Código.
/// </summary>
/// <param name="code">Código a Formatear.</param>
/// <returns>Código con los *</returns>
private string FormatBarCode(string code)
{
string barcode = string.Empty;
barcode = string.Format("*{0}*",code);
return barcode;
}
private void button1_Click(object sender, System.EventArgs e)
{
try
{
if( txtBarcode.Text == string.Empty)
lbBarCode.Text = "Tienes que introducir un Código";
else
{
if( _Font != null)
{
lbBarCode.Font= _Font;
lbBarCode.Text = FormatBarCode( txtBarcode.Text );
lbCode.Text = FormatBarCode( txtBarcode.Text );
}
}
}
catch(Exception ex)
{
MessageBox.Show( ex.Message);
}
}
<<<<<<<<< Esto esta en VB y no hace la impresion en el Label >>>>>>>>
Public Class Form1
'Variables
Private _Font As Font
Private PATH_FONTS As String
'Para cargar las fuentes del directorio en el combo de Fuentes
Private Sub CargarListaFuentes()
Try
'Dim dir As New DirectoryInfo(PATH_FONTS)
Dim dir As New DirectoryInfo("D:\Visual Studio
2005\Projects\CodigoBarras\CodigoBarras\Fonts")
If (dir.Exists) Then
Dim file As FileInfo()
file = dir.GetFiles()
'Si la carpeta esta llena corremos su contenido para cargar
fuentes
For Each Fonts As FileInfo In file
If (Fonts.Extension = ".TTF") Then
cbListaFonts.Items.Add(Fonts.Name)
End If
Next
'Seleccionamos por defecto una fuente
cbListaFonts.SelectedIndex = 0
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "RVC Soft®")
End Try
End Sub
Private Sub CargarFuente(ByVal fuente As String)
Dim pfc As New PrivateFontCollection()
pfc.AddFontFile(PATH_FONTS & fuente)
Dim FontFamilyBarCode As FontFamily
FontFamilyBarCode = pfc.Families(0)
_Font = New Font(FontFamilyBarCode, 30)
End Sub
Private Function formatbarcode(ByVal code As String) As String
Dim barcode As String = String.Empty
barcode = String.Format("*{0}*", code)
Return barcode
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
CargarListaFuentes()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
MessageBox.Show("Dentro al Evento Clic", "RVC Soft®")
Try
If (txtBarcode.Text = String.Empty) Then
lbBarCode.Text = "Tienes que introducir un Código"
Else
If (Not _Font Is Nothing) Then
MessageBox.Show("Dentra al Nothing", "RVC Soft®")
lbBarCode.Font = _Font
lbBarCode.Text = formatbarcode(txtBarcode.Text)
lbcode.Text = formatbarcode(txtBarcode.Text)
End If
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "RVC Soft®")
End Try
End Sub
End Class
Espero me ayuden.
Leer las respuestas