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

crear abrir aleatorio

Estas en el tema de crear abrir aleatorio en el foro de Programación General en Foros del Web. Creación del archivo Imports System.IO Public Class CrearArchivo Shared Sub main() Dim intConteo, intCuantos As Integer Try Console.WriteLine("Indica el nombre del archivo y su ubicación: ...
  #1 (permalink)  
Antiguo 07/02/2007, 12:46
 
Fecha de Ingreso: febrero-2007
Mensajes: 2
Antigüedad: 17 años, 2 meses
Puntos: 0
crera abrir aleatorio

Creación del archivo

Imports System.IO
Public Class CrearArchivo
Shared Sub main()
Dim intConteo, intCuantos As Integer
Try
Console.WriteLine("Indica el nombre del archivo y su ubicación:
")
Dim archivo As String
Dim objArchivo As TextWriter
archivo = Console.ReadLine
objArchivo = File.CreateText(archivo)
lineas:
Console.WriteLine("Cantidad de líneas del archivo: ")
intCuantos = Console.ReadLine()
Console.WriteLine()
Dim strElementos(intCuantos) As String ' declaracion del arreglo
Dim objResultado As TextWriter = Console.Out
Console.WriteLine("Escribe: {0} líneas <oprima intro despues de
cada una>", intCuantos)
For intConteo = 0 To intCuantos - 1
strElementos(intConteo) = Console.ReadLine
Next
Console.WriteLine()
Console.SetOut(objArchivo)
Console.WriteLine("-----<Líneas del archivo {0}>-----", archivo)
For intConteo = 0 To intCuantos
Console.WriteLine(UCase(strElementos(intConteo)))
Next
objArchivo.Close()
Console.SetOut(objResultado)
Console.WriteLine("***********Ha finalizado la creación del
archivo*************")
Console.ReadLine()
Catch e As Exception
Console.WriteLine(e.Message)
GoTo lineas
End Try
End Sub
End Class


LEctura del archivo

Public Class Archivo_a_leer
Public strlectorarchivo As System.IO.StreamReader

Shared Sub main()
Console.WriteLine() : Console.WriteLine()
Console.Write("Indica el nombre del archivo a leer debe terminar con
.txt: ")
strarchivo = Console.ReadLine()
If System.IO.File.Exists(strarchivo) = True Then
strlectorarchivo = System.IO.File.OpenText(strarchivo)
strlinealeida = "Algo"
Do Until strlinealeida Is Nothing
strlinealeida = strlectorarchivo.ReadLine()
intlineas += 1
Console.WriteLine(UCase(strlinealeida))
Loop
Console.WriteLine("El archivo contaba con {0} líneas", intlineas
- 2)
GoTo volver
Else
Console.WriteLine("El archivo {0} no existe", strarchivo)
volver:

Console.WriteLine("¿Proporcionar nuevamente el nombre del
archivo?:")
Dim otra As Char
otra = Console.ReadLine
If otra = "S" Or otra = "s" Then
Console.Clear()
Archivo_a_leer.main()
Else
Exit Sub
End If
End If
End Sub
End Class


Aleatorio

Public Class Adivina
Shared Sub Main()
Try
Dim intobj, intlimsup, intliminf, intpreg, intoport As Integer
Dim strentrada As String
Dim objAleatorio As System.Random = New System.Random()
Console.WriteLine("TECLEE EL NUMERO INFERIOR")
strentrada = Console.ReadLine
intliminf = CInt(strentrada)
Console.WriteLine("TECLEE NUMERO SUPERIOR")
strentrada = Console.ReadLine
intlimsup = CInt(strentrada)
intobj = objAleatorio.Next(intliminf, intlimsup + 1)
intpreg = 0 : intoport = 0
Do While intpreg <> intobj
Try
Console.WriteLine("ADIVINE EL NUMERO ALEATORIO")
strentrada = Console.ReadLine
intoport += 1
intpreg = strentrada
If intpreg < intobj Then Console.WriteLine("EL NUMERO ES
MAYOR")
If intpreg > intobj Then Console.WriteLine("EL NUMERO ES
MENOR")
Catch EXCEPTION2 As Exception
Console.WriteLine(EXCEPTION2.Message)
End Try
Loop
Console.WriteLine("LOGRO ADIVINAR {0} EN {1} APORTUNIDADES",
intobj, intoport)
Console.ReadLine()
Catch EXCEPTION As Exception
Console.WriteLine(EXCEPTION.Message)
End Try
End Sub

End Class
  #2 (permalink)  
Antiguo 07/02/2007, 12:49
 
Fecha de Ingreso: febrero-2007
Mensajes: 2
Antigüedad: 17 años, 2 meses
Puntos: 0
prac 1

Imports system.IO
Imports System


Public Class Adivina
Shared Sub main()

Try

Dim ObjArchivo As TextWriter ' = Console.Out
ObjArchivo = File.CreateText(My.Application.Info.DirectoryPath & "\Jugadores.txt")
Inicio:
Console.WriteLine("PROPORCIONE EL NOMBRE")
nombre = Console.ReadLine
Console.WriteLine("TECLEE EL NUMERO INFERIOR")
strentrada = Console.ReadLine
intliminf = CInt(strentrada)
Console.WriteLine("TECLEE NUMERO SUPERIOR")
strentrada = Console.ReadLine
inc = TimeOfDay
intlimsup = CInt(strentrada)
intobj = objAleatorio.Next(intliminf, intlimsup + 1)
intpreg = 0 : intoport = 0
Do While intpreg <> intobj
Try
Console.WriteLine("ADIVINE EL NUMERO ALEATORIO")
strentrada = Console.ReadLine
intoport += 1
intpreg = strentrada
If intpreg < intobj Then Console.WriteLine("EL NUMERO ES MAYOR QUE: {0}", intpreg)
If intpreg > intobj Then Console.WriteLine("EL NUMERO ES MENOR QUE: {0}", intpreg)
Catch EXCEPTION2 As Exception
Console.WriteLine(EXCEPTION2.Message)
End Try
Loop
fin = TimeOfDay
Console.WriteLine("******************************* ******************************************")
Console.WriteLine("EL PARTICIPANTE ES: {0}", nombre)
Console.WriteLine("COMENZO A LAS: {0}", inc)
Console.WriteLine("CONCLUYO A LAS: {0}", fin)
Console.WriteLine("EL NUMERO GENERADO FUE: {0} ENTRE {1} AL {2}", intobj, intliminf, intlimsup)
Console.WriteLine("LOGRO ADIVINAR EN: {0} OPORTUNIDADES", intoport)
ObjArchivo.WriteLine("**************************** *********************************************")
ObjArchivo.WriteLine("EL PARTICIPANTE ES: {0}", nombre)
ObjArchivo.WriteLine("COMENZO A LAS: {0}", inc)
ObjArchivo.WriteLine("CONCLUYO A LAS: {0}", fin)
ObjArchivo.WriteLine("EL NUMERO GENERADO FUE: {0} ENTRE {1} AL {2}", intobj, intliminf, intlimsup)
ObjArchivo.WriteLine("LOGRO ADIVINAR EN: {0} OPORTUNIDADES", intoport)
Nom(Contador) = nombre
Inten(Contador) = intoport
Contador += 1
Console.ReadLine()
Console.WriteLine()
Console.WriteLine("Deseas jugar de nuevo? Si=1 No=2 ")
Dec = Console.ReadLine()
If Dec = 1 Then
GoTo Inicio
End If
For I = 0 To Contador - 1
For J = 0 To Contador - 1
If Inten(I) < Inten(J) Then
Aux = Inten(J)
Inten(J) = Inten(I)
Inten(I) = Aux
aux2 = Nom(J)
Nom(J) = Nom(I)
Nom(I) = aux2
End If
Next
Next
Console.WriteLine()
Console.WriteLine("Los Mejores jugadores")
For I = 0 To 2
Console.WriteLine("{0} {1} OPORTUNIDADES", Nom(I), Inten(I))
Next
'Console.SetOut(Auxi)
ObjArchivo.Close()
Console.ReadLine()
Catch EXCEPTION As Exception
Console.WriteLine(EXCEPTION.Message)
Console.ReadLine()
End Try
End Sub
End Class
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 13:34.