Google Answers Logo
View Question
 
Q: I need code for a VB program ( Answered,   2 Comments )
Question  
Subject: I need code for a VB program
Category: Computers
Asked by: googooly-ga
List Price: $15.00
Posted: 11 Feb 2003 21:57 PST
Expires: 13 Mar 2003 21:57 PST
Question ID: 160323
Hi, 
I need the code for following VB program. 
I have limited experience in VB so Code has to be written very simply
so I can understand and modify it
I f you do it quickly and explain what you do in each step then I give
you more project and rate it 5 star
 
Have fun 
googooly 

ps--$3 tip per Enhancement 
ps--if you are looking for the file look at the end of this Question



Develop a program which will take the following input:

File path for a text file 
Search text string 
Replace text string 
New File name 
The program will parse the text file and look for data which matches
the specified 'search text string', and then replaces it with the
specified 'replace text string' and then saves it as specified in the
'new file path'

For e.g. 

Search Text String = "<date>"

Replace Text String = "1/1/2003"

So it will look in this file and will replace all the place where
<date> is found with '1/1/2003' and then save to a different file as
specified by the New File Name in the same folder where the input file
exists.

Enhancement:

1. Should be able to search and replace and array of string (separated
by commas) as specified in the input. So for e.g.

Search text string = "<date>", "<name>","<title>"

Replace Text String = "1/1/2003","SN", "ENGINEER"

2. All the inputs will be saved in a configuration INI (config.ini)
file and the VB program will open the config.ini file and get all the
inputs.

Suggestions

Parsing and String Function: Len, Mid, Instr

File Operation (for e.g. opening files, reading files, creating files,
editing files): Learn how to use FileSystemObject

To read/write INI files refer to this article and also learn to use
Windows API in VB Code.

Step1: Read the inputs and store in variables

Step2: Open the text file and read all the text to a string variable

Step3: Call your parsing routine (refer the book. Page 85) to look for
the string, and replace the string.

Step4: Save the file as specified with the new file name.




File:
just open the notepad and cut and past this text into it:



Todays date is <date>. 

Please come by to my office at this particular time and <date>.
Once the <date> is fixed then we can move on to the new task.

Thanks
SN
<date>

Request for Question Clarification by hammer-ga on 12 Feb 2003 09:04 PST
What version of VB?

- Hammer

Request for Question Clarification by theta-ga on 16 Feb 2003 11:59 PST
Hi googooly-ga,
    Just wanted to clarify a few points about your question. More
specifically, I need more information about the format of the
config.ini file.From your question I assume that the config.ini file
will contain data in the following format:
   [sectionname]
   date=12/12/2001
   name=SN
   title=asdf

Is this so? If so, what is the section name? It would be helpful if
you could provide a sample of this config.ini file. Also, I assume you
need VB6 code.
As soon as I receive your reply, I can have the program ready for you
within a day.
Thank you,
Theta-ga

Clarification of Question by googooly-ga on 17 Feb 2003 23:00 PST
Ok,
Sorry everyone I was in vacation in past few days and looks like there are few
 answers, all of them are grate however I have to take my pick.

Hammer you got it.


Thanks 
Googooly

What version of VB? 
>>>>>VB6

Request for Question Clarification by hammer-ga on 18 Feb 2003 04:15 PST
Googooly and other Researchers,

I have not answered this question. Only clarified what version of VB.
I'll get to it if I can, but the question is still open to other
Researchers.

- Hammer

Clarification of Question by googooly-ga on 18 Feb 2003 20:32 PST
Ok looks like hammer is very busy and he is not interested.

Theta-ga could you please answer to my question.

Thank you
googooly


Here is your clarification: 



Hi googooly-ga, 
    Just wanted to clarify a few points about your question. More
specifically, I need more information about the format of the
config.ini file.From your question I assume that the config.ini file
will contain data in the following format:
   [sectionname] 
   date=12/12/2001 
   name=SN 
   title=asdf 

 
Is this so?
>>>YES it is correct<<<<
If so, what is the section name?
 >>>please just use your imagination and create a name<<<<<

It would be helpful if
you could provide a sample of this config.ini file.
>>>I really don’t have time and knowledge please do your best and
create some thing thanks.<<<<<
 
 Also, I assume youneed VB6 code.

>>>yes VB6<<<<
As soon as I receive your reply, I can have the program ready for you
within a day.

>>>As soon as you make it I will pay you. I am just tiring to
understand this concept so I am not picky on it.

Request for Question Clarification by theta-ga on 19 Feb 2003 07:10 PST
Hi googooly-ga,
   Working on it.....
Regards,
Theta-ga
:-)
Answer  
Subject: Re: I need code for a VB program
Answered By: theta-ga on 22 Feb 2003 10:56 PST
 
Hi googooly-ga,
   Sorry for the delay in posting your answer, but a problem at my
ISP's end had kept me off the net for the last couple of days. Anyway,
here I am with the answer. :-)
   You can download the code from the following URL:
http://member.isavvix.com/theta_ga/Search&Replace.jar
Download the file 'Search&Replace.jar' and rename it
'Search&Replace.ZIP'. You can then easily extract its contents.
   The ZIP file contains the following main files:
- GA_Q.vbp: The main VB project file. Click on it to start up VB.
- frmMain.frm: The form which takes in input from the user.
- SearchAndReplace.bas : Implements the function which searches and
replaces text in the given input file.
- Enhancement1.bas: Contains code to implement the functionality
required by the first enhancement as per your question.
- Enhancement2.bas: Contains code to implement the functionality
required by the second enhancement, i.e., reading INI files.

==========================================
When you run the program, the Main form will appear.
At the bottom of this form, there are radio buttons to select the
program mode. The 3 program modes are:
  1. Default: In this mode, you can only enter one term to search for.
 The program searches for the text specified in the Search Term
textbox, and replaces it with the text specified in the Replace Terms
textbox.
  2. Enhancement1: In this mode, the program can search for and
replace multiple search terms. You can specify multiple search terms
in the Search Terms textbox as follows:
        "<date>","<title>","<name>"
     The Replace Terms are specified as:
        "1/1/2003","Manager","Joe User"
     Every term should be in double-quotes (") and separated by commas
(,).
  3. Enhancement2: In this mode, the search and replace terms are read
in from an ini file. The Search and Replace terms textboxes are not
visible. Instead, you are provided a textbox in which you must enter
the full path and name of the ini file to be used. The ini file should
have the following format:
      [Input]
      searchterm1=replaceterm1
      searchterm2=replaceterm2
      searchterm3=replaceterm3
      ...
      The zip file you downloaded will contain a sample ini file named
config.ini

The form will also have two textboxes at the very top. The first
textbox allows you to enter the full path and name of the input text
file. A sample input file 'test.txt' is contained in the zip file you
downloaded.
The second textbox is where you will provide the name of the new file
in which the results of the search and replace operation are to be
saved. You need to provide only the name, not the full path. This file
will be created in the same folder as the input file.

Once you have filled the required data in the textboxes, click on the
Start button. A new file will be created in which the results of the
operation are stored.

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

 This program is of the level of an intermediate VB programmer. While
you are reading the code, be sure to keep a copy of the MSDN library
handy, or check out its online version at http://msdn.microsoft.com
 Although I have commented the code pretty liberally, you might have
some problems if you are not familiar with the following topics:
   - The VB String functions: Len, Mid, Left, Right, InStr
   - Dynamic Arrays In VB
   - The FileSystemObject Object
   - Using the Win32 API functions in VB
   - INI files/ GetPrivateProfileSection() WIN32 function

 If you are not very comfortable with the above topics, you might want
to check out the following articles:
- The VB String functions
     - Juicy Studio Visual Basic String Functions
       ( http://www.juicystudio.com/tutorial/vb/strings.html )
     - Visual Basic Parsing Strings
       ( http://www.rentron.com/parsingstrings.htm )

- Dynamic Arrays In VB
     - Developer Fusion: Arrays - Dynamic Arrays
       By James Crowley
       ( http://www.developerfusion.com/show/19/5/ )

- The FileSystemObject Object
     - MSDN Library: FileSystemObject Object
       ( http://msdn.microsoft.com/library/devprods/vs6/vbasic/vbenlr98/vaobjFileSystemObject.htm)
     - The FileSystemObject and associates
       ( http://www.vbwm.com/art_1999/whatsnew/filesys.asp )

 - Using the Win32 API functions in VB
     - Using Win32 API - Online tutorial 
       ( http://www.webwareindex.com/tutorials/API.html )
     - Using the Win32 API in VB
       by Sreejath
       ( http://www.student.kuleuven.ac.be/~m0116986/agnet/tutors/iapi2p.htm
)

- INI files/ GetPrivateProfileSection() WIN32 function
     - Visual Basic : Mastering INI files
       ( http://www.vbexplorer.com/VBExplorer/focus/ini_tutorial.asp )
     - MSDN Library: GetPrivateProfileSection
       ( http://msdn.microsoft.com/library/en-us/sysinfo/base/getprivateprofilesection.asp
)

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

Here is a synopsis of how the program works. The search/replace terms
that you provide as input are stored in two separate arrays. If you
are working in the default program mode, there will only be 1 search
term and 1 replace term, so the arrays will contain only one element
each.
  If you are working in Enhancement1 mode, you provide an input
string, which can contain any number of search/replace terms. These
input strings are passed on to a function which parses these strings,
extracts the search and replace terms one by one, and adds them to the
arrays, dynamically resizing the arrays so they have enough space to
hold the new elements.
  If you are working in Enhancement2 program mode, the search terms
are read in from the ini file you specified. Here also, a function
reads in the complete text from the ini file, extracts the search and
replace pairs from it one by one, and adds them to the respective
array. The function uses the GetPrivateProfileSection() WIN32 API
function to read data from the INI file. For more information on this
function, check out the article I have linked to in the previous
section.
  Once the Search and Replace arrays have been filled with the search
and replace terms you provided, they are passed to the
SearchAndReplace function. This function reads in the text from the
input file into a string, searches and replaces the text in this
string, and then writes the result into the new file that it creates.

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

Hope this helps.
If you need any clarifications, just ask!
Happy Coding!

Regards,
Theta-ga
:-)

============================================
Google Search Terms Used:
     visual basic string mid len left right instr
     filesystem object visual basic
     using win32 api in vb
Comments  
Subject: Re: I need code for a VB program
From: ttubbs-ga on 14 Feb 2003 01:22 PST
 
Do you mind if it is written in VB script ?
This is very easy program that can easily be written in VB script - so
I'm wondering if you want a binary or will the raw VB script be fine -
If you're after editing the file yourself later (and it sounds like
you are) VBscript would be my choice.
Regards
ttubbs
Subject: Re: I need code for a VB program
From: ghost1320-ga on 15 Feb 2003 20:08 PST
 
I can do this program... and i can make it simple and easy for you to understand.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy