Go Premium for a chance to win a PS4. Enter to Win

x
?
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
?
492 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 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…
Suggested Courses

886 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