estica Posted January 6, 2016 at 12:39 AM Report Share #591459 Posted January 6, 2016 at 12:39 AM Boas pessoal, Uso o seguinte código para ler a info de um determinado ficheiro. Agora é assim... Com o código ele vai ler a lista completa. Por exemplo começando no offset 1 com intervalo de 10... O que eu queria era dar ordem para ele parar no offset 100 por exemplo. Using c As New System.IO.BinaryReader(System.IO.File.Open((fileDialogBox.FileName), System.IO.FileMode.Open)) For i As Long = 1 To c.BaseStream.Length - 1 Step 10 c.BaseStream.Seek(i, System.IO. SeekOrigin.Begin) Dim Temp As String = c.ReadUInt16 ListView1.Items(ItemCounter).SubItems(1).Text = Temp ItemCounter += 1 Next End Using Link to comment Share on other sites More sharing options...
He B TeMy Posted January 6, 2016 at 12:52 AM Report Share #591461 Posted January 6, 2016 at 12:52 AM (edited) Em vez de c.BaseStream.Length metes 100... ou eu não percebi a pergunta? Edited January 6, 2016 at 12:52 AM by He B TeMy 1 Report Link to comment Share on other sites More sharing options...
estica Posted January 6, 2016 at 01:08 AM Author Report Share #591463 Posted January 6, 2016 at 01:08 AM Ou seja, eu tenho um determinado ficheiro e estou a ler o hex para poder edita-lo. Se eu usar assim: For i As Long = 1 To c.BaseStream.Length - 1 Step 10 Vai carregar desde o offset "1" até ao fim com um intervalo de "10" E se eu usar assim For i As Long = 1 To 100 - 1 Step 10 Vai carregar uma lista começando no offset "1" até ao "100" com intervalo de "10" Link to comment Share on other sites More sharing options...
He B TeMy Posted January 6, 2016 at 01:45 AM Report Share #591465 Posted January 6, 2016 at 01:45 AM E qual é o problem outra vez? Link to comment Share on other sites More sharing options...
estica Posted January 6, 2016 at 01:50 AM Author Report Share #591466 Posted January 6, 2016 at 01:50 AM E qual é o problem outra vez? Nenhum... Estava me a certificar que tinha percebido... Obrigado Link to comment Share on other sites More sharing options...
He B TeMy Posted January 6, 2016 at 02:27 AM Report Share #591467 Posted January 6, 2016 at 02:27 AM (edited) Edit: Podes ligar na mesma a option strict, mas o que eu disse tava errado 😉 Edited January 6, 2016 at 02:16 PM by He B TeMy 1 Report Link to comment Share on other sites More sharing options...
ribeiro55 Posted January 6, 2016 at 10:18 AM Report Share #591474 Posted January 6, 2016 at 10:18 AM He B TeMy, O Option Strict não te vai chatear aqui. Qual o problema do For i As Long? Usas o datatype que tiveres de usar para a iteração... Até podes precisar de coisas mais estranhas, por exemplo: For i As Single = 0 To 100 Step 0.1F 'coisas Next Neste caso (o caso do poster original) o Long é apropriado porque: 1. Integer (32, signed) não é suficiente para iterar ficheiros com mais de 2147483647 bytes (aprx 2GB) 2. É o tipo de BaseStream.Length (por a mesma razão do 1) Sérgio Ribeiro "Great coders aren't born. They're compiled and released""Expert coders do not need a keyboard. They just throw magnets at the RAM chips" Link to comment Share on other sites More sharing options...
He B TeMy Posted January 6, 2016 at 02:15 PM Report Share #591482 Posted January 6, 2016 at 02:15 PM Ups, tens razão, normalmente no .net framework as propriedades .length são quase todas int que nem pensei. 1 Report Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now