Visual Basic 6 : some useful functions

VB 6 introduced a trio of powerful functions that operate on string arrays. These functions save the coding effort of having to set up loops and using combinations of other basic string functions to perform the equivalent tasks.

Split(expression[, delimiter[, count[, compare]]])
Join(
list[, delimiter])
Filter(InputStrings, Value[, Include[, Compare]])

Here are two visual basic 6 programs for reading and writing files with visual basic sequential file :

Sub Extraction_PhotosMiningSplit()
On Error GoTo Err_Extraction_PhotosMiningSplit_Click

Dim i As Integer
Dim ISN As String
Dim ligne As String

filein = “C:\phototeque\photodoc.txt”

ISN = “”
Close #1
Close #2

Dim partie1 As Integer

partie1 = 0

Open filein For Input As 1
Open “c:\phototeque\split_class2.txt” For Output As #2

MsgBox “Reading  Photos file line by line … ”

Do While Not EOF(1)
Line Input #1, ligne

If InStr(1, ligne, “$DOC_ISN”) <> 0 Then
Line Input #1, ligne
‘Print #2, ligne;
‘Print #2, Chr$(9);
ISN = ligne
GoTo Suite
End If

‘$DOC_CLASS2
‘CIMETIERE$SEP$POTERIE$SEP$VILLE

If InStr(1, ligne, “$DOC_CLASS2”) <> 0 Then
Line Input #1, ligne
‘Print #2, ligne;
‘Print #2, Chr$(9)

astrSplitItems = Split(ligne, “$SEP$”)

For intX = 0 To UBound(astrSplitItems)

Print #2, ISN;
Print #2, Chr$(9); ‘tab char code
Print #2, astrSplitItems(intX)

Next

partie1 = 1
GoTo Suite
End If

If InStr(1, ligne, “//FINENREG”) <> 0 Then

If partie1 = 0 Then
Print #2, Chr$(9)
Else
partie1 = 0
End If

GoTo Suite

End If

Suite:
Loop

Close #1
Close #2
‘Kill fileout

‘Name “c:\tempbr.tmp” As fileout

MsgBox “End Mining des Photos … ”

Exit_Extraction_PhotosMiningSplit_Click:
Exit Sub

Err_Extraction_PhotosMiningSplit_Click:
MsgBox Err.Description
Resume Exit_Extraction_PhotosMiningSplit_Click

End Sub

======== SolR Data generated by VB6 sample ==========

Sub Extraction_PhotoSolr()
On Error GoTo Err_Extraction_PhotoSolr_Click

Dim ligne As String
filein = “C:\phototeque\photos_doc.txt”

Close #1
Close #2
Dim id_isn As Double
Dim partie As Integer

Open filein For Input As 1
Open “c:\phototeque\indexdata_solr.txt” For Output As #2

‘objFile.WriteLine “<? xml version = ” & Chr(34) & “1.0” & Chr(34) & _
‘   ” encoding = ” & Chr(34) & “UTF-8″ & Chr(34) & ” ?>”

‘ Chr(34) code char des double quote

MsgBox “Extraction des Photos … ”

Do While Not EOF(1)
Line Input #1, ligne

If InStr(1, ligne, “$DOC_DP”) <> 0 Then

Line Input #1, ligne
Print #2, “<field name=” & Chr(34) & “typeres” & Chr(34) & “>”;
Print #2, ligne;
Print #2, “</field>”
GoTo Suite
End If

If InStr(1, ligne, “$DOC_ISN”) <> 0 Then

Line Input #1, ligne
Print #2, “<field name=” & Chr(34) & “id” & Chr(34) & “>”;
Print #2, ligne;
Print #2, “</field>”
GoTo Suite
End If

If InStr(1, ligne, “$DOC_TITRE”) <> 0 Then

Line Input #1, ligne
Print #2, “<field name=” & Chr(34) & “titre” & Chr(34) & “>”;
Print #2, ligne;
Print #2, “</field>”
GoTo Suite
End If

If InStr(1, ligne, “$DOC_NUMINVENT”) <> 0 Then

Line Input #1, ligne
Print #2, “<field name=” & Chr(34) & “idimg” & Chr(34) & “>”;
Print #2, ligne;
Print #2, “</field>”
GoTo Suite
End If

If InStr(1, ligne, “//FINENREG”) <> 0 Then

‘ end of record tag

Print #2, “</add>”
Print #2, “</doc>”

Print #2, “<add>”
Print #2, “<doc>”

GoTo Suite

End If

Suite:
Loop

Close #1
Close #2
‘Kill fileout
‘Name “c:\tempbr.tmp” As fileout

MsgBox “Fin Extraction index SolR Photos … ”

Exit_Extraction_PhotoSolr_Click:
Exit Sub

Err_Extraction_PhotoSolr_Click:
MsgBox Err.Description
Resume Exit_Extraction_PhotoSolr_Click

End Sub

 

 

extradrmtech

Since 30 years I work on Database Architecture and data migration protocols. I am also a consultant in Web content management solutions and medias protecting solutions. I am experienced web-developer with over 10 years developing PHP/MySQL, C#, VB.Net applications ranging from simple web sites to extensive web-based business applications. Besides my work, I like to work freelance only on some wordpress projects because it is relaxing and delightful CMS for me. When not working, I like to dance salsa and swing and to have fun with my little family.

You may also like...