Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Studio
  4. Keep getting error message when trying to run this bit of code

Keep getting error message when trying to run this bit of code

Scheduled Pinned Locked Moved Visual Studio
helpquestionlounge
2 Posts 2 Posters 12 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 13982471
    wrote on last edited by
    #1

    I don't know what is wrong with this code. Keep getting error messages as follows: bc30026 End sub expected bc30289 Statement cannot appear within a method body. End of method assumed. bc42024 unused local variable: 'position'. bc42109 Variable 'temp' is used before it has been assigned a value. any help would be appreciated. Thanks

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim position As Integer
    
    Structure person
        Dim id As Integer
        Dim name As String
        Dim surname As String
    End Structure
    
    Private Function FindLastRecordNo()
        Dim temp As person, FileNumber As Integer
    
        FileNumber = FreeFile()
    
        FileOpen(FileNumber, TextBox1.Text, OpenMode.Random, \_OpenAccess.Read,, Len(temp))
        FindLastRecordNo = 1
    
        Do While Not EOF(FileNumber)
            FileGet(FileNumber, temp, )
            FindLastRecordNo = FindLastRecordNo + 1
        Loop
    
        FileClose(FileNumber)
    End Function
    
    
    End Sub
    
    V 1 Reply Last reply
    0
    • M Member 13982471

      I don't know what is wrong with this code. Keep getting error messages as follows: bc30026 End sub expected bc30289 Statement cannot appear within a method body. End of method assumed. bc42024 unused local variable: 'position'. bc42109 Variable 'temp' is used before it has been assigned a value. any help would be appreciated. Thanks

      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

          Dim position As Integer
      
      Structure person
          Dim id As Integer
          Dim name As String
          Dim surname As String
      End Structure
      
      Private Function FindLastRecordNo()
          Dim temp As person, FileNumber As Integer
      
          FileNumber = FreeFile()
      
          FileOpen(FileNumber, TextBox1.Text, OpenMode.Random, \_OpenAccess.Read,, Len(temp))
          FindLastRecordNo = 1
      
          Do While Not EOF(FileNumber)
              FileGet(FileNumber, temp, )
              FindLastRecordNo = FindLastRecordNo + 1
          Loop
      
          FileClose(FileNumber)
      End Function
      
      
      End Sub
      
      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      [Statement cannot appear within a method body | Microsoft Docs](https://docs.microsoft.com/en-us/dotnet/visual-basic/misc/bc30289) ['End Sub' expected | Microsoft Docs](https://docs.microsoft.com/en-us/dotnet/visual-basic/misc/bc30026)... ... Or do you avoid reading the docs?

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups