Jump to content

Recommended Posts

Posted

Estou com um problema a escrever num .txt

No inicio o numero é "0", é um integer.

Ao fim disto:

   Sub maisnumero()
    Using numeronew As New System.IO.StreamReader(numeroPath, False)
	    numero = numeronew.Read
	    numero = numero + 1
    End Using
    Using morenumero As New StreamWriter(numeroPath, False)
	    morenumero.WriteLine(numero)
	    ToolStripLabel1.Text = "Número de Pautas: " & numero
    End Using
   End Sub

numero é igual a 65534, a minha dúvida é: como isto é possive?

Learning

  • VB.Net
  • HTML
  • C/C++

Posted (edited)

olá boa tarde.

Assim :

Sub maisnumero()
		Using numeronew As New System.IO.StreamReader(numeroPath, False)
				numero = numeronew.Read
				numero += 1
		End Using
		Using morenumero As New StreamWriter(numeroPath, False)
				morenumero.WriteLine(numero)
				ToolStripLabel1.Text = "Número de Pautas: " & numero
		End Using
End Sub
Edited by programadorvb6

______________________________________________________________________________

Que minha coragem seja maior que meu medo e que minha força seja tão grande quanto minha fé.
 

Posted

De acordo com a documentação o método Read lê apenas um caracter, retornado como um Int32 e retorna -1, se atingires o fim do stream. O que precisas de usar é o método ReadLine para obter a linha como string e depois usas Convert.ToInt32(string) para converter para um Int32.

Posted
    Using numeronew As New System.IO.StreamReader(numeroPath, False)
	    Dim inputnumero As String
	    inputnumero = numeronew.ReadLine
	    numero = Convert.ToInt32(inputnumero)
	    numero += numero
    End Using
    Using morenumero As New StreamWriter(numeroPath, False)
	    morenumero.WriteLine(numero)
	    ToolStripLabel1.Text = "Número de Pautas: " & numero
    End Using

    Using numeronew As New System.IO.StreamReader(numeroPath, False)
	    Dim inputnumero As String
	    inputnumero = numeronew.ReadLine
	    numero = Convert.ToInt32(inputnumero)
	    numero += numero
    End Using
    Using morenumero As New StreamWriter(numeroPath, False)
	    morenumero.WriteLine(numero)
	    ToolStripLabel1.Text = "Número de Pautas: " & numero
    End Using

Learning

  • VB.Net
  • HTML
  • C/C++

Posted

Já consegui, mudei o encoding

e o Código

   Sub maisnumero()
    Using numeronew As New System.IO.StreamReader(numeroPath, False)
	    Dim inputnumero As String
	    inputnumero = numeronew.ReadLine
	    numero = Convert.ToInt32(inputnumero)
	    numero = numero + 1
    End Using
    Using morenumero As New StreamWriter(numeroPath, False)
	    morenumero.WriteLine(numero)
	    ToolStripLabel1.Text = "Número de Pautas: " & numero
    End Using
   End Sub

Learning

  • VB.Net
  • HTML
  • C/C++

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.