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
487 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

791 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