Results 1 to 7 of 7

Thread: Reading a single value?

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2020
    Posts
    34

    Reading a single value?

    Hi this code is used to read values from h592 to h595.
    How can i write code to read only value h592, not from h592 to h595?

    Code:
      Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim b() As Byte = IO.File.ReadAllBytes("ecu test1.bin")
        Label1.Text = ""
        For i As Integer = &H592 To &H595
          Label1.Text &= Chr(b(i))
        Next
      End Sub
    Last edited by Shaggy Hiker; Jul 7th, 2020 at 05:39 PM.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Reading a single value?

    Well, think about it for a bit. As you have it, you have a loop. It first sets i to &H592, and gets the value from the array at location i. It then sets i to &H593, and gets the value from the array at location i. i has increased by one, but it is still getting the value from the array at location i. It then sets i to &H594 and gets the value from the array at location i, and so on until it reaches &H595.

    So, if you want just one value. There's no need for a loop, just set i to the value you want.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2020
    Posts
    34

    Re: Reading a single value?

    I'm sorry but I really don't understand what am I supposed to do. I'm a beginner in VB, so if you can give me the edited code I would be very grateful!

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Reading a single value?

    No, I'm just not going to do that. You've actually got all the code you need in the example you already posted. That's what makes the question so frustrating. You must not understand what you posted, because it has the answer in it already, so where did you get that? If this is homework, you won't be learning anything. If it's not homework, then you need to start with the basics, because YOU gave the answer to your question, and yet you ask me for it.
    My usual boring signature: Nothing

  5. #5
    Lively Member
    Join Date
    Jan 2020
    Posts
    120

    Re: Reading a single value?

    Live Demo
    Module loops
    Sub Main()
    Dim a As Byte
    ' for loop execution
    For a = 10 To 20
    Console.WriteLine("value of a: {0}", a)
    Next
    Console.ReadLine()
    End Sub
    End Module

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Reading a single value?

    For the record, there's no such thing as h592. The VB representation of a hexadecimal literal SPECIFICALLY uses the &H prefix, so only &H592 is actually meaningful. C-based languages, e.g. C#, use the mathematical standard for representing hexadecimal numbers, so 0x592 is also meaningful.

  7. #7
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845

    Re: Reading a single value?

    Quote Originally Posted by vargaperformance View Post
    Hi this code is used to read values from h592 to h595.
    How can i write code to read only value h592, not from h592 to h595?

    Code:
      Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim b() As Byte = IO.File.ReadAllBytes("ecu test1.bin")
        Label1.Text = ""
        For i As Integer = &H592 To &H595
          Label1.Text &= Chr(b(i))
        Next
      End Sub
    Interesting this code, it is passel's one... as an answer to the same question you asked in an other thread of yours.... http://www.vbforums.com/showthread.p...=1#post5485953
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width