Public Shared Function TextoAleatorio(Optional ByVal largoMinimo As Int16 = 1, Optional ByVal largoMaximo As Int16 = Int16.MaxValue) As String
Dim i As Integer
Dim largo As Integer = NumeroAleatorio(largoMaximo, largoMinimo)
Dim strTemp As New StringBuilder(largo)
For i = 0 To largo - 1
strTemp.Append(Chr(NumeroAleatorio(maximo:=90, minimo:=65)))
Next
Return strTemp.ToString()
End Function
Public Shared Function NumeroAleatorio(Optional ByVal maximo As Integer = Integer.MaxValue, Optional ByVal minimo As Integer = Integer.MinValue) As Integer
Dim r As New Random(lastintegervalue)
If minimo > maximo Then
Dim t As Integer = minimo
minimo = maximo
maximo = t
End If
lastintegervalue = r.Next(minimo, maximo)
Return lastintegervalue
End Function
Public Shared Function DecimalAleatorio(Optional ByVal maximo As Decimal = Decimal.MaxValue, Optional ByVal minimo As Decimal = Decimal.MinValue) As Decimal
Dim r As New Random()
If minimo > maximo Then
Dim t As Decimal = minimo
minimo = maximo
maximo = t
End If
lastdecimalvalue = (r.NextDouble() * (maximo - minimo)) + minimo
Return lastdecimalvalue
'create unhandled exception handler
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf ucLinker_UnhandledExceptionHandler
'event handler
Private Sub uc_UnhandledExceptionHandler(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs)
Dim ex As Exception = DirectCast(e.ExceptionObject, Exception)
Dim sb As New System.Text.StringBuilder()
sb.AppendLine("************** Exception Text **************")
sb.Append(ex.GetType.ToString)
sb.Append(": ")
sb.AppendLine(ex.Message)
sb.Append(ex.StackTrace)
Console.WriteLine(sb.ToString)
End Sub
On Error GoTo E
Dim openit As New OpenFileDialog
openit.ShowDialog()
Dim readit As New System.IO.StreamReader(openit.FileName)
RichTextBox1.Text = readit.ReadToEnd
readit.Close()
Exit sub
E:
End sub
Module RevString
Sub Main()
Dim inputString As String = Console.ReadLine()
ReverseOrder(inputString)
End Sub
Private Sub ReverseOrder(ByVal textInput As String)
Dim text2Rev As String = textInput
Dim reversed As String
Dim charArray() As Char = textInput.ToCharArray()
Array.Reverse(charArray)
reversed = charArray
Console.WriteLine("")
Console.WriteLine("Original Text: " + text2Rev)
Console.WriteLine("Reversed Text: " + reversed)
End Sub
End Module
Public Class ERROR_LOGGING
Public Shared Sub writeError(ByVal sPathName As String, ByVal sErrMsg As String)
Dim LogFormat As String = DateTime.Now.ToShortDateString & " " & DateTime.Now.ToLongTimeString & " ==> "
Dim year As String = DateTime.Now.Year.ToString
Dim month As String = DateTime.Now.Month.ToString
Dim day As String = DateTime.Now.Day.ToString
Dim ErrorTime As String = month + "_" + day + "_" + year
Dim fileName As String = sPathName + ErrorTime + ".log" 'Server.MapPath("TestMsg.txt")
IO.File.AppendAllText(fileName, LogFormat + sErrMsg + ControlChars.NewLine + ControlChars.NewLine)
End Sub
End Class
' Example on its usage I use it in the global.asx file
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs
Try
ERROR_LOGGING.writeError(Server.MapPath("~/Logs/ErrorLog/"), Server.GetLastError.Message + Server.GetLastError.InnerException.ToString)
Response.Redirect("~/security/index.aspx")
Catch ex As Exception
End Try
End Sub
VB.NET Códigoejemploparamostrarinformaciónnenun Repeater desde BD
Dim adaptadorNoticias As New DSContenidosTableAdapters.NoticiasTableAdapter
Dim noticias As New DSContenidos.NoticiasDataTable
Dim conversion As New ContenidosWeb
Dim tablaDatos As New DataTable("Articulos")
Dim datos As New DataSet()
Dim fila As DataRow
' Inicializo la estructura que mostrará las noticias en las páginas
tablaDatos.Columns.Add(New DataColumn("Fecha"))
tablaDatos.Columns.Add(New DataColumn("Titulo"))
tablaDatos.Columns.Add(New DataColumn("Id"))
datos.Tables.Add(tablaDatos)
' Obtengo las noticias a incluir en el tablón de anuncios
noticias = adaptadorNoticias.ListadoNoticiasPorSeccion(205)
' Las incluyo en el DataSet
For i As Integer = 0 To noticias.Count - 1
fila = datos.Tables("Articulos").NewRow
fila("Id") = noticias.Item(i).id
fila("Titulo") = conversion.ConversionAHTML(noticias.Item(i).Titulo)
fila("Fecha") = noticias.Item(i).FechaPublicacion.Day & "/" & noticias.Item(i).FechaPublicacion.Month & "/" & _
noticias.Item(i).FechaPublicacion.Year
datos.Tables("Articulos").Rows.Add(fila)
Next
' Vinculo el DataSet con el objeto Repeater de la página
Repeticion.DataSource = tablaDatos
Me.DataBind()
adaptadorNoticias.Dispose()
Function Base64ToImage(ByVal base64string As String) As System.Drawing.Image
'Setup image and get data stream together
Dim img As System.Drawing.Image
Dim MS As System.IO.MemoryStream = New System.IO.MemoryStream
Dim b64 As String = base64string.Replace(" ", "+")
Dim b() As Byte
'Converts the base64 encoded msg to image data
b = Convert.FromBase64String(b64)
MS = New System.IO.MemoryStream(b)
'creates image
img = System.Drawing.Image.FromStream(MS)
Return img
End Function
Protected Overrides Sub ChargeImpresoras()
Dim lPrintDoc As New Printing.PrintDocument
Dim lPrinter As Object
For Each lPrinter In PrinterSettings.InstalledPrinters
cboPrinters.Items.Add(lPrinter)
Next
End Sub