Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 2nd, 2006, 06:28 AM
Registered User
 
Join Date: Oct 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default I need to implement Sequential File Access


I have attached a working VB implementation that I coded myself.

App reads an input file (customer master), processes it and outputs to a data file which is used

as input to another software.

I need to do this in C# urgently.

Questions:
1. Is it possible?
2. How do I go about it in the most elegant and efficient way?
3. A working example would be appreciated!!!

I read many newsgroups and forums and microsoft website, and they talk about marshalling and

reflection and ad infinitum.. I can not make sense of it all...

Can you help me?

Sincerely,
Jack

===================

VERSION 5.00
Begin VB.Form frmMain
   BackColor = &H00FFC0C0&
   Caption = "MVRS Data File Translator"
   ClientHeight = 4530
   ClientLeft = 60
   ClientTop = 345
   ClientWidth = 8535
   LinkTopic = "Form1"
   ScaleHeight = 4530
   ScaleWidth = 8535
   StartUpPosition = 3 'Windows Default
   Begin VB.Frame Frame1
      BackColor = &H00FFC0C0&
      Caption = "Choose a task:"
      BeginProperty Font
         Name = "Times New Roman"
         Size = 12
         Charset = 0
         Weight = 400
         Underline = 0 'False
         Italic = 0 'False
         Strikethrough = 0 'False
      EndProperty
      Height = 3615
      Left = 120
      TabIndex = 2
      Top = 120
      Width = 8295
      Begin VB.OptionButton Option4
         BackColor = &H00FFC0C0&
         Caption = "="
         BeginProperty Font
            Name = "Times New Roman"
            Size = 12
            Charset = 0
            Weight = 400
            Underline = 0 'False
            Italic = 0 'False
            Strikethrough = 0 'False
         EndProperty
         Height = 405
         Left = 240
         TabIndex = 6
         Top = 2760
         Width = 7935
      End
      Begin VB.OptionButton Option3
         BackColor = &H00FFC0C0&
         Caption = "="
         BeginProperty Font
            Name = "Times New Roman"
            Size = 12
            Charset = 0
            Weight = 400
            Underline = 0 'False
            Italic = 0 'False
            Strikethrough = 0 'False
         EndProperty
         Height = 405
         Left = 240
         TabIndex = 5
         Top = 2040
         Width = 7935
      End
      Begin VB.OptionButton Option2
         BackColor = &H00FFC0C0&
         Caption = "="
         BeginProperty Font
            Name = "Times New Roman"
            Size = 12
            Charset = 0
            Weight = 400
            Underline = 0 'False
            Italic = 0 'False
            Strikethrough = 0 'False
         EndProperty
         Height = 405
         Left = 240
         TabIndex = 4
         Top = 1320
         Width = 7935
      End
      Begin VB.OptionButton Option1
         BackColor = &H00FFC0C0&
         Caption = "Parse AML and Generate Host Download File (SPECTRUM ---> MVRS)"
         BeginProperty Font
            Name = "Times New Roman"
            Size = 12
            Charset = 0
            Weight = 400
            Underline = 0 'False
            Italic = 0 'False
            Strikethrough = 0 'False
         EndProperty
         Height = 405
         Left = 240
         TabIndex = 3
         Top = 600
         Width = 7935
      End
   End
   Begin VB.CommandButton btnExit
      Caption = "Exit"
      BeginProperty Font
         Name = "Times New Roman"
         Size = 12
         Charset = 0
         Weight = 400
         Underline = 0 'False
         Italic = 0 'False
         Strikethrough = 0 'False
      EndProperty
      Height = 405
      Left = 6840
      TabIndex = 1
      Top = 3960
      Width = 1575
   End
   Begin VB.CommandButton btnBegin
      Caption = "Begin"
      BeginProperty Font
         Name = "Times New Roman"
         Size = 12
         Charset = 0
         Weight = 400
         Underline = 0 'False
         Italic = 0 'False
         Strikethrough = 0 'False
      EndProperty
      Height = 405
      Left = 4200
      TabIndex = 0
      Top = 3960
      Width = 2535
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Type mvFileHeaderTrailerRecord
  f01_RecordID As String * 3
  f02_TablesIndicator As String * 1
  f03_OpticalProbeRecordIndicator As String * 1
  f04_VersionNumberOfTable As String * 5
  f05_Reserved As String * 3
  f06_NumberOfCycles As String * 2
  f07_OffSiteRecordIndicator As String * 1
  f08_WandRecordIndicator As String * 1
  f09_ExtendedRouteHeaderTrailerFormatIndicator As String * 1
  f10_Pad As String * 108
  f11_CRLF As String * 2
