Hi guys,
I can't figure it out where I am doing wrong. I keep getting FileNotFoundException saying that "Could not find file 'C:\delete\band3_tao.img'." but this file was writen to a file in previous step. I have attached the code I have written.

I need your help.

Thanks.

Here is the code:

Imports System
Imports System.IO
Public Class formMain
 Private Sub FormMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click

        If txtBoxAtmTrans.Text.Length = 0 Or txtBoxBandMin3.Text.Length = 0  Then
            MessageBox.Show("Please do not leave textboxes blank!", "Warning!")
            Me.btnOk.Focus()
        Else

            'STEP 1: This precedure reads band3.img as input, and outputs band3_toa.img
            Dim s5 As FileStream 'Load file 1
            Dim s6 As FileStream 'Save output

            'If System.IO.File.Exists("C:\delete\band3_toa.img") Then
            '    System.IO.File.Delete("C:\delete\band3_toa.img")
            'End If

            '---read from and write to a binary file
            s5 = New FileStream("C:\delete\band3.img", FileMode.Open, FileAccess.Read)
            s6 = New FileStream("C:\delete\band3_toa.img", FileMode.CreateNew, FileAccess.Write)

            Dim br3 As BinaryReader
            Dim bw3 As BinaryWriter

            br3 = New BinaryReader(s5)
            bw3 = New BinaryWriter(s6)

            Dim fLen3 As Integer
            Dim f3 As New System.IO.FileInfo("C:\delete\band3.img")
            fLen3 = f3.Length

            Dim snglRead3 As Single
            Dim snglOutput3 As Single 'wıll hold results from division

            Dim n As Integer


            Dim LMax As Single
            Dim LMin As Single
            Dim QCalMax As Single
            Dim QCalMin As Single
            Dim BandMin As Single

            LMax = CSng(txtBoxLMax3.Text)
            LMin = CSng(txtBoxLMin3.Text)
            QCalMax = CSng(txtBoxQMax3.Text)
            QCalMin = CSng(txtBoxQMin3.Text)
            BandMin = CSng(txtBoxBandMin3.Text)

            'Read binary file1 and fill the array with pixel values 
            For n = 0 To fLen3 - 1
                snglRead3 = br3.ReadByte
                'If snglRead1 >= BandMin Then
                '    snglRead1 = snglRead1 - BandMin
                'Else
                '    snglRead1 = BandMin
                'End If
                snglOutput3 = ((LMax - LMin) / (QCalMax - QCalMin)) * ((snglRead3 - BandMin) - QCalMin) + LMin
                bw3.Write(snglOutput3)
            Next

            s5.Close()
            s6.Close()
        End If
        MessageBox.Show("STEP 1 DONE", "Success!")

        'STEP 2: This precedure reads band4.img and outputs band4_toa.img

        Dim s7 As FileStream 'Load file 1
        Dim s8 As FileStream 'Save output

        'If System.IO.File.Exists("C:\delete\band4_toa.img") Then
        '    System.IO.File.Delete("C:\delete\band4_toa.img")
        'End If

        '---read from and write to a binary file
        s7 = New FileStream("C:\delete\band4.img", FileMode.Open, FileAccess.Read)
        s8 = New FileStream("C:\delete\band4_toa.img", FileMode.CreateNew, FileAccess.Write)

        Dim br4 As BinaryReader
        Dim bw4 As BinaryWriter

        br4 = New BinaryReader(s7)
        bw4 = New BinaryWriter(s8)

        Dim fLen4 As Integer
        Dim f4 As New System.IO.FileInfo("C:\delete\band4.img")
        fLen4 = f4.Length

        Dim snglRead4 As Single
        Dim snglOutput4 As Single 'wıll hold results from division

        Dim c As Integer


        Dim LMax2 As Single
        Dim LMin2 As Single
        Dim QCalMax2 As Single
        Dim QCalMin2 As Single
        Dim BandMin2 As Single

        LMax2 = CSng(txtBoxLMax4.Text)
        LMin2 = CSng(txtBoxLMin4.Text)
        QCalMax2 = CSng(txtBoxQMax4.Text)
        QCalMin2 = CSng(txtBoxQMin4.Text)
        BandMin2 = CSng(txtBoxBandMin4.Text)

        'Read binary file1 and fill the array with pixel values 
        For c = 0 To fLen4 - 1
            snglRead4 = br4.ReadByte
            'If snglRead1 >= BandMin Then
            '    snglRead1 = snglRead1 - BandMin
            'Else
            '    snglRead1 = BandMin
            'End If
            snglOutput4 = ((LMax2 - LMin2) / (QCalMax2 - QCalMin2)) * ((snglRead4 - BandMin2) - QCalMin2) + LMin2
            bw4.Write(snglOutput4)
        Next

        s7.Close()
        s8.Close()

        MessageBox.Show("STEP 2 DONE", "Success!")
        'STEP 3: This precedure reads band6.img and outputs band6_toa.img

        Dim s9 As FileStream 'Load file 1
        Dim s10 As FileStream 'Save output

        'If System.IO.File.Exists("C:\delete\band6_toa.img") Then
        '    System.IO.File.Delete("C:\delete\band6_toa.img")
        'End If

        '---read from and write to a binary file
        s9 = New FileStream("C:\delete\band6.img", FileMode.Open, FileAccess.Read)
        s10 = New FileStream("C:\delete\band6_toa.img", FileMode.CreateNew, FileAccess.Write)

        Dim br5 As BinaryReader
        Dim bw5 As BinaryWriter

        br5 = New BinaryReader(s9)
        bw5 = New BinaryWriter(s10)

        Dim fLen5 As Integer
        Dim f5 As New System.IO.FileInfo("C:\delete\band6.img")
        fLen5 = f5.Length

        Dim snglRead5 As Single
        Dim snglOutput5 As Single 'wıll hold results from division

        Dim d As Integer


        Dim LMax3 As Single
        Dim LMin3 As Single
        Dim QCalMax3 As Single
        Dim QCalMin3 As Single
        Dim BandMin3 As Single

        LMax3 = CSng(txtBoxLMax6.Text)
        LMin3 = CSng(txtBoxLMin6.Text)
        QCalMax3 = CSng(txtBoxQMax6.Text)
        QCalMin3 = CSng(txtBoxQMin6.Text)
        BandMin3 = CSng(txtBoxBandMin6.Text)

        'Read binary file1 and fill the array with pixel values 
        For d = 0 To fLen5 - 1
            snglRead5 = br5.ReadByte
            'If snglRead1 >= BandMin Then
            '    snglRead1 = snglRead1 - BandMin
            'Else
            '    snglRead1 = BandMin
            'End If
            snglOutput5 = ((LMax3 - LMin3) / (QCalMax3 - QCalMin3)) * ((snglRead5 - BandMin3) - QCalMin3) + LMin3
            bw5.Write(snglOutput5)
        Next

        s9.Close()
        s10.Close()

        MessageBox.Show("STEP 3 DONE", "Success!")

        'STEP 4: This precedure reads band3_toa.img and outputs band3_ref.img

        Dim s1 As FileStream 'Load file 1
        Dim s3 As FileStream 'Save output

        'If System.IO.File.Exists("C:\delete\band3_ref.img") Then
        '    System.IO.File.Delete("C:\delete\band3_ref.img")
        'End If

        '---read from and write to a binary file
        s1 = New FileStream("C:\delete\band3_tao.img", FileMode.Open, FileAccess.Read) 'Exception thrown here 
        s3 = New FileStream("C:\delete\band3_ref.img", FileMode.CreateNew, FileAccess.Write)

        Dim br1 As BinaryReader
        Dim bw As BinaryWriter

        br1 = New BinaryReader(s1)
        bw = New BinaryWriter(s3)

        Dim fLen1 As Integer
        Dim f1 As New System.IO.FileInfo("C:\delete\band3_tao.img")

        fLen1 = Int(f1.Length / 4)


        Dim snglRead1 As Single
        Dim snglOutput As Single 'wıll hold results from division


        Dim i As Integer


        Dim distance As Single
        Dim esun As Single
        Dim zenith As Single
        distance = CSng(txtBoxEarthSun.Text)
        esun = CSng(txtBoxExoAtm3.Text)
        zenith = CSng(txtBoxZenith.Text)

        For i = 0 To fLen1 - 1
            snglRead1 = br1.ReadSingle()
            snglOutput = ((3.14159265 * snglRead1 * distance * distance) / (esun * Math.Cos(zenith * 0.01745329252)))

            bw.Write(snglOutput)
        Next


        s1.Close()
        s3.Close()
End Sub
End Class

Recommended Answers

All 2 Replies

Hi,

On line 25 it looks like you call the image "band3_toa.img" and on line 197 its called "band3_tao.img".

Note: tao and toa

Thanks Sling for your help. I do not know how I made such a mistake. The program works ok now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.