-1

The files I am trying to read are in a file called systemstate in the bin\debug file. I have a text file call systemdetails in that file and a file in there called Products and a file of products called P0 containing the rest of the text files

in the following lines of code the first readalllines works, the rest fails without any exception raised and the program continues to run as if nothing happened.

in the form1.vb file

    Public Sub init()
    If start Then
        productcount = Int(IO.File.ReadAllLines(filestoreloc + systemfile)(0).Split()(1))
        For i As Integer = 0 To productcount
            Dim id As String = Str(i)

            Dim det As String() = IO.File.ReadAllLines(filestoreloc + Product.location + "P" + id + Product.detailsfile)
            Dim desc As String() = IO.File.ReadAllLines(filestoreloc + Product.location + "P" + id + Product.descriptionfile)
            Dim rev As String() = IO.File.ReadAllLines(filestoreloc + Product.location + "P" + id + Product.reviewfile)

            products.Add(New Product(det, desc, extractRecords(rev, Product.revstartmark, Product.revendmark)))
        Next
        start = False
    End If
End Sub

This method is invoked from the Form1_load method

these are the variables used in the above code:

in the form1.vb file

Property filestoreloc As String = "systemstate\"

Property systemfile As String = "systemdetails.txt"

Property productcount As Integer

Property start As Boolean = True

in the product.vb file

Public Shared Property location As String = "Products\"
Public Shared Property detailsfile As String = "\details.txt"
Public Shared Property descriptionfile As String = "\description.txt"
Public Shared Property reviewfile As String = "\reviews.txt"

Public Shared Property revstartmark As String = "[REVIEWSTART]"
Public Shared Property revendmark As String = "[REVIEWEND]"
adeel
  • 7
  • 4
  • What do you mean by "the rest fail"? If they aren't throwing exceptions, what do they do? Return a null or empty array? Skip out of the method without continuing? – Steven Doggart Oct 18 '17 at 14:27
  • @StevenDoggart when I get to the 1st failing readalllines in debug mode and I step over it the system stops debugging and the program is shown to be running – adeel Oct 18 '17 at 14:31
  • the product.add part which comes after all the reads does not even run – adeel Oct 18 '17 at 14:33
  • 1
    So it is probably throwing an exception, it's just catching it and eating it somewhere else. Try putting a Try/Catch block right around that one line of code and see if you can catch the exception and see what it is. – Steven Doggart Oct 18 '17 at 14:35
  • @StevenDoggart it says directory not found also I have now noticed when I convert 0 to a string it becomes space and then 0: " 0" – adeel Oct 18 '17 at 14:38
  • I Trimmed the string and now no exception is thrown. they all work thank you! also should I close the question now? – adeel Oct 18 '17 at 14:43
  • You could answer it yourself, or delete it, or leave it open. It's up to you :) – Steven Doggart Oct 18 '17 at 14:44
  • @StevenDoggart wait how do I get my program to throw exceptions properly – adeel Oct 18 '17 at 14:46
  • 1
    Exceptions thrown in Form Load are usually not caught due to a well known bug. Move your code to Form Shown or a button click – Ňɏssa Pøngjǣrdenlarp Oct 18 '17 at 14:47
  • @StevenDoggart okay thanks – adeel Oct 18 '17 at 14:50

1 Answers1

1

an exception was not showing up. this exception was because the directory couldn't be found because when I converted the id to a string there was a leading space @StevenDoggart helped me detect the exception

adeel
  • 7
  • 4