End Type

Private Type mvCycleHeaderTrailerRecord
  f01_RecordID As String * 3
  f02_CycleIDNumber As String * 2
  f03_NumberOfRoutesInCycle As String * 4
  f04_CycleDate As String * 8
  f05_Pad As String * 109
  f06_CRLF As String * 2
End Type

Private Type mvStandardRouteHeaderTrailerRecord
  f01_RecordID As String * 3
  f02_RouteNumber As String * 8
  f03_SurveyIndicator As String * 1
  f04_RouteMessageIndicator As String * 1
  f05_TotalNumberOfKeys As String * 4
  f06_TotalNumberOfReadingRecords As String * 4
  f07_TotalNumberOfDemandMeters As String * 4
  f08_TotalNumberOfKeyedReadings As String * 4
  f09_TotalNumberOfOpticalProbeReadings As String * 4
  f10_TotalNumberOfOffSiteRadioReadings As String * 4
  f11_TotalNumberOfCustomerRecords As String * 4
  f12_TotalNumberOfMeterRecords As String * 4
  f13_TimeAllottedForRoute As String * 6
  f14_TotalNumberOfGasMeters As String * 4
  f15_TotalNumberOfWaterMeters As String * 4
  f16_TotalNumberOfElectricMeters As String * 4
  f17_TotalNumberOfLocationMeters As String * 4
  f18_TotalNumberOfExtraMeters As String * 4
  f19_Region As String * 2
  f20_Zone As String * 2
  f21_Office As String * 2
  f22_BillCycle As String * 2
  f23_DropCycle As String * 2
  f24_TotalNumberOfRemoteWandReads As String * 4
  f25_MobileAMR As String * 1
  f26_Pad As String * 40
  f27_CRLF As String * 2
End Type

Private Type mvCustomerRecord
  f01_RecordID As String * 3
  f02_RouteNumber As String * 8
  f03_NumberOfMeters As String * 3
  f04_AccountNumber As String * 20
  f05_Name As String * 20
  f06_Address1 As String * 20
  f07_Address2 As String * 20
  f08_Reserved As String * 2
  f09_GroupCode As String * 1
  f10_CustomerInformation As String * 20
  f11_CustomerExtraRecordIndicator As String * 1
  f12_SegmentCode As String * 4
  f13_UtilityID As String * 2
  f14_PassThroughData As String * 1
  f15_Pad As String * 1
  f16_CRLF As String * 2
End Type

Private Type mvMeterRecord
  f01_RecordID As String * 3
  f02_RouteNumber As String * 8
  f03_NumberOfReadings As String * 3
  f04_Reserved As String * 2
  f05_GroupCode As String * 1
  f06_Reserved As String * 8
  f07_SurveyCode1DisplayIndicator As String * 1
  f08_Reserved As String * 2
  f09_SurveyCode2DisplayIndicator As String * 1
  f10_BillCode As String * 1
  f11_MeterStatus As String * 1
  f12_OpticalProbeRecorderID As String * 14
  f13_MeterNumber As String * 12
  f14_Reserved As String * 2
  f15_MeterType As String * 2
  f16_MeterReadSequence As String * 8
  f17_MeterInformation As String * 20
  f18_Reserved As String * 1
  f19_MeterLocation As String * 2
  f20_Reserved As String * 1
  f21_ReadInstruction1 As String * 2
  f22_Reserved As String * 1
  f23_ReadInstruction2 As String * 2
  f24_SpecialMessageDisplayIndicator As String * 1
  f25_Reserved As String * 1
  f26_SpecialMessageIndicator As String * 1
  f27_MeterCategory As String * 1
  f28_LocationExtraMeter As String * 1
  f29_TimeCode As String * 3
  f30_MeterAudit1 As String * 2
  f31_MeterAudit2 As String * 2
  f32_MeterAudit3 As String * 1
  f33_MeterAudit4 As String * 1
  f34_Pad As String * 14
  f35_CRLF As String * 2
