OK
i have a plain text file in a rich text box. This plain text file contains for the most part just text, but it has several chunks of data which are apparently stored as doubles
For Example this string here:
I happen to know that the date field is a date of payment, and apparently, the data before this is the amount paid.
The original program i am trying to read was written in quickbasic 7. I don't know enough to know how to do what i what.
I've tried
Try Dim test As Stringtest =
"33333oH@33333oH@" Dim Result As DoubleResult = Convert.ToDouble(test)
TextBox2.Text = Result.ToString
Catch ex As ExceptionMsgBox(ex.Message)
End Try
or
Try Dim test As Stringtest =
"33333oH@33333oH@" Dim Result As DoubleResult =
Double.Parse(test)TextBox2.Text = Result.ToString
Catch ex As ExceptionMsgBox(ex.Message)
End Try
But had no luck. An Help Appreciated :)
Ta
Mc

Converting String to double?
AllaP
Thanks Anthony,
Could you (or anyone else :) )please give me a rough idea of how i would build an array that i can load each variable into I don't have any dramas reading the file, but i'm not quite sure how to tell it that each record is 512bytes, comprised of cu00,cu01 etc
Many thanks for all your help to date!
jeffwu
CESAR DE LA TORRE
Here is all the code - at the moment i am just testing the read proceedure to make sure it works
The only other code is your modified structure statement
I think after i posted the last message i determined it was a problem with the recordnumber but im having difficulty in determining why. Im thinking its because the fileget has NFI about the number of records in the file.
Dim filenumber As Integer
Dim RecordNumber As Integer Dim temp As ValueType Dim record As CustomerRecordfilenumber = FreeFile()
FileOpen(filenumber,
"f:\cust.p04", OpenMode.Random, , , 512) Try Do Until EOF(1)FileGet(filenumber, temp, RecordNumber)
record =
DirectCast(temp, CustomerRecord) Loop Catch ex As ExceptionMsgBox(ex.Message)
End TryCreature
You know... My guess is that what you are seeing there is artifactual. If you looked at it in binary or in a Hex format... you may see something more intelligible, not that a real number representation is necessarily going to be intelligble.
If you can... if you have the program. Make a known entry into those files and see what you get.
J Kenyon
I assume you're ommitting portions of your code for brevity. Your NullReference exception less useful without some stack information about what object caused it. as for the argument Recordnumber being invalid I have no idea what the value is at that point in the do loop. Feel free to email me your code and I'll take a look:
ad_green@lycos.com
Otherwise I think you need to recheck the documentation to appreciate what all is happening. RecordNumber is 1 based, not 0 based, so passing it in without initializing it should throw an exception as there is no record #0. Furthermore temp must always be set to an instance (even a blank one) of CustomerRecord (I assume) for the method to reflect over the type to determine what fields to read and how to read them.
michaelji
This is the type conversion I came up with. Use it in conjunction with the VB Runtime functions FileOpen (RandomAccess), FileGet and FilePut. This should give you file i/o compatable with the VB6 way. I would however advise constructing a separate file converter component and migrating the data to a more modern format. Either a Database or an XML File.
Lucky for you I'm one of the few people on the planet to still have a QB71 IDE on their hard drive. I just tried reading a file in VB written in QB using this structure and it reads fine using the method prescribed. However, a word of warning, the floating types either loose a bit of precision in the translation or floating points can't represent the number 7.89 (since I read 7.889........). Second warning, when using FileGet, don't type your variable as CustomerRecord, use ValueType or the compiler will complain. Initialize the variable to New CustomerRecord though.
Structure CustomerRecord
<VBFixedString(6)> Public cu00 As String '* 6 ' Header Var
<VBFixedString(10)> Public cu01 As String ' * 10 ' Account Code
<VBFixedString(35)> Public cu02 As String ' * 35 ' Account Name
<VBFixedString(30)> Public cu03 As String ' * 30 ' Address Line 1
<VBFixedString(30)> Public cu04 As String ' * 30 ' Address Line 2
<VBFixedString(30)> Public cu05 As String ' * 30 ' Address Line 3
<VBFixedString(6)> Public cu06 As String ' * 6 ' Post Code
<VBFixedString(15)> Public cu07 As String ' * 15 ' Phone Number 1
<VBFixedString(15)> Public cu08 As String ' * 15 ' Phone NUmber 2
<VBFixedString(15)> Public cu09 As String ' * 15 ' Fax NUmber
Public cu10 As Short ' Account Type 1-6
Public cu11 As Short ' Account Category 1-6
<VBFixedString(1)> Public cu12 As String ' * 1 ' Disputed Account Y/N
<VBFixedString(1)> Public cu13 As String ' * 1 ' always Y
<VBFixedString(8)> Public cu14 As String ' * 8 ' GST Exemption Code
Public cu15 As Short ' Price Level 1 - 7
Public cu16 As Single ' Discount %
Public cu17 As Short ' CRedit Terms In Days
Public cu18 As Double ' CRedit Limit
Public cu19 As Short '
Public cu20 As Double '
Public cu21 As Short ' CRedit Card Number #1 (type)
<VBFixedString(6)> Public cu22 As String ' * 6 ' Credit Card Prefix #1
<VBFixedString(20)> Public cu23 As String ' * 20 ' CRedit Card NUmber #1
Public cu24 As Short ' CRedit Card Number #2 (type)
<VBFixedString(6)> Public cu25 As String ' * 6 ' Credit Card Prefix #2
<VBFixedString(20)> Public cu26 As String ' * 20 ' CRedit Card Number #2 (type)
<VBFixedString(10)> Public cu27 As String ' * 10 ' User Def #1
<VBFixedString(10)> Public cu28 As String ' * 10 ' User Def #2
<VBFixedString(10)> Public cu29 As String ' * 10 ' User Def #3
<VBFixedString(10)> Public cu30 As String ' * 10 ' User Def #4
<VBFixedString(10)> Public cu31 As String ' * 10 '
<VBFixedString(10)> Public cu32 As String ' * 10 '
<VBFixedString(25)> Public cu33 As String ' * 25 ' Contact Name
<VBFixedString(10)> Public cu34 As String ' * 10 '
<VBFixedString(20)> Public cu35 As String ' * 20 '
<VBFixedString(12)> Public cu36 As String ' * 12 '
<VBFixedString(6)> Public cu37 As String ' * 6 ' debtors code
Public cu38 As Double '
Public cu39 As Double '
Public cu40 As Double '
Public cu41 As Double '
Public cu42 As Double ' Account Balance
<VBFixedString(8)> Public cu43 As String ' * 8 ' Date Last Paid
Public cu44 As Double ' Amount Last Paid
<VBFixedString(17)> Public CU45 As String ' * 17 ' Various
Public cu47 As Double ' MTD Purchases
Public cu48 As Double ' YTD Purchases
<VBFixedString(2)> Public cu46 As String ' * 2 ' Good Record Indicator ^^ = good record
End Structure
DSull
Anthony,
i think i follow you here
Here is a bit of "my" code
Try
Do Until EOF(1)FileGet(filenumber, temp, -1)
record =
DirectCast(temp, CustomerRecord) Loop Catch ex As ExceptionMsgBox(ex.Message)
End TryIf i run the above, i get "Object Reference not set to instance of an object"
If i replace FileGet(filenumber, temp, -1) with FileGet(filenumber, temp, Recordnumber)
I get "Argument Recordnumber is not a valid value"
:(
ERodrigues
Ryan Taylor
To my knowledge the only way to do this is to use the methods in the Microsoft.VisualBasic runtime library. These are imported by default into Visual Basic projects. Here's a sample:
Dim filename As String
Dim fileNumber, recordNumber As Integer
Dim temp As ValueType
Dim record As CustumerRecord
fileNumber = FreeFile()
FileOpen(fileNumber, filename, OpenMode.Random, RecordLength:=512)
FileGet(fileNumber, temp, recordNumber)
record = DirectCast(temp, CustumerRecord)
You can check the documentation on these methods and their parameters but this code alone demonstrates the basics of retrieving records from a file. To get all the records you'd probably wrap the FileGet in a For loop with an upperbound = the file length \ 512 or a Do Until EoF(1) loop.
dunnee
Hmm
Ok
Perhaps i need to look at converting the VB6 type statements to define the file, and then read from it directly. This might solve all my problems
R Thompson
Hi!
I think you need regular expressions to split input string into parts. Check MSDN for System.Text.RegularExpressions.Regex.Split() method.
jvictor
Sorry to be be boring, but i don't understand what i'm looking for in regards to regex.split
I don't know what i can split it by
My double is stored in a string of 512 characters - i can use the substring command to get the chars that the double is stored as, but apparently its stored AS a double.
Maybe i just don't understand, but i can't see how regex will help me.
I do have the original program so my sample code of
33333oH@ is actually $20.00
the vb6 code used to read this is as follows:
msgbox "Value last paid : "+format$(cu.cu44,"#.##")
However, the VB6 code uses a type statement to define each record in the file. Im not using this in .net. Perhaps i should I have the complete code required to read my file directly in vb6 butI know nothing about vb6 so it makes it even harder and i can't convert it.
web_monkey2k
I misundestand your data format, I thought you have STRING and want extract from it doubles (like smart tags in Word).
If you have BINARY doubles - you need use BinaryReader. You should not treat your file as text, because it's not text in fact, but a binary stream of doubles and strings.
Ian Morrish - MSFT
Anthony,
Here is the type statement from VB6. It might be worth noting that datafile itself was not written by a VB6 based program but rather a QuickBasic 7 (i think its 7, could be older) based program. Apparently the records as stored exactly as the type statement indicates (Double is 8 bytes, Single is 4 bytes, Integer is 2 bytes - I'm guessing the rest of the fields are stored as per the length of each)
In any case, each record in the file is 512 bytes long, and the 512 bytes is broken up as per the below type statement.
I hope this is what you were asking for!
I need to be able to read each record from the file in its original format into a properly specified array, without converting to text readers etc first. I think. That should prevent translation problems with the doubles Then i can write from the array to a text file and convert to string on the fly. That's what i'd like to be able do in any case.
Type customerrec
cu00 As String * 6 ' Header Var
cu01 As String * 10 ' Account Code
cu02 As String * 35 ' Account Name
cu03 As String * 30 ' Address Line 1
cu04 As String * 30 ' Address Line 2
cu05 As String * 30 ' Address Line 3
cu06 As String * 6 ' Post Code
cu07 As String * 15 ' Phone Number 1
cu08 As String * 15 ' Phone NUmber 2
cu09 As String * 15 ' Fax NUmber
cu10 As Integer ' Account Type 1-6
cu11 As Integer ' Account Category 1-6
cu12 As String * 1 ' Disputed Account Y/N
cu13 As String * 1 ' always Y
cu14 As String * 8 ' GST Exemption Code
cu15 As Integer ' Price Level 1 - 7
cu16 As Single ' Discount %
cu17 As Integer ' CRedit Terms In Days
cu18 As Double ' CRedit Limit
cu19 As Integer '
cu20 As Double '
cu21 As Integer ' CRedit Card Number #1 (type)
cu22 As String * 6 ' Credit Card Prefix #1
cu23 As String * 20 ' CRedit Card NUmber #1
cu24 As Integer ' CRedit Card Number #2 (type)
cu25 As String * 6 ' Credit Card Prefix #2
cu26 As String * 20 ' CRedit Card Number #2 (type)
cu27 As String * 10 ' User Def #1
cu28 As String * 10 ' User Def #2
cu29 As String * 10 ' User Def #3
cu30 As String * 10 ' User Def #4
cu31 As String * 10 '
cu32 As String * 10 '
cu33 As String * 25 ' Contact Name
cu34 As String * 10 '
cu35 As String * 20 '
cu36 As String * 12 '
cu37 As String * 6 ' debtors code
cu38 As Double '
cu39 As Double '
cu40 As Double '
cu41 As Double '
cu42 As Double ' Account Balance
cu43 As String * 8 ' Date Last Paid
cu44 As Double ' Amount Last Paid
CU45 As String * 17 ' Various
cu47 As Double ' MTD Purchases
cu48 As Double ' YTD Purchases
cu46 As String * 2 ' Good Record Indicator ^^ = good record
End Type