?
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
Medium Priority
?
491 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 300 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Suggested Courses

770 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