End Type

Private Type mvReadingRecord
  f01_RecordID As String * 3
  f02_RouteNumber As String * 8
  f03_TextPrompt As String * 4
  f04_PromptCode As String * 1
  f05_ReadDirection As String * 1
  f06_CompareCode As String * 3
  f07_ValidationCode As String * 3
  f08_Reserved As String * 1
  f09_ChannelNumber As String * 2
  f10_NumberOfDials As String * 2
  f11_NumberOfDecimals As String * 2
  f12_ReadMethod As String * 1
  f13_PreviousReading As String * 10
  f14_High1 As String * 10
  f15_Low1 As String * 10
  f16_MeterConstant As String * 6
  f17_ConstantFlag As String * 1
  f18_HHFPosition As String * 1
  f19_PositiveDialCreep As String * 5
  f20_NumberOfConsecutiveEstimates As String * 1
  f21_Reserved As String * 1
  f22_ReadType As String * 2
  f23_MaximumPercent As String * 6
  f24_MinimumPercent As String * 6
  f25_NegativeDialCreep As String * 5
  f26_Pad As String * 31
  f27_CRLF As String * 2
End Type

Private Sub AccountMasterToMVRS()
 '
 '
 Dim fhr As mvFileHeaderTrailerRecord
 Dim ftr As mvFileHeaderTrailerRecord
 '
 Dim cyhr As mvCycleHeaderTrailerRecord
 Dim cytr As mvCycleHeaderTrailerRecord
 '
 Dim rhr As mvStandardRouteHeaderTrailerRecord
 Dim rtr As mvStandardRouteHeaderTrailerRecord
 '
 Dim cr As mvCustomerRecord
 '
 Dim mr As mvMeterRecord
 '
 Dim rr As mvReadingRecord
 '


 '
 ' File header data
 '
 fhr.f01_RecordID = "FHD"
 fhr.f02_TablesIndicator = "N"
 fhr.f03_OpticalProbeRecordIndicator = "N"
 fhr.f04_VersionNumberOfTable = "00000"
 fhr.f05_Reserved = "RRR"
 fhr.f06_NumberOfCycles = Format(1, "00")
 fhr.f07_OffSiteRecordIndicator = "N"
 fhr.f08_WandRecordIndicator = "N"
 fhr.f09_ExtendedRouteHeaderTrailerFormatIndicator = "N"
 fhr.f10_Pad = String(128, "P")
 fhr.f11_CRLF = Chr(10) + Chr(13)

 '
 ' File trailer data
 '
 ftr = fhr
 ftr.f01_RecordID = "FTR"

 '
 ' Cycle header data
 '
 cyhr.f01_RecordID = "CHD"
 cyhr.f02_CycleIDNumber = Format(1, "00")
 cyhr.f03_NumberOfRoutesInCycle = Format(1, "0000")
 cyhr.f04_CycleDate = Format("1/1/1999", "MMDDYYYY")
 cyhr.f05_Pad = String(109, "P")
 cyhr.f06_CRLF = Chr(10) + Chr(13)

 '
 ' Cycle trailer data
 '
 cytr = cyhr
 cytr.f01_RecordID = "CTR"

 '
 ' Route header data
 '
 rhr.f01_RecordID = "RHD"
 rhr.f02_RouteNumber = "01000001"
 rhr.f03_SurveyIndicator = "N"
 rhr.f04_RouteMessageIndicator = "N"
 rhr.f05_TotalNumberOfKeys = "0000"
 rhr.f06_TotalNumberOfReadingRecords = Format(29, "0000")
 rhr.f07_TotalNumberOfDemandMeters = Format(2, "0000")
 rhr.f08_TotalNumberOfKeyedReadings = Format(2, "0000")
 rhr.f09_TotalNumberOfOpticalProbeReadings = Format(0, "0000")
 rhr.f10_TotalNumberOfOffSiteRadioReadings = Format(0, "0000")
 rhr.f11_TotalNumberOfCustomerRecords = Format(29, "0000")
 rhr.f12_TotalNumberOfMeterRecords = Format(29, "0000")
 rhr.f13_TimeAllottedForRoute = "043015"
 rhr.f14_TotalNumberOfGasMeters = Format(0, "0000")
 rhr.f15_TotalNumberOfWaterMeters = Format(0, "0000")
 rhr.f16_TotalNumberOfElectricMeters = Format(0, "0000")
 rhr.f17_TotalNumberOfLocationMeters = Format(0, "0000")
 rhr.f18_TotalNumberOfExtraMeters = Format(0, "0000")
 rhr.f19_Region = Format(1, "00")
 rhr.f20_Zone = Format(1, "00")
 rhr.f21_Office = Format(1, "00")
 rhr.f22_BillCycle = Format(1, "00")
 rhr.f23_DropCycle = Format(1, "00")
 rhr.f24_TotalNumberOfRemoteWandReads = Format(0, "0000")
 rhr.f25_MobileAMR = ""
 rhr.f26_Pad = String(40, "P")
 rhr.f27_CRLF = Chr(10) + Chr(13)

 '
 ' Route trailer data
 '
 rtr = rhr
 rtr.f01_RecordID = "RTR"

 '
 ' Customer record data
 '
 cr.f01_RecordID = "CUS"
 cr.f02_RouteNumber = "01000001"
 cr.f03_NumberOfMeters = "001"
 LSet cr.f04_AccountNumber = "1243567890-01"
 LSet cr.f05_Name = "CUSTOMER NAME"
 LSet cr.f06_Address1 = "StrNo.StrName."
 LSet cr.f07_Address2 = "Address 2"
 cr.f08_Reserved = "RR"
 cr.f09_GroupCode = "0"
 cr.f10_CustomerInformation = ""
 cr.f11_CustomerExtraRecordIndicator = "N"
 cr.f12_SegmentCode = "0001"
 cr.f13_UtilityID = "01"
 cr.f14_PassThroughData = "0"
 cr.f15_Pad = String(1, "P")
 cr.f16_CRLF = Chr(10) + Chr(13)

 '
 ' Meter record data
 '
 mr.f01_RecordID = "MTR"
 mr.f02_RouteNumber = "01000001"
 mr.f03_NumberOfReadings = "001"
 mr.f04_Reserved = "RR"
 mr.f05_GroupCode = "0"
 mr.f06_Reserved = String(8, "R")
 mr.f07_SurveyCode1DisplayIndicator = "0"
 mr.f08_Reserved = "RR"
 mr.f09_SurveyCode2DisplayIndicator = "0"
 mr.f10_BillCode = "R"
 mr.f11_MeterStatus = "A"
 mr.f12_OpticalProbeRecorderID = ""
 mr.f13_MeterNumber = String(12, "0")
 mr.f14_Reserved = "RR"
 mr.f15_MeterType = "00"
 mr.f16_MeterReadSequence = "10"
 mr.f17_MeterInformation = ""
 mr.f18_Reserved = "R"
 mr.f19_MeterLocation = "00"
 mr.f20_Reserved = "R"
 mr.f21_ReadInstruction1 = "00"
 mr.f22_Reserved = "R"
 mr.f23_ReadInstruction2 = "00"
 mr.f24_SpecialMessageDisplayIndicator = "3"
 mr.f25_Reserved = "R"
 mr.f26_SpecialMessageIndicator = "N"
 mr.f27_MeterCategory = "E"
 mr.f28_LocationExtraMeter = "L"
 mr.f29_TimeCode = "00"
 mr.f30_MeterAudit1 = "YY"
 mr.f31_MeterAudit2 = "YY"
 mr.f32_MeterAudit3 = "Y"
 mr.f33_MeterAudit4 = "Y"
 mr.f34_Pad = String(14, "P")
 mr.f35_CRLF = Chr(10) + Chr(13)

 '
 ' Reading record data
 '
 rr.f01_RecordID = "RDG"
 rr.f02_RouteNumber = "01000001"
 rr.f03_TextPrompt = "KWH "
 rr.f04_PromptCode = "Y"
 rr.f05_ReadDirection = "L"
 rr.f06_CompareCode = "CCC"
 rr.f07_ValidationCode = "099"
 rr.f08_Reserved = "R"
 rr.f09_ChannelNumber = "00"
 rr.f10_NumberOfDials = "05"
 rr.f11_NumberOfDecimals = "00"
 rr.f12_ReadMethod = "K"
 rr.f13_PreviousReading = String(10, "0")
 rr.f14_High1 = String(10, "0")
 rr.f15_Low1 = String(10, "0")
 rr.f16_MeterConstant = "000001"
 rr.f17_ConstantFlag = "0"
 rr.f18_HHFPosition = "1"
 rr.f19_PositiveDialCreep = "00000"
 rr.f20_NumberOfConsecutiveEstimates = "9"
 rr.f21_Reserved = "R"
 rr.f22_ReadType = "00"
 rr.f23_MaximumPercent = "32767"
 rr.f24_MinimumPercent = "32767"
 rr.f25_NegativeDialCreep = "00000"
 rr.f26_Pad = String(31, "P")
 rr.f27_CRLF = Chr(10) + Chr(13)


 '
 ' Create & write data to output file
 '
 Open "HostDownload.DAT" For Binary As #1

 Put #1, , fhr
 Put #1, , cyhr
 Put #1, , rhr
 '
 '

 Dim s As String
 Open "allaml.txt" For Input As #2

 While Not EOF(2)
   Line Input #2, s
   cr.f04_AccountNumber = Split(s, "|")(5)
   cr.f05_Name = Split(s, "|")(7)
   cr.f06_Address1 = Split(s, "|")(10)
   cr.f07_Address2 = Split(s, "|")(11)
   Put #1, , cr
   '
   Put #1, , mr
   '
   rr.f10_NumberOfDials = Split(s, "|")(21)
   rr.f13_PreviousReading = Split(s, "|")(22)
   Put #1, , rr
 Wend
 '
 '
 Put #1, , rtr
 Put #1, , cytr
 Put #1, , ftr

