0

I have a text file with each record having a data value and I have to generate a text file that should have each of the original records and new records with data value sign changed. Input file with records look like this (pipe is the delimiter, data value is always the 5th field):

 abc|xyz|a|ab_1|100
 abs|pqr|d|ab3|-200 

The output should be:

abc|xyz|a|ab_1|100
abc|xyz|a|ab_1|-100
abs|pqr|d|ab3|-200 
abs|pqr|d|ab3|+200  
5
  • 1
    how urgent is it? is there any other requirement? must it be vbscript or can we provide you with a solution in some other language? Commented Sep 25, 2014 at 12:59
  • Hi..thanks for the reply. I have to use VB script only. I have got the idea and hopefully I will b able 2 develop the code, if not I will be back here asking for help :). Also I need to sort the output file based upon some field from within the file. how can this be achieved ( using VB only). Thanks for ur help and time Commented Sep 25, 2014 at 15:55
  • Thanks @bond nd horner ... I ahve developed the initial code..though still need to check the execution. hopefully it will work. Also can u provide the vbs(VB only) code to convert the .txt file into .csv .txt file could be space delimited or comma delimited Commented Sep 27, 2014 at 10:23
  • Hi, I am able to perform most of the tasks. Now trouble for me is how to convert value in a variable to float and than multiply it with -1. I tried CInt but still its giving type mismatch error..kindly help. regards Commented Sep 28, 2014 at 16:52
  • accept the answer and post another question in SO for your problem. Or first try to debug your element, does it contain spaces? Commented Sep 30, 2014 at 11:25

1 Answer 1

1

A plan:

  1. .OpenTextFile() input
  2. .CreateTextFile output
  3. Until input .AtEndOfStream
  4. ---- .ReadLine from input and .WriteLine to output
  5. ---- .Split on | into 5 element array
  6. ---- CInt() elm 4 and multiply with -1
  7. ---- Join array with |
  8. ---- .WriteLine to output
  9. Close both files

Use the docs to lookup functions like CInt() and Split() and objects like FileSystemObject and TextStream and their methods OpenTextFile(), .ReadLine(), ...

Sign up to request clarification or add additional context in comments.

4 Comments

Good plan. And note, @Sharma, that steps 4 thru 8 are within your reading loop (created in step 3). Step 9 is outside the loop, after you've finished reading the entire file.
@bond Hi, I am able to perform most of the tasks. Now trouble for me is how to convert value in a variable to float and than multiply it with -1. I tried CInt but still its giving type mismatch error..kindly help. regards
@Sharma - Display/WScript.Echo the element before you apply CInt(). Does it look like a number? Does the first line of your file contain column headers? Are the numbers too large (-> CLng()) or not integers (-> CDbl())? Did you think of: 5 elements, but indexed 0-4?
Hi, So here I got something -- all column value is having a space character in between them. I am messed up now. whats happedning here. for I read abc from file and when I write it it is becoming a b c . Y it is happening. Please help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.