home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / CSV2TXT__(2076757232007.psc / CSV2TXT.frm < prev    next >
Text File  |  2007-07-23  |  3KB  |  100 lines

  1. VERSION 5.00
  2. Begin VB.Form CSV2TXT_Main 
  3.    Caption         =   "Kevin Ritch - V8Software.com"
  4.    ClientHeight    =   4575
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   12045
  8.    LinkTopic       =   "Form1"
  9.    Picture         =   "CSV2TXT.frx":0000
  10.    ScaleHeight     =   4575
  11.    ScaleWidth      =   12045
  12.    StartUpPosition =   3  'Windows Default
  13. End
  14. Attribute VB_Name = "CSV2TXT_Main"
  15. Attribute VB_GlobalNameSpace = False
  16. Attribute VB_Creatable = False
  17. Attribute VB_PredeclaredId = True
  18. Attribute VB_Exposed = False
  19. Dim NulString As String
  20. Dim Q As String
  21. Dim C As String
  22. Dim tb As String
  23. Dim QCQ As String
  24. Dim StoreComma As String
  25. Dim DummyQuote As String
  26. Dim RAW
  27. Private Sub Form_Load()
  28.  tb = Chr$(9)
  29.  Q = Chr$(34)
  30.  C = ","
  31.  QCQ = Q & C & Q
  32.  StoreComma = Chr$(255)
  33.  DummyQuote = Chr$(254)
  34. '=================================================================================
  35. 'CREATE YOUR "Occasional Quotes File" (Commas in Street Addresses etc) File FIRST!
  36. '=================================================================================
  37.  CSVFile$ = "c:\V8Client\OccasionalQuotes.csv"
  38.  TabFile$ = "c:\V8Client\ImportOK.tab"
  39.  IsQuoteCommaQuoteFile = TestQCQ(CSVFile$)
  40.  Open CSVFile$ For Input As #1
  41.  Open TabFile$ For Output As #2
  42.  While Not EOF(1)
  43.   Line Input #1, a$
  44.   If IsQuoteCommaQuoteFile Then
  45.    a$ = Replace$(a$, QCQ, tb)
  46.    a$ = Replace$(a$, Q, NulString)
  47.   Else ' OK This file is not a fully fledged Quote Comma Quote file
  48.   '=========================== ===================
  49.   'Find Commas in WITHIN cells (ie NOT Delimiters)
  50.   '=========================== ===================
  51.    While InStr(a$, Q)
  52.     S1 = InStr(a$, Q)
  53.     S2 = InStr(S1 + 1, a$, Q)
  54.     tmp$ = Mid$(a$, S1 + 1, (S2 - S1) - 1)
  55.    '=========================   =============================
  56.    'EG "166, Riviera Parkway" - TEMPORARILY "STORE" THE COMMA
  57.    '=========================   =============================
  58.     tmp$ = Replace(tmp$, C, StoreComma)
  59.     Mid$(a$, S1, 1) = DummyQuote
  60.     Mid$(a$, S2, 1) = DummyQuote
  61.     Mid$(a$, S1 + 1, (S2 - S1) - 1) = tmp$
  62.    Wend
  63.   '======================
  64.   'Remove the DummyQuotes
  65.   '======================
  66.    a$ = Replace$(a$, DummyQuote, NulString)
  67.   '========================
  68.   'REPLACE COMMAS WITH TABS
  69.   '========================
  70.    a$ = Replace$(a$, C, tb)
  71.   '=============================
  72.   'Now replace the stored commas
  73.   '=============================
  74.    a$ = Replace$(a$, StoreComma, C)
  75.   End If
  76.  '=============================
  77.  'SAVE THE LINE TO THE TAB FILE
  78.  '=============================
  79.   Print #2, a$
  80.  Wend
  81.  Close
  82.  MsgBox "FILE CONVERTED"
  83.  Shell "Notepad " & TabFile$, vbMaximizedFocus
  84.  End
  85. End Sub
  86. Function TestQCQ(Filename As String) As Boolean
  87.  TestQCQ = True
  88.  DF = FreeFile
  89.  Open Filename$ For Input As #DF
  90.  While Not EOF(1)
  91.   Line Input #DF, a$
  92.   If InStr(a$, QCQ) = 0 Then
  93.    TestQCQ = False
  94.    GoTo DoneChecking:
  95.   End If
  96.  Wend
  97. DoneChecking:
  98.  Close #DF
  99. End Function
  100.