End Sub

Private Sub btnBegin_Click()
 If Option1.Value = True Then
    AccountMasterToMVRS
    MsgBox "Host Download File Generation Complete."
 ElseIf Option2.Value = True Then
    ParseAML
    MsgBox "AML File Parsing Complete."
 ElseIf Option3.Value = True Then
 ElseIf Option4.Value = True Then

 End If

End Sub

Private Sub btnExit_Click()
 End
End Sub

Private Sub Form_Load()
 Option1.Value = True
End Sub

Private Sub ParseAML()
 Dim s As String

  Open "allaml.txt" For Input As #3

 While Not EOF(2)
    Line Input #2, s
    MsgBox Split(s, "|")(5)
 Wend

End Sub




Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sequential File Manipulation chandan8888 BOOK: Professional Visual Studio 2008 ISBN: 978-0-470-22988-0 1 January 14th, 2013 04:02 PM
Access sequential numbering in a query ChadKempel Access 3 June 4th, 2007 12:49 PM
Sequential Numbers ricespn Access 5 February 17th, 2007 01:54 AM
HELP!!!!! Sequential DTS e_cabrera_g SQL Server DTS 1 October 11th, 2006 11:54 AM
Rename multiple file upload in sequential order flyguylol PHP How-To 0 January 11th, 2006 05:05 PM



All times are GMT -4. The time now is 07:49 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.