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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

690 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