AboutSyed Rizwan Muhammad Rizvi Expertise I can answers questions regarding web based and desktop based programming in VB.Net. Which can include SOAP, XML, Custom Controls, COM Interoperability etc.
Experience Have been working in this specific area for last 2 years previously I was a VB 6 Developer with experties in other languages as well. Total 10 years of programming experience.
Question Hello Seyd,
I am not a Vb programmer, but I looking for a program written Visual Basic to do the following:
File type: Txt
step 1 - Copy file name xxxxx.txt to xxxxxOLD.txt (just as a backup)
step 2 - In the xxxxx.txt, if position 4 is a "-", and position 7 is a "-" then copy the entire record to the new file adding "xxxx" in positions 8 - 11. Otherwise, copy the entire record to the new file.
In English - I am trying to copy the contents of a file to another file. However, if the record being copied has a "-" in both position, 4 and 7, I would like the string "xxxx" written in positions 8 - 11. If I can keep the input and output file names the same that would be great.
Can you help? I do have a VB compile.
Answer Hi,
Seems like you are trying to Copy CC numbers.
To read a character in a string you can use Mid$(String,StartPosition,Length) function. So to check if you have a '-' at location 4 you can say:
if Mid(strCCNo,4,1) = "-" then
if Mid(strCCNo,7,1) = "-" then
'We can also use the mid function for assignments so to replace a specific character
mid(strCCNo,8,1) = "x"
'I guess you want to replace positions 8-11 with xxxxx not add xxxx to it, to achieve that you can use:
strNewCCNo = left(strCCNo,7) & "xxxx"
end if
end if
Hope the above helps let me know if you have got further questions. You can use the Open statement to open a file and close statement to close the file or alternatively you can use the FileSystemObject which is much easier to use, you can read data from file, using Input statement if you are using Open/Close statements to open the file.