bad file name or number

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cvirendra
    New Member
    • Mar 2007
    • 3

    bad file name or number

    Hi all,

    M using visual basic 2005. I have declared a variable Log_File as integer in a module.

    I've open a file using openfile in a function (which is again defined in the same module). M using a Print function to write inot the file. When i call Print function within same moude it works fine. But if i call Print from a event in form, i m gettin bad ile name or number exception.

    Can anyone help me. Wat m i missin her?

    Thanks in advance
    Virendra Chaudhary
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Hi Virendra. Post your code please. The part that works and the part that does not work. Then we will work out the problem together.
    Thanks

    Comment

    • cvirendra
      New Member
      • Mar 2007
      • 3

      #3
      Originally posted by willakawill
      Hi Virendra. Post your code please. The part that works and the part that does not work. Then we will work out the problem together.
      Thanks
      Thankx for d reply...

      the code dat works is

      Code:
      Public Sub processSend(ByVal message As String, ByVal port As String)
              System.Threading.Thread.Sleep(50)
              My.Forms.frmMain.serialPort.Write(message & vbCrLf)
              Last_Sent_Time = GetTickCount()
              Print(Log_File, Last_Sent_Time & "@" & message & vbCrLf)
      End Sub
      I m callin dis function whenever I hv a data to b sent 2 d serial port. Also this function is defined in a module.

      Now on the frmMain form I have a serialport control. On the recieve event i hv written d followin code..

      Code:
      Private Sub serialPort_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles serialPort.DataReceived
      
              Dim ReceiveTimeStamp As Long
      
              ReceiveTimeStamp = GetTickCount()
      
              If (Look_Buffer_Count >= 19) Then
                  Look_Buffer_Count = 0
              Else
                  Look_Buffer_Count = Look_Buffer_Count + 1
              End If
      
      
              Look_Buffer(Look_Buffer_Count) = ReceiveTimeStamp & "@" & Me.serialPort.ReadLine
      
              If (Start_Logging = True) Then
                  'Call updateLogFile(ReceiveTimeStamp & "@" & Look_Buffer(Look_Buffer_Count))
                  Print(Log_File, Look_Buffer(Look_Buffer_Count))
              End If
      End Sub
      Here while executin line "Print(Log_file ......" i get bad file name or number exception.

      Hope dis clear d problem 2 u.
      Last edited by willakawill; Mar 1 '07, 03:47 PM. Reason: please use code tags when posting code

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Have you checked what the value is in Log_File when it works, and when it doesn't?

        Comment

        • cvirendra
          New Member
          • Mar 2007
          • 3

          #5
          Originally posted by Killer42
          Have you checked what the value is in Log_File when it works, and when it doesn't?
          Yes! It is the same both d times ...

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by cvirendra
            Yes! It is the same both times ...
            Damn! :(

            Not being familiar with VB.Net, I'm pretty much out of ideas.

            Comment

            • willakawill
              Top Contributor
              • Oct 2006
              • 1646

              #7
              Originally posted by cvirendra
              Yes! It is the same both d times ...
              That does not make sense. Either the file has been closed, not opened yet, or out of scope. We need to know the scope of Log_File and where and when it is given a file handle.

              Comment

              Working...