Solved

VBScript Q:How to read a Hex(07) character from a text file which looks like a ^G in the file

Posted on 2003-10-29
2
484 Views
Last Modified: 2008-02-01
Hello Experts,

Environment:  Flat file with .txt extension; having data records delimited with Hex 07 character.
This delimiter is visible as a box when I open the file in notepad and visible as a tiny ^G when I open with an editor called Vedit.  

I am trying to read the file character by character and need to identify the delimiter which is supposed to be Hex 07 character.  

My Question: within a vb script, how can I identify the delimiter character, Hex 07 ?  I am lost here.  Any help would be greatly appreciated.

Here is the code I have tried, which is not working. This is vb active x script in DTS of sql server.  This code is never printing the msg- 'found the delimiter'

'********************************************************************
'  Visual Basic ActiveX Script
'********************************************************************
Function Main()

dim pipect,i,fld,c
dim column(50)

Set f1o = CreateObject("Scripting.FileSystemObject")
Set f1 = f1o.OpenTextFile("T:\Load to SQL\testfile.txt" , 1)

Do Until f1.AtEndOfStream
      c = f1.Read(1)
      msgbox "value of c" & c

      if c = Hex(x07)  then
            msgbox "found the delimiter"
      end if
Loop
      Main = DTSTaskExecResult_Success
End Function
=================================
0
Comment
Question by:chitkala
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 75 total points
ID: 9643096
Hi chitkala,

You should use:

'********************************************************************
'  Visual Basic ActiveX Script
'********************************************************************
Function Main()

dim pipect,i,fld,c
dim column(50)

Set f1o = CreateObject("Scripting.FileSystemObject")
Set f1 = f1o.OpenTextFile("T:\Load to SQL\testfile.txt" , 1)

Do Until f1.AtEndOfStream
     c = f1.Read(1)
     msgbox "value of c" & c

     if c = Chr(7)  then
          msgbox "found the delimiter"
     end if
Loop
     Main = DTSTaskExecResult_Success
End Function
=================================

Chr(7) is the character represented by x07

Tim Cottee MCSD, MCDBA, CPIM
Brainbench MVP for Visual Basic
http://www.brainbench.com
0
 

Author Comment

by:chitkala
ID: 9643618
Hi Tim Cottee,
Thank you Very much for giving me the right function.  I tested it and it works.
Great and very fast help. Appreciate very much.

regards,
chitkala